cancel
Showing results for 
Search instead for 
Did you mean: 

DI: Add userfield to usertable

Former Member
0 Kudos

I tried to add an userfield to an usertable.

This is my Code:

Public ocompany As SAPbobsCOM.Company

Public errorCode As Long

Public ErrorMsg As String

Public lretcode As Long

Public bp As SAPbobsCOM.BusinessPartners

Public usertable1 As SAPbobsCOM.UserTablesMD

Public userfield As SAPbobsCOM.UserFieldsMD

Private Sub addtablesbtn_Click()

Set usertable1 = ocompany.GetBusinessObject(oUserTables)

Set userfield = ocompany.GetBusinessObject(oUserFields)

'add usertable

usertable1.TableName = "tt1"

usertable1.TableDescription = "test1"

usertable1.Add

'add userfield

userfield.TableName = "tt1"

userfield.Name = "Tf1"

userfield.Description = "Testfield1"

userfield.Type = db_alpha

userfield.Size = 8

lretcode = userfield.Add

If lretcode <> 0 Then

ocompany.GetLastError errorCode, ErrorMsg

MsgBox "Failed to add UserField " & errorCode & " " & ErrorMsg

End If

When trying to add the userfield i get the error:

"Failed to add UserField -1120 The Mete Data for this object cannot be updated, since it's ref count is bigger then 0"

Do Anybody knows whats wrong?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Juergen:

Try to use userfieldsMD:

Dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD

Set oUserFieldsMD = oCompany.GetBusinessObject(oUserFields)

oUserFieldsMD.TableName = "RDR1"

oUserFieldsMD.Name = "BE_CardCode"

oUserFieldsMD.Description = "End Customer No."

oUserFieldsMD.Type = db_Alpha

oUserFieldsMD.EditSize = 15

'// Adding the Field to the Table

lRetCode = oUserFieldsMD.Add

'// Check for errors

If lRetCode <> 0 Then

oCompany.GetLastError lErrCode, sErrMsg

MsgBox sErrMsg

End If

try this, there is a sample calles EndCostumer that create's User Tables and then Userfields.

Former Member
0 Kudos

Hi Natalia:

Thank's for ur post, in wich version I can find that sample??.

Can U send it to me.

Thanks

Answers (3)

Answers (3)

Former Member
0 Kudos

Close the object table is obligatory before than you open the object fields

After you create the table in .NET

You mustn't write :

ObjectName=nothing

You must write:

System.Runtime.InteropServices.Marshal.ReleaseComObject(ObjectName)

or other solution may be:

ObjectName=nothing

GC.Collect()

GC.WaitForPendingFinalizers()

Exemple:

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

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

Public Sub INF_ControlAddon(ByVal INF_SBOApp As SAPbouiCOM.Application)

Dim oUser As Object

'Dim oUserTablesMd As SAPbobsCOM.UserTablesMD

'Dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD

oUser = gCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)

oUser.TableName = "INFADDON"

oUser.TableDescription = "Bonito"

oUser.TableType = SAPbobsCOM.BoUTBTableType.bott_MasterData

If oUser.Add <> 0 Then

Beep()

End If

System.Runtime.InteropServices.Marshal.ReleaseComObject(oUser)

' oUser = Nothing

' GC.Collect()

' GC.WaitForPendingFinalizers()

oUser = gCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

oUser.TableName = "INFADDON"

oUser.Name = "INF_OTAB"

oUser.Description = "Tablas"

oUser.Type = SAPbobsCOM.BoFieldTypes.db_Alpha

oUser.SubType = SAPbobsCOM.BoFldSubTypes.st_None

oUser.EditSize = 1

If oUser.Add <> 0 Then Beep()

oUser = Nothing

Exit Sub

End Sub

Former Member
0 Kudos

Thats it.

Set usertable1 = Nothing

solved my problem

Tank you very much

Former Member
0 Kudos

I think you must release the user table object.

The problem is that only one MetaData object is allowed at a time.

I think in VB you must use this code:

usertable1 = nothing

Regards,

Ibai Peñ