Skip to Content

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

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Oct 27, 2016 at 09:44 PM

    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

    Add comment
    10|10000 characters needed characters exceeded