Skip to Content
0

How do I drop a UDT that doesn't have any records?

Oct 27, 2016 at 09:22 PM

80

avatar image

I have a UDT (not UDO). I want to use the .Remove method, because I want to clean up after myself, and the table is no longer needed. The UDT is empty, meaning it has no records/rows/keys. How do I use that method, without first using .GetByKey? Or must one first always .Add and then .GetByKey on the code that was just added? Is there another method?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

DIEGO LOTHER Oct 27, 2016 at 09:44 PM
1

Hi David,

You first should call GetByKey method.

A sample:

            UserTablesMD oUserTableMD = null;
            try
            {
                oUserTableMD = (SAPbobsCOM.UserTablesMD)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables);


                if (oUserTableMD.GetByKey("Your user table name without @"))
                {
                    if(oUserTableMD.Remove() != 0)
                    {
                        //Something wrong, look oCompany.GetLastErrorCode() and oCompany.GetLastErrorDescription()
                    }
                }
                else
                {
                    //The table was not found
                }
            }
            catch(Exception ex)
            {
                //Something wrong
            }
            finally
            {
                //Release the resources used
                if (oUserTableMD != null)
                {
                    Marshal.ReleaseComObject(oUserTableMD);
                    oUserTableMD = null;
                }
            }

Kind Regards,

Diego Lother

Share
10 |10000 characters needed characters left characters exceeded