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

How to creating Service Contract using BAPI_SLSTRANSACT_CREATEMULTI

Hi,

In my requirement, I have to create a Service Contract from flat file by using BAPI - BAPI_SLSTRANSACT_CREATEMULTI and data which are comming from flat files are, Serial number, Sold-to party, Ship-to party, Installation date, Contract start date, Contract end date, Service profile, Response profile.

Please suggest me what are the Import parameters should I pass in this BAPI to create Service Contract?

Thanks in Advance,

Deepesh

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jan 20, 2008 at 12:43 PM

    Hi All,

    for everybody's benefit (and to avoid you the time I've spent to work this out...), here is a working example on how to create an sales order (TA) via the BAPI_SLSTRANSACT_CREATEMULTI.

    Not really a Service Contract, but it tells you how to call the BAPI.

    Points appreciated, if you find this helpful...

    I use the convention entryField for the values that should be set based on your system.

    Cheers

    G

    &----


    *& Report ZZGVBAPISALESORDER

    *&

    &----


    *&

    *&

    &----


    REPORT ZZGVBAPISALESORDER.

    • include constants

    include crm_direct.

    • // GUIDs

    data: lv_guid_h type GUID_32,

    lv_guid_i type GUID_32,

    lv_guid_sl type GUID_32,

    lv_guid_p type GUID_32.

    • // Handles

    data: lv_current_handle type crmt_handle,

    lv_handle_h type crmt_handle,

    lv_handle_i type crmt_handle,

    lv_handle_sl type crmt_handle,

    lv_handle_p type crmt_handle.

    • // Administration header + item + etc

    data: lt_salesorder_header type table of bapibus20001_header_ins,

    ls_salesorder_header type bapibus20001_header_ins,

    lt_salesorder_item type table of bapibus20001_item,

    ls_salesorder_item type bapibus20001_item,

    lt_scheduleline type table of BAPIBUS20001_SCHEDLIN,

    ls_scheduleline type BAPIBUS20001_SCHEDLIN,

    lt_partner type table of BAPIBUS20001_PARTNER_INS,

    ls_partner type BAPIBUS20001_PARTNER_INS,

    ls_logical_key TYPE crmt_partner_logic_partner_key,

    lt_organisation type table of BAPIBUS20001_ORGMAN_INS,

    ls_organisation type BAPIBUS20001_ORGMAN_INS.

    • // Saved sales orders

    data: lt_saved_process type table of bapibus20001_object_id,

    ls_saved_process type bapibus20001_object_id,

    ls_salesorder type CRMT_RETURN_OBJECTS_STRUC.

    data: lt_input_fields type table of bapibus20001_input_fields,

    ls_input_fields type bapibus20001_input_fields,

    lt_return type table of bapiret2,

    ls_return type bapiret2.

    • // Macro definition to populate structure and input field

    • This, called as

    *

    • setfield ls_salesorder_header GUID lv_guid_h

    *

    • is exploded as

    *

    • ls_salesorder_header-GUID = lv_guid_h.

    • ls_input_fields-fieldname = 'GUID'.

    • append ls_input_fields to lt_input_fields.

    *

    • Note 1: &2 (field name) MUST be uppercase

    • Note 2: for the salesorder header, I haven't used the macro,

    • to show how the code should look.

    • I've used the macro everywhere else.

    define setfield.

    &1-&2 = &3.

    ls_input_fields-fieldname = '&2'.

    append ls_input_fields to lt_input_fields.

    end-of-definition.

    • // end of macro definition

    • // fill order administration header

    perform get_guid changing lv_guid_h.

    add 1 to lv_handle_h.

    ls_salesorder_header-guid = lv_guid_h.

    ls_salesorder_header-handle = lv_handle_h.

    ls_salesorder_header-process_type = 'TA'.

    clear ls_input_fields.

    ls_input_fields-ref_handle = lv_handle_h.

    ls_input_fields-ref_guid = lv_guid_h.

    *ls_input_fields-ref_kind = gc_object_ref_kind-orderadm_h.

    ls_input_fields-objectname = gc_object_name-orderadm_h.

    ls_input_fields-fieldname = 'GUID'.

    append ls_input_fields to lt_input_fields.

    ls_input_fields-fieldname = 'HANDLE'.

    append ls_input_fields to lt_input_fields.

    ls_input_fields-fieldname = 'PROCESS_TYPE'.

    append ls_input_fields to lt_input_fields.

    append ls_salesorder_header to lt_salesorder_header.

    • // fill organisation data (I needed this, you may rely on

    • sales org determination instead...)

    clear ls_input_fields.

    ls_input_fields-ref_handle = lv_handle_h.

    ls_input_fields-ref_guid = lv_guid_h.

    ls_input_fields-ref_kind = gc_object_ref_kind-orderadm_h.

    ls_input_fields-objectname = gc_object_name-orgman.

    setfield ls_organisation REF_GUID lv_guid_h.

    setfield ls_organisation REF_HANDLE lv_handle_h.

    setfield ls_organisation REF_KIND gc_object_ref_kind-orderadm_h.

    setfield ls_organisation SALES_ORG_RESP salesOrgResp(input).

    setfield ls_organisation SALES_ORG salesOrg(input).

    setfield ls_organisation DIS_CHANNEL disChannel(input).

    append ls_organisation to lt_organisation.

    • // fill order administration item

    perform get_guid changing lv_guid_i.

    lv_handle_i = lv_handle_h.

    add 1 to lv_handle_i.

    clear ls_input_fields.

    ls_input_fields-ref_guid = lv_guid_i.

    ls_input_fields-ref_handle = lv_handle_i.

    *ls_input_fields-ref_kind = gc_object_ref_kind-orderadm_i.

    ls_input_fields-objectname = gc_object_name-orderadm_i.

    setfield ls_salesorder_item GUID lv_guid_i.

    setfield ls_salesorder_item HEADER lv_guid_h.

    setfield ls_salesorder_item HANDLE lv_handle_i.

    setfield ls_salesorder_item HEADER_HANDLE lv_handle_h.

    setfield ls_salesorder_item ORDERED_PROD product(input).

    *_set_field ls_salesorder_item ITM_TYPE 'TAN'.

    setfield ls_salesorder_item MODE 'A'.

    *adjustment taken from standard include LCMS_MAPPERF04

    *(see where-used-list for BAPI_SLSTRANSACT_CREATEMULTI, program LCMS_MAPPERU11)

    delete lt_input_fields where fieldname = 'HANDLE'

    OR

    fieldname = 'HEADER_HANDLE'.

    append ls_salesorder_item to lt_salesorder_item.

    • // fill schedule line for item

    perform get_guid changing lv_guid_sl.

    add 1 to lv_handle_sl.

    clear ls_input_fields.

    ls_input_fields-ref_guid = lv_guid_i.

    ls_input_fields-ref_handle = lv_handle_i.

    ls_input_fields-ref_kind = gc_object_ref_kind-orderadm_i.

    ls_input_fields-objectname = gc_object_name-schedlin.

    setfield ls_scheduleline ITEM_GUID lv_guid_i.

    setfield ls_scheduleline GUID lv_guid_sl.

    setfield ls_scheduleline HANDLE lv_handle_sl.

    setfield ls_scheduleline ITEM_HANDLE lv_handle_i.

    setfield ls_scheduleline QUANTITY '1.000'.

    append ls_scheduleline to lt_scheduleline.

    • // fill partner line

    *perform get_guid changing lv_guid_p.

    *the partner use the logical key as well

    ls_logical_key-ref_partner_handle = '0001'.

    clear ls_input_fields.

    ls_input_fields-ref_guid = lv_guid_h.

    ls_input_fields-ref_handle = lv_handle_h.

    ls_input_fields-ref_kind = gc_object_ref_kind-orderadm_h.

    ls_input_fields-objectname = gc_object_name-partner.

    ls_input_fields-logical_key = ls_logical_key.

    setfield ls_partner REF_GUID lv_guid_h.

    setfield ls_partner REF_HANDLE lv_handle_h.

    setfield ls_partner REF_KIND gc_object_ref_kind-orderadm_h.

    setfield ls_partner REF_PARTNER_HANDLE '0001'.

    setfield ls_partner KIND_OF_ENTRY 'C'.

    setfield ls_partner PARTNER_FCT '00000001'.

    setfield ls_partner PARTNER_NO bpNumber(input).

    setfield ls_partner NO_TYPE 'BP'.

    setfield ls_partner DISPLAY_TYPE 'BP'.

    move-corresponding ls_partner to ls_logical_key.

    append ls_partner to lt_partner.

    • // example of a second partner function (custom) with data

    • override

    ls_logical_key-ref_partner_handle = '0002'.

    clear ls_input_fields.

    ls_input_fields-ref_guid = lv_guid_h.

    ls_input_fields-ref_handle = lv_handle_h.

    ls_input_fields-ref_kind = gc_object_ref_kind-orderadm_h.

    ls_input_fields-objectname = gc_object_name-partner.

    ls_input_fields-logical_key = ls_logical_key.

    setfield ls_partner REF_GUID lv_guid_h.

    setfield ls_partner REF_HANDLE lv_handle_h.

    setfield ls_partner REF_KIND gc_object_ref_kind-orderadm_h.

    setfield ls_partner REF_PARTNER_HANDLE '0002'.

    setfield ls_partner KIND_OF_ENTRY 'B'. "manual entry...

    setfield ls_partner PARTNER_FCT customFct(input).

    setfield ls_partner PARTNER_NO bpNumber(input).

    setfield ls_partner NO_TYPE 'BP'.

    setfield ls_partner DISPLAY_TYPE 'BP'.

    setfield ls_partner TITLE 'Mr.'.

    setfield ls_partner FIRSTNAME 'John'.

    setfield ls_partner LASTNAME 'Smith'.

    setfield ls_partner STR_SUPPL1 'John Smith and Co'.

    setfield ls_partner STREET 'Street1'.

    setfield ls_partner STR_SUPPL3 'Street4'.

    setfield ls_partner HOUSE_NO '42'.

    setfield ls_partner CITY 'Townville'.

    setfield ls_partner DISTRICT 'Districtshire'.

    setfield ls_partner POSTL_COD1 'AA1 2BB'.

    • note now ...

    *adjustment taken from standard include LCMS_MAPPERF04

    *(see where-used-list for BAPI_SLSTRANSACT_CREATEMULTI, program LCMS_MAPPERU11)

    • I don't use macro because name of the field in input_table is different

    *_set_field ls_partner COUNTRYISO 'GB'.

    *instead

    ls_partner-COUNTRYISO = 'GB'.

    ls_input_fields-fieldname = 'COUNTRY'.

    append ls_input_fields to lt_input_fields.

    *_set_field ls_partner LANGU_ISO 'EN'.

    ls_partner-LANGU_ISO = 'EN'.

    ls_input_fields-fieldname = 'LANGU'.

    append ls_input_fields to lt_input_fields.

    move-corresponding ls_partner to ls_logical_key.

    append ls_partner to lt_partner.

    ----


    • Create sales orders *

    ----


    call function 'BAPI_SLSTRANSACT_CREATEMULTI'

    EXPORTING

    testrun = false

    TABLES

    header = lt_salesorder_header[]

    item = lt_salesorder_item[]

    partner = lt_partner[]

    organisation = lt_organisation[]

    input_fields = lt_input_fields[]

    scheduleline = lt_scheduleline[]

    saved_process = lt_saved_process[]

    return = lt_return[].

    • // get the GUID of the created object

    call function 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    wait = 'X'.

    INCLUDE ZZGVBAPISALESORDER_GET_GUIDF01.

    The include contains only this:

    ----


    ***INCLUDE ZZGVBAPISALESORDER_GET_GUIDF01 .

    ----


    &----


    *& Form get_guid

    &----


    • text

    ----


    • <--guid text

    ----


    FORM get_guid CHANGING GUID.

    CALL FUNCTION 'SYSTEM_UUID_C_CREATE'

    IMPORTING

    UUID = GUID.

    ENDFORM. " get_guid

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.