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

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

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

Add comment
10|10000 characters needed characters exceeded

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on May 19, 2004 at 11:28 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 19, 2004 at 10:21 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.