cancel
Showing results for 
Search instead for 
Did you mean: 

How to read and write data to a user defined table?

former_member458725
Active Participant
0 Kudos

I have created a srf with 2 edit box and a ok buttin, I want to insert data to the user defined table i created using sql query while i press OK button..

Please provide the complete code to insert and select da from the user defined table.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member458725
Active Participant
0 Kudos

Code helped...lot...little bit your knowledge..will solve all problem

Former Member
0 Kudos

Hi,

You can use the code below.

Dim ret As Long

d

Private Sub Add_Table_Click()

Dim oUserTablesMD As SAPbobsCOM.UserTablesMD

Set oUserTablesMD = oCompany.GetBusinessObject(oUserTables)

'**************************************************

' When adding user tables or fields, use a prefix

' identifying your partner name space. This will

' prevent collisions from different partner add-ons

'

' SAP's name space prefix is "BE_"

'**************************************************

'Set the two mandatory fields

oUserTablesMD.TableName = "T1"

oUserTablesMD.TableDescription = "Table1"

'Add the table (which contains 2 default, mandatory fields, 'Code' and 'Name')

ret = oUserTablesMD.Add

If ret <> 0 Then

oCompany.GetLastError ret, Str

MsgBox Str

Else

MsgBox "Table: " & oUserTablesMD.TableName & " was added successfully"

End If

End Sub

Private Sub Add_UDF_Click()

Dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD

Set oUserFieldsMD = oCompany.GetBusinessObject(oUserFields)

oUserFieldsMD.TableName = "T1"

oUserFieldsMD.Name = "AlbUDF"

oUserFieldsMD.Description = "Albert UDF"

'Add the field to the table

lRetCode = oUserFieldsMD.Add

If lRetCode <> 0 Then

oCompany.GetLastError ret, Str

MsgBox Str

Else

MsgBox "Field: '" & oUserFieldsMD.Name & "' was added successfuly to " & oUserFieldsMD.TableName & " Table"

End If

End Sub

Private Sub Add_Data_Click()

Dim oUserTable As SAPbobsCOM.UserTable

Set oUserTable = oCompany.UserTables.Item(1)

oUserTable.GetByKey ("T1")

'Set default, mandatory fields

oUserTable.Code = "A"

oUserTable.Name = "Albert"

'Set user field

oUserTable.UserFields.Fields.Item("U_AlbUDF").Value = "1"

oUserTable.Add

If ret <> 0 Then

oCompany.GetLastError ret, Str

MsgBox Str

Else

MsgBox "Value to field: '" & oUserTable.UserFields.Fields.Item("U_AlbUDF").Name & "' was updated successfuly to " & oUserTable.TableName & " Table"

End If

End Sub

Regards,

Noor

former_member458725
Active Participant
0 Kudos

i Understand the code but this is not i looking for...

i already created the user table with the field...

i need code to read data from my editbox and insert it into the table i careted...is this possible with the sql query...and the other way around..i.e from table to the editbox and gid.

Thanks for the Reply

Vibin Varghese

Former Member
0 Kudos

Vibin,

Its possible to read and write the data from the textbox. You have to recordeset object provided by SAP for database operation.

Public oRecordSet As SAPbobsCOM.Recordset

Public oEdit As SAPbouiCOM.EditText

To read the data from db use the below code

oRecordSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

oRecordSet.DoQuery("Select U_OPPart from [@IS_PS] ")

If Not oRecordSet.EoF Then

oEdit = oForm.Items.Item("txtOp").Specific

oEdit.Value = oRecordSet.Fields.Item("U_OPPart").Value

End If

To write into the db use the below code

oEdit = oForm.Items.Item("txtOp").Specific

oRecordSet.DoQuery("Insert into [@IS_PS](U_OPPart) values('"+ oEdit.Value+"')"

Noor

former_member458725
Active Participant
0 Kudos

Thanks...that helped lot...

Thanks for the reply