创建主合同函数为SD_SALESDOCUMENT_CREATE,参数business_object 值应设置为 ‘BUS2095’;
创建设备合同BAPI为BAPI_CONTRACT_CREATEFROMDATA,通过表extensionin 可传入增强数据
代码仅为实现功能测试,如下
FUNCTION zc_contract_order_create.
*"----------------------------------------------------------------------
*"*"局部接口:
*"----------------------------------------------------------------------
DATA: ls_header TYPE bapisdhd1,
lt_header TYPE TABLE OF bapisdhd1,
ls_header_x TYPE bapisdhd1x,
lt_header_x TYPE TABLE OF bapisdhd1x,
ls_item TYPE bapisditm,
lt_item TYPE TABLE OF bapisditm,
ls_item_x TYPE bapisditmx,
lt_item_x TYPE TABLE OF bapisditmx,
ls_condition1 TYPE bapicond,
lt_condition1 TYPE TABLE OF bapicond,
ls_condition1_x TYPE bapicondx,
lt_condition1_x TYPE TABLE OF bapicondx,
ls_condition2 TYPE bapicond,
lt_condition2 TYPE TABLE OF bapicond,
ls_condition2_x TYPE bapicondx,
lt_condition2_x TYPE TABLE OF bapicondx,
ls_condition3 TYPE bapicond,
lt_condition3 TYPE TABLE OF bapicond,
ls_condition3_x TYPE bapicondx,
lt_condition3_x TYPE TABLE OF bapicondx,
ls_partner TYPE bapiparnr,
lt_partner TYPE TABLE OF bapiparnr,
ls_extensionin LIKE bapiparex,
lt_extensionin LIKE TABLE OF bapiparex,
ls_bape_vbak TYPE bape_vbak,
ls_bape_vbakx TYPE bape_vbakx.
DATA:lv_vbeln TYPE bapivbeln-vbeln,
lt_message TYPE TABLE OF bapiret2.
* 创建主合同
ls_header-ct_valid_f = '20200101'.
ls_header_x-ct_valid_f = 'X'.
ls_header-ct_valid_t = '20200101'.
ls_header_x-ct_valid_t = 'X'.
ls_header-refdoc_cat = 'G'.
ls_header_x-refdoc_cat = 'X'.
ls_header-doc_type = 'ZGK1'.
ls_header_x-doc_type = 'X'.
ls_header-sales_org = '1000'.
ls_header_x-sales_org = 'X'.
ls_header-distr_chan = '10'.
ls_header_x-distr_chan = 'X'.
ls_header-division = '00'.
ls_header_x-division = 'X'.
ls_header-pp_search = 'SA00108896/TEST'.
ls_header_x-pp_search = 'X'.
ls_header_x-updateflag = 'I'.
"partner data
ls_partner-partn_role = 'AG'.
ls_partner-partn_numb = '0000200067'.
APPEND ls_partner TO lt_partner.
ls_partner-partn_role = 'WE'.
ls_partner-partn_numb = '0000200067'.
APPEND ls_partner TO lt_partner.
* 创建主合同
CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
EXPORTING
salesdocument = 'O10040007'"主合同号
sales_header_in = ls_header
sales_header_inx = ls_header_x
business_object = 'BUS2095'
IMPORTING
salesdocument_ex = lv_vbeln
TABLES
return = lt_message
sales_partners = lt_partner.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
* 创建设备合同
* 更改header为设备和通数据
ls_header-doc_type = 'ZCQ1'.
ls_header-purch_no_c = 'SA10040007'.
ls_header_x-purch_no_c = 'X'.
* 录入项目数据
ls_item-itm_number = '000010'.
ls_item_x-itm_number = '000010'.
ls_item-material = '000000000030001848'.
ls_item_x-material = 'X'.
ls_item-plant = '1100'.
ls_item_x-plant = 'X'.
ls_item-target_qty = 1.
ls_item_x-target_qty = 'X'.
ls_item-target_qu = 'PC'.
ls_item_x-target_qu = 'X'.
ls_item-item_categ = 'ZKMN'.
ls_item_x-item_categ = 'X'.
ls_item_x-updateflag = 'I'.
APPEND ls_item TO lt_item.
APPEND ls_item_x TO lt_item_x.
*Creation of Dealer sponsorship
"condtion data
ls_condition1-itm_number = '000010'.
ls_condition1-cond_type = 'ZR01'.
ls_condition1-cond_value = '1000'.
* ls_condition1-cond_unit = 'PC'.
* ls_condition1-cond_p_unt = 1.
ls_condition1_x-itm_number = '000010'.
ls_condition1_x-cond_type = 'ZR01'.
ls_condition1_x-cond_value = 'X'.
* ls_condition1_x-cond_unit = 'X'.
* ls_condition1_x-cond_p_unt = 'X'.
APPEND ls_condition1 TO lt_condition1.
APPEND ls_condition1_x TO lt_condition1_x.
* 合同号和主合同号增强
ls_extensionin-structure = 'BAPE_VBAK'.
ls_bape_vbak-vbeln = 'SA10040008'."合同号
ls_bape_vbak-vbelh = 'O10040008'."主合同
ls_bape_vbak-mbqsr = 'B'.
ls_bape_vbak-mbqx = '12'.
ls_extensionin-valuepart1 = ls_bape_vbak.
APPEND ls_extensionin TO lt_extensionin.
ls_extensionin-structure = 'BAPE_VBAKX'.
ls_bape_vbakx-vbeln = 'X'.
ls_bape_vbakx-vbelh = 'X'.
ls_bape_vbakx-mbqsr = 'X'.
ls_bape_vbakx-mbqx = 'X'.
ls_extensionin-valuepart1 = ls_bape_vbakx.
APPEND ls_extensionin TO lt_extensionin.
CALL FUNCTION 'BAPI_CONTRACT_CREATEFROMDATA'
EXPORTING
salesdocumentin = 'SA10040008' "合同号
contract_header_in = ls_header
contract_header_inx = ls_header_x
convert = 'X'
IMPORTING
salesdocument = lv_vbeln
TABLES
return = lt_message
contract_items_in = lt_item
contract_items_inx = lt_item_x
contract_partners = lt_partner
contract_conditions_in = lt_condition1
contract_conditions_inx = lt_condition1_x
extensionin = lt_extensionin.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ENDIF.
ENDFUNCTION.