cancel
Showing results for 
Search instead for 
Did you mean: 

DI: Deleting a UserField

Former Member
0 Kudos

Hi SBO forum, I have a problem when I try to delete some userfields, my code is the next:

Dim oCampo As SAPbobsCOM.UserFieldsMD

Dim oRecord As SAPbobsCOM.Recordset

Dim lCode As Long

Dim sQuery As String

Dim sMensaje As String

Set oCampo = oCompany.GetBusinessObject(oUserFields)

Set oRecord = oCompany.GetBusinessObject(BoRecordset)

sQuery = "SELECT FIELDID FROM CUFD WHERE TABLEID = '" & sTabla & " ' AND ALIASID = '" & sCampo & "' "

oRecord.DoQuery sQuery

If oCampo.GetByKey(sTabla, oRecord.Fields(0).Value) Then

lCode = oCampo.Remove

If lCode <> 0 Then

oCompany.GetLastError lCode, sMensaje

MsgBox "Ocurrió el siguiente error: " & sMensaje, vbCritical, "Error"

End If

End If

And then, shows me the next error:

The Mete Data for this object cannot be updated,

since it's ref count is bigger then 0.

Any suggestions?

Hi everyone!!

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

While creating User Fields we will use two DI objects:-

1) Record Set for the purpose of exist field or not from CUFD table.

2) UserfieldMD Object for the purpose of create of field.

Major reason behind creating error on this :-

We were initialize Record Set Object simultaneously with UserFieldsMD.

Error Effect

-1120 Ref is higher than 0

Sol:-

if(oRS.RecordCount = 0) then

system,.Runtime,Interoperateservices.Marshal.Release.ComObject (oRS)

oRS =Nothing

GC.Collect()

' KILL ORS OBJECT BEFORE INITIALIZE SECOND OBJECT

oUDFMD = oCompany.GetBusinessObject(oUserFields)

oUDFMD.TableName= ""

oUDFMD.Name = ""

.

.

lretcode = oUDFMD.Add()  or Remove



Repeat same steps of release com object code for OUDFMD.

Former Member
0 Kudos

The problem is that MetaDataObject an RecordSet cannot coexist. I cite the DI-Help (see FAQ):

"When I am trying to perform a meta data operation, why am I getting an error message? The meta data for this object can not be updated since its reference count is bigger than 0" (error code: -1120).:

The DI API allows only one instance of a meta data object at a time. This maintains data integrity by preventing any manipulation of a business object while modifying the object's user fields. Therefore, verify that no other DI object is active except the meta data object."

You have to store your values in an own field and then destroy the RecordSet before using the MD-Object.

As for manipulating the fields with extern SQL (ALTER is not allowed via DI-API), I was told it is not recommended as the SAP-logic needs to track your tables.

Ch. Becker

former_member185703
Active Contributor
0 Kudos

Thank you very much for your post!

Besides the fact that I can just confirm that you have to make that the particular meta data objects are cleaned up properly (see e.g Yaniv G.'s recommendation how to handle it (and don't forget to set the object to null) ).

Regarding Lutz' reply:

You must learn how to use the API's instead of finding the appropriate hacks to work around them.

It may be true that the hacked worked in one release, but this does not necessarily have to be the case in the next release - or service pack...

In addition, SAP Support will refuse to support the database where you used such work arounds.

Regards,

Frank

Former Member
0 Kudos

Thanks Trond and Lutz. I will try to shutdown my SBO client when I run my code. Lutz, in this days i use slq sentences to delete this user fields like you said.

Saludos desde Mexico y Feliz Año...

Former Member
0 Kudos

Is the SBO client active on your PC when you run your code? I think that may be the problem, both when adding and removing user defined fields from program code.

Former Member
0 Kudos

Hi,

you can most probably turn around the following sql statement which will create a userfield via sql only.


/* How to Add a user field to an existing table */

/* Add the field to the table */
Alter table OCRD add U_SAMPLE varchar(1) null
GO

/* add the userfield to the tracking table (FieldId might be a problem) */
/* field id is usually highest existing field id in a table increased by one */
/* choose an unlikely value like 200 */
INSERT INTO CUFD ("TableID","FieldID","AliasID","Descr","TypeID","EditType","SizeID","EditSize","NotNull","IndexID") 
          VALUES ('OCRD', 200,'SAMPLE','Beispiel','A',' ',1,1,'N','N')
GO

/* create list of values */
INSERT INTO UFD1 ("TableID","FieldID","IndexID","FldValue","Descr") Values ('OCRD',200,1,'Y','Ja')
GO

/*Set default value for User Field to 'Y' */
Update OCRD set U_SAMPLE = 'Y' WHERE U_SAMPLE is null
GO

Executing sql against server directly will bypass SAP logic.

Make sure that you know what you are doing, though.

HTH Lutz Morrien

Former Member
0 Kudos

I am having this same problem.

I think it may work if there are no rows in the table and that is what the error message is referring to. However, you can delete them from the SAP app when there are rows in the table. Even when there is data in the column.

Did you find a solution since you posted your message?

Former Member
0 Kudos

No, I haven't. I want to use this task in a application that uninstall my user tables.

Saludos desde México...