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

Cant add the coloums in the table

dear all

i had done the following code but its not working

mean its running well but cant added the coloums in the database table.....

can you tell me whats wrong in thes code

  Public Sub FieldsForMCHAR()
        Try

            Dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD
            i = 0
            oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

            oUserFieldsMD.TableName = "MCHAR"
            oUserFieldsMD.Name = "CharType"
            oUserFieldsMD.Description = "Characteristic Type "
            oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Alpha
            oUserFieldsMD.SubType = SAPbobsCOM.BoFldSubTypes.st_None
            oUserFieldsMD.Size = 20
            oUserFieldsMD.EditSize = 20
            Try
                i = oUserFieldsMD.Add()
                SBO_Application.StatusBar.SetText("Field : " & oUserFieldsMD.Name, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Catch ex As Exception
            End Try



            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
            oUserFieldsMD = Nothing
            oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
            oUserFieldsMD.TableName = "MCHAR"
            oUserFieldsMD.Name = "CreateBy"
            oUserFieldsMD.Description = "Created By"
            oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Alpha
            oUserFieldsMD.SubType = SAPbobsCOM.BoFldSubTypes.st_None
            oUserFieldsMD.Size = 15
            oUserFieldsMD.EditSize = 15
            Try
                i = oUserFieldsMD.Add()
                SBO_Application.StatusBar.SetText("Field : " & oUserFieldsMD.Name, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Catch ex As Exception
            End Try


            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
            oUserFieldsMD = Nothing
            oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
            oUserFieldsMD.TableName = "MCHAR"
            oUserFieldsMD.Name = "REMARK"
            oUserFieldsMD.Description = "REMARK"
            oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Memo
            oUserFieldsMD.SubType = SAPbobsCOM.BoFldSubTypes.st_None
            'oUserFieldsMD.Size = 15
            'oUserFieldsMD.EditSize = 15
            Try
                i = oUserFieldsMD.Add()
                SBO_Application.StatusBar.SetText("Field : " & oUserFieldsMD.Name, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Catch ex As Exception
            End Try


            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
            oUserFieldsMD = Nothing
            oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
            oUserFieldsMD.TableName = "MCHAR"
            oUserFieldsMD.Name = "UpdateBY"
            oUserFieldsMD.Description = "UpdateBY"
            oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Alpha
            oUserFieldsMD.SubType = SAPbobsCOM.BoFldSubTypes.st_None
            oUserFieldsMD.Size = 15
            oUserFieldsMD.EditSize = 15
            Try
                i = oUserFieldsMD.Add()
                SBO_Application.StatusBar.SetText("Field : " & oUserFieldsMD.Name, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Catch ex As Exception
            End Try

            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
            oUserFieldsMD = Nothing
            oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
            oUserFieldsMD.TableName = "MCHAR"
            oUserFieldsMD.Name = "GrpCode"
            oUserFieldsMD.Description = "GrpCode"
            oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Alpha
            oUserFieldsMD.SubType = SAPbobsCOM.BoFldSubTypes.st_None
            oUserFieldsMD.Size = 15
            oUserFieldsMD.EditSize = 15

            Try
                i = oUserFieldsMD.Add()
                SBO_Application.StatusBar.SetText("Field : " & oUserFieldsMD.Name, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Catch ex As Exception
            End Try

            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
            oUserFieldsMD = Nothing
            oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
            oUserFieldsMD.TableName = "PDN1"
            oUserFieldsMD.Name = "QA"
            oUserFieldsMD.Description = "QA Status"
            oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Alpha
            oUserFieldsMD.SubType = SAPbobsCOM.BoFldSubTypes.st_None


            oUserFieldsMD.ValidValues.Value = "D"
            oUserFieldsMD.ValidValues.Description = "Done"
            oUserFieldsMD.ValidValues.Add()
            oUserFieldsMD.ValidValues.Value = "A"
            oUserFieldsMD.ValidValues.Description = "Pending"
            oUserFieldsMD.ValidValues.Add()
            oUserFieldsMD.ValidValues.Value = "NA"
            oUserFieldsMD.ValidValues.Description = "Not Applicable"


            oUserFieldsMD.DefaultValue = "NA"

            oUserFieldsMD.Size = 50
            oUserFieldsMD.EditSize = 50
            Try
                i = oUserFieldsMD.Add()
                SBO_Application.StatusBar.SetText("Field : " & oUserFieldsMD.Name, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Catch ex As Exception
            End Try


            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
            oUserFieldsMD = Nothing
            oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
            oUserFieldsMD.TableName = "MCHAR1"
            oUserFieldsMD.Name = "VldValue"
            oUserFieldsMD.Description = "Valid Values"
            oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Alpha
            oUserFieldsMD.SubType = SAPbobsCOM.BoFldSubTypes.st_None
            oUserFieldsMD.Size = 50
            oUserFieldsMD.EditSize = 50
            Try
                i = oUserFieldsMD.Add()
                SBO_Application.StatusBar.SetText("Field : " & oUserFieldsMD.Name, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
            Catch ex As Exception
            End Try





            System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserFieldsMD)
            oUserFieldsMD = Nothing
            GC.Collect()

        Catch ex As Exception
            SBO_Application.MessageBox(ex.Message)
        End Try


    End Sub  

Edited by: kishor karanjkar on Sep 8, 2011 1:37 PM

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Sep 08, 2011 at 11:58 AM

    Hi Kishor,

    Try This.....

    For adding fields to the user defined table

     Try
                ouserfield = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
                ouserfield.TableName = "@OEMP"
                ouserfield.Name = "empid"  'Field Name
                ouserfield.EditSize = "5"
                ouserfield.Type = SAPbobsCOM.BoFieldTypes.db_Numeric
                ouserfield.Description = "Employee id"
                lretcode = ouserfield.Add
                If lretcode <> 0 Then
                    ocompany.GetLastError(lerrcode, serrmsg)
                    sbo_application.MessageBox(serrmsg)
                End If
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ouserfield)
                ouserfield = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)
                ouserfield.TableName = "@OEMP"
                ouserfield.Name = "empnam"
                ouserfield.Description = "Employee Name"
                ouserfield.EditSize = 30
                ouserfield.Type = SAPbobsCOM.BoFieldTypes.db_Alpha
                lretcode = ouserfield.Add
                If lretcode <> 0 Then
                    ocompany.GetLastError(lerrcode, serrmsg)
     sbo_application.MessageBox(serrmsg)
                End If
    System.Runtime.InteropServices.Marshal.ReleaseComObject(ouserfield)
                GC.Collect()
            Catch ex As Exception
                sbo_application.MessageBox(ex.Message)
            End Try
    

    Thanks

    Shafi

    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.