cancel
Showing results for 
Search instead for 
Did you mean: 

DI - Service Contract 'Lines' item not adding to database

Former Member
0 Kudos

I am writing an application to load service contract data into SBO from a CSV file.

I am having a problem using the DI to add lines to a service contract.

The 'Add' method on the SAPbobsCOM.ServiceContract_Lines object does not add a record to the CTR1 table in the database.

The add method on the SAPbobsCOM.ServiceContract_Lines object is unique amongst similar add methods in that is a void function. It does not return a Boolean indicating it's success or failure, as all of the other Add methods seem to do.

I though perhaps there would be an error code waiting, but calling SAPbobsCOM.Company.GetLastErrorCode returns no error code.

It seems that I am going to have to use a RecordSet object to manually perform an insert into this table in order to do my data load.

Has anybody handled this condition before?

Here is the I am using code, for reference.

With Contract.Lines

.ItemCode = EquipCard.ItemCode

.StartDate = Data.StartDate.Value

.EndDate = Data.ExpiryDate.Value

.ManufacturerSerialNum = EquipCard.ManufacturerSerialNum

.InternalSerialNum = EquipCard.InternalSerialNum

.UserFields.Fields.Item("U_UDF1").Value = Data.CUSTOM_FIELD1.Value

' More UDF's are here, but have been removed for brevity

Call .Add '<> 0 Then ' this is a Sub, not a Function like the others

' check to see if maybe an error condition is waiting

Call mCompany.GetLastError(ErrorCode, ErrorMessage)

Debug.Print ErrorCode & " - " & ErrorMessage

Call MsgBox(ErrorCode & " - " & ErrorMessage)

End With

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks for the reply.

With the DI, is it possible to load an existing service contract, then add lines to it, then save those lines to the database?

I tried using the Update method on the contract object after adding line items to the lines collection, and it didn't seem to work.

Thanks,

Demetree

Former Member
0 Kudos

Hi again,

DI API was design to do just that...

You'll need to load the correct object from DB using:

Dim oServiceContracts As SAPbobsCOM.ServiceContracts

Set oServiceContracts = oCompany.GetBusinessObject(oServiceContracts)

Call oServiceContracts.GetByKey (<Object UID>)

Now you should have the object and can update it.

Note that the original lines where added and to add new lines use:

Call oServiceContracts.Lines.Add

After updating the object new <b>and/or</b> original lines call the following method:

Call oServiceContracts.update()

this should do the trick

if you still encounter problems implementing this - I suggest opening a CSN message to ireland support and send them your code.

Best regards,

Yaniv Gamliel

SDK Consultant

SAP Manage Israel

Former Member
0 Kudos

Thanks for the reply.

I've taken a look around the SAP site, and I can't seem to find out how to send a CSN message.

Could you please send me some information on how to do this?

Thanks,

Demetree

Former Member
0 Kudos

Hi again,

Opening a CSN can e done via he SAP internal tools - SAP partner has an access to these tools.

SAP partner should also get a package of samples that demonstrates a lot of "How To"'s.

In case you cannot find your SAP Partner - I can send you a sample code for the Line issue.

Best regards

Yaniv G.

Former Member
0 Kudos

Hi,

The structure of the Business Object is:

Business Object

-->Header properties

-->Lines - a collection

-


>Line - an object

-


>Line properties

-->UserFields - a collection

-->ContactEmployees - a collection

-->etc'

This means that the object to use is the main Business

Object and not the SubObject.

Now we get to the tricky part:

1. Add() method of a collection will only add an <b>empty row</b>(line) to the collection - it will <u><b>not</b></u> add anything to the DB

2. <b>Add() method of the main business object is the only add() function that adds data to the company DB</b>

<u>Bottom line:</u>

1. Use the Contract.Lines.Add() to add empty line in lines collection

2. Use the Contract.Add() to add the object to company DB

Best regards,

Yaniv Gamliel

SDK Consultant

SAP Manage Israel