Skip to Content
2
Sep 19, 2019 at 11:42 AM

BAPI to create a contract with material configuration does not work in S/4 HANA anymore

546 Views Last edit Sep 23, 2019 at 08:12 AM 7 rev

Hello Experts,

I create contracts with the Function Module 'BAPI_CONTRACT_CREATEFROMDATA'.

In the contract is a Service Material which gets some configuration data from a gui input.

In the old System ECC Release 740 its working. EHP7 FOR SAP ERP Release 6.0 | SAP ERP Release 2005.

In the new S/4 HANA System Release 753. SAP_BASIS 753, SAP_ABA 75D | S4HANA ON PREMISE 1809, SAP S/4HANA FOUNDATION 1809. The logic does not work. Contract gets created with the Material but the configuration of the material is missing.

I wrote a test report to figure out, if something is missing but it still wont create the configuration.

DATA salesdocumentin         TYPE bapivbeln-vbeln.
DATA contract_header_in      TYPE bapisdhd1.
DATA contract_header_inx     TYPE bapisdhd1x.
DATA sender                  TYPE bapi_sender.
DATA binary_relationshiptype TYPE bapireltype-reltype.
DATA int_number_assignment   TYPE bapiflag-bapiflag.
DATA behave_when_error       TYPE bapiflag-bapiflag.
DATA logic_switch            TYPE bapisdls.
DATA testrun                 TYPE bapiflag-bapiflag.
DATA convert                 TYPE bapiflag-bapiflag.
DATA salesdocument           TYPE bapivbeln-vbeln.
DATA return                  TYPE STANDARD TABLE OF bapiret2.
DATA contract_items_in       TYPE STANDARD TABLE OF bapisditm.
DATA ls_it       TYPE  bapisditm.
DATA contract_items_inx      TYPE STANDARD TABLE OF bapisditmx.
DATA contract_partners       TYPE STANDARD TABLE OF bapiparnr.
DATA ls_pa       TYPE bapiparnr.
DATA contract_conditions_in  TYPE STANDARD TABLE OF bapicond.
DATA ls_con  TYPE bapicond.
DATA contract_conditions_inx TYPE STANDARD TABLE OF bapicondx.
DATA contract_cfgs_ref       TYPE STANDARD TABLE OF bapicucfg.
DATA ls_ref       TYPE  bapicucfg.
DATA contract_cfgs_inst_t    TYPE STANDARD TABLE OF bapicuins.
DATA contract_cfgs_inst      TYPE bapicuins.
DATA contract_cfgs_part_of_t TYPE STANDARD TABLE OF bapicuprt.
DATA contract_cfgs_part_of   TYPE bapicuprt.
DATA contract_cfgs_value     TYPE STANDARD TABLE OF bapicuval.
DATA ls_val TYPE bapicuval.
DATA contract_cfgs_blob      TYPE STANDARD TABLE OF bapicublb.
DATA contract_cfgs_vk        TYPE STANDARD TABLE OF bapicuvk.
DATA contract_cfgs_refinst   TYPE STANDARD TABLE OF bapicuref.
DATA contract_data_in        TYPE STANDARD TABLE OF bapictr.
DATA ls_data        TYPE bapictr.
DATA contract_data_inx       TYPE STANDARD TABLE OF bapictrx.
DATA ls_datax       TYPE bapictrx.
DATA contract_text           TYPE STANDARD TABLE OF bapisdtext.
DATA contract_keys           TYPE STANDARD TABLE OF bapisdkey.
DATA extensionin             TYPE STANDARD TABLE OF bapiparex.
DATA partneraddresses        TYPE STANDARD TABLE OF bapiaddr1.
DATA extensionex             TYPE STANDARD TABLE OF bapiparex.
DATA lv_vbeln TYPE vbeln.


*Fill Header
contract_header_in-doc_type = 'ZWV1'.
contract_header_in-sales_org = 'D000'.
contract_header_in-distr_chan = '24'.
contract_header_in-division = '01'.
contract_header_in-sales_grp = 'DD0'.
contract_header_in-sales_off = 'D012'.
contract_header_in-pmnttrms = '0010'.
contract_header_in-ord_reason = '01'.

*fill item
ls_it-itm_number = '000010'.
*ls_it-po_itm_no = '000010'.
ls_it-config_id = '000010'.
*ls_it-material = 'SERVICEMAT'.
ls_it-currency = 'EUR'.
ls_it-material_long = 'SERVICEMAT'.
APPEND ls_it TO contract_items_in.

*fill partners
ls_pa-partn_role = 'AG'.
ls_pa-partn_numb = '1000100005'.
APPEND ls_pa TO contract_partners.
ls_pa-partn_role = 'RE'.
ls_pa-partn_numb = '1000100005'.
APPEND ls_pa TO contract_partners.
ls_pa-partn_role = 'RG'.
ls_pa-partn_numb = '1000100005'.
APPEND ls_pa TO contract_partners.
ls_pa-partn_role = 'WE'.
ls_pa-partn_numb = '1000100005'.
APPEND ls_pa TO contract_partners.

*fill condition
ls_con-itm_number = '000010'.
ls_con-cond_type = 'ZCP1'.
ls_con-cond_value = '140'.
ls_con-currency = 'EUR'.
APPEND ls_con TO contract_conditions_in.

*fill data
ls_data-val_per = '036'.
ls_data-val_per_ca = 'Z3'.
ls_data-con_st_dat = sy-datum.
APPEND ls_data TO contract_data_in.

*fill xdata
ls_datax-updateflag = 'I'.
ls_datax-val_per = 'X'.
ls_datax-con_st_rul = 'X'.
APPEND ls_datax TO contract_data_inx.

*fill config
ls_ref-posex = '000010'.
ls_ref-config_id = '000010'.
ls_ref-root_id = '000010'.
APPEND ls_ref TO contract_cfgs_ref.


clear ls_val.
ls_val-config_id = '000010'.
ls_val-inst_id = '000010'.
ls_val-charc = 'SERVICE_WINDOW'.
ls_val-value = 'BD'.
APPEND ls_val TO contract_cfgs_value.


clear ls_val.
ls_val-config_id = '000010'.
ls_val-inst_id = '000010'.
ls_val-charc = 'TIME_AGREEMENT'.
ls_val-value = '08'.
ls_val-value_long = '08'.
APPEND ls_val TO contract_cfgs_value.


clear ls_val.
ls_val-config_id = '000010'.
ls_val-inst_id = '000010'.
ls_val-charc = 'SW_MAINTENANCE_CATEGORIE'.
ls_val-value = '03'.
APPEND ls_val TO contract_cfgs_value.

contract_cfgs_inst-config_id = '000010'.
contract_cfgs_inst-inst_id   = '000010'.
contract_cfgs_inst-class_type = '300'.
contract_cfgs_inst-obj_key = 'SERVICEMAT'.
APPEND contract_cfgs_inst TO contract_cfgs_inst_t.


contract_cfgs_part_of-config_id = '000010'.
contract_cfgs_part_of-inst_id = '000010'.
contract_cfgs_part_of-class_type = '300'.
contract_cfgs_part_of-obj_key = 'SERVICEMAT'.
APPEND contract_cfgs_part_of to contract_cfgs_part_of_t.

CALL FUNCTION 'BAPI_CONTRACT_CREATEFROMDATA'
  EXPORTING
    contract_header_in     = contract_header_in
 IMPORTING
   salesdocument          = lv_vbeln
  TABLES
   return                 = return
    contract_items_in      = contract_items_in
    contract_partners      = contract_partners
    contract_conditions_in = contract_conditions_in
    contract_cfgs_ref      = contract_cfgs_ref
    contract_cfgs_inst     = contract_cfgs_inst_t
   contract_cfgs_part_of  = contract_cfgs_part_of_t
   contract_cfgs_value    = contract_cfgs_value
    contract_data_in       = contract_data_in
    contract_data_inx      = contract_data_inx
  .

 CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
 message lv_vbeln type 'S'.