Skip to Content
author's profile photo Former Member
Former Member

Set child table

hi all

how can i define child table and parent child through code.

Thanks

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on May 18, 2008 at 11:27 PM

    Hi,

    Here's a basic procedure for creating a document and document rows UDO:

    private bool CreateUDO()
            {
                bool bRetVal = true;
                string sCode = "MY_UDO";
                string sName = "My User-Defined Object";
    
                SAPbobsCOM.UserObjectsMD sboUDO = (SAPbobsCOM.UserObjectsMD)_sboCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserObjectsMD);
    
                try
                {   
                    // Set the UDO properties
                    sboUDO.Code = sCode;
                    sboUDO.Name = sName;
                    sboUDO.ObjectType = SAPbobsCOM.BoUDOObjType.boud_Document;
                    sboUDO.TableName = "MY_UDT";
                    sboUDO.CanFind = SAPbobsCOM.BoYesNoEnum.tNO;
                    sboUDO.CanCancel = SAPbobsCOM.BoYesNoEnum.tYES;
                    sboUDO.CanClose = SAPbobsCOM.BoYesNoEnum.tYES;
                    sboUDO.CanDelete = SAPbobsCOM.BoYesNoEnum.tYES;
                    sboUDO.CanYearTransfer = SAPbobsCOM.BoYesNoEnum.tYES;
                    sboUDO.CanLog = SAPbobsCOM.BoYesNoEnum.tNO;
                    sboUDO.CanCreateDefaultForm = SAPbobsCOM.BoYesNoEnum.tNO;
                    sboUDO.ManageSeries = SAPbobsCOM.BoYesNoEnum.tYES;
    
                    // Add the child table
                    sboUDO.ChildTables.TableName = "MY_CHILD_UDT";
                    sboUDO.ChildTables.Add();
    
                    int iVal = sboUDO.Add();
                    if (iVal == 0)
                    {
                        _sboApp.SetStatusBarMessage("UDO " + sCode + " (" + sName + ") created successfully.", SAPbouiCOM.BoMessageTime.bmt_Short, false);
                    }
                    else
                    {
                        // Object creation failed so report error to user and stop initialisation
                        bRetVal = false;
                        _sboApp.SetStatusBarMessage("Failed to create UDO " + sCode + " (" + sName + ") due to the following error: " + _sboCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Long, true);
                    }
                }
                catch (Exception ex)
                {
                    bRetVal = false;
                    _sboApp.SetStatusBarMessage("Failed to create UDO " + sCode + " (" + sName + ") due to the following error: " + _sboCompany.GetLastErrorDescription(), SAPbouiCOM.BoMessageTime.bmt_Long, true);
                }
                finally
                {
                    // Clean up
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(sboUDO);
                    sboUDO = null;
                    GC.Collect();
                }
    
                return bRetVal;
            }
    

    To keep things simple I've hardcoded the properties of the UDO in to the procedure (normally I hold all my UDT, UDO and UDF data in XML files). I've also not set things like the Find Columns or the default form properties. To run the sample you'll need to have 2 user-defined tables already set up; MY_UDT needs to be a Document type and MY_CHILD_UDT needs to be a Document Rows type.

    Kind Regards,

    Owen

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.