一、事务代码VA41
合同创建的过程和销售订单几乎一致
二、调用BAPI
调用BAPI为BAPI_CONTRACT_CREATEFROMDATA
传参和销售订单BAPI:BAPI_SALESORDER_CREATEFROMDAT2一致
"-----------------------------@斌将军-----------------------------
DATA: ls_header_in TYPE bapisdhd1,
ls_header_inx TYPE bapisdhd1x,
lv_vbeln LIKE vbak-vbeln,
ls_logic_switch TYPE bapisdls,
lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE,
lt_items_in TYPE TABLE OF bapisditm WITH HEADER LINE,
lt_items_inx TYPE TABLE OF bapisditmx WITH HEADER LINE,
lt_partners TYPE TABLE OF bapiparnr WITH HEADER LINE,
lt_partnerchanges TYPE TABLE OF bapiparnrc WITH HEADER LINE,
lt_schedules_in TYPE TABLE OF bapischdl WITH HEADER LINE,
lt_schedules_inx TYPE TABLE OF bapischdlx WITH HEADER LINE,
lt_conditions_in TYPE TABLE OF bapicond WITH HEADER LINE,
lt_conditions_inx TYPE TABLE OF bapicondx WITH HEADER LINE,
lt_partneraddresses TYPE TABLE OF bapiaddr1 WITH HEADER LINE,
order_cfgs_ref TYPE TABLE OF bapicucfg WITH HEADER LINE,
order_cfgs_inst TYPE TABLE OF bapicuins WITH HEADER LINE,
order_cfgs_value TYPE TABLE OF bapicuval WITH HEADER LINE.
DATA:lv_check TYPE char1,
lv_message TYPE char200,
lv_update TYPE char1 VALUE 'I'.
CLEAR:ls_header_in.
ls_header_in-doc_type = 'Z100'."i_head-auart."销售凭证类型
ls_header_in-sales_org = '1010'."i_head-vkorg ."销售组织
ls_header_in-distr_chan = '00'."i_head-vtweg."分销渠道
ls_header_in-division = '00'."i_head-spart."产品组
ls_header_in-purch_no_c = '20220905'."i_head-bstkd."客户参考日期
ls_header_in-cust_grp3 = 'Z00'."i_head-kvgr3."订单变更原因
ls_header_in-created_by = 'LCC'."i_head-ernam."制单工号
* ls_header_in-sales_grp = i_head-vkgrp."销售组
* ls_header_in-sales_off = i_head-vkbur."销售办事处
*
* ls_header_in-sd_doc_cat = i_head-."SD 凭证类别
* ls_header_in-doc_date = sy-datum."凭证日期 (接收/发送日期)
* ls_header_in-price_date = i_head-."定价日期和汇率
* ls_header_in-exchg_rate = i_head-."定价和统计直接引用的汇率
* ls_header_in-dlvschduse = 'QQQ'."l_abrvw. "使用标识
* ls_header_in-ship_type = i_head-vsart. "装运类型
* ls_header_in-s_proc_ind = 'QQQ'."lt_reslut-sdabw. "特殊标识
* ls_header_in-pymt_meth = i_head-zlsch. "付款方式
* ls_header_in-pmnttrms = i_head-zterm. "付款条件
* ls_header_in-ref_1 = i_head-ihrez."你的参考 CRM 订单号
* ls_header_in-incoterms1 = i_head-inco1."贸易条款
CLEAR:ls_header_inx.
ls_header_inx-updateflag = lv_update."更新标识
ls_header_inx-sales_org = abap_true ."销售组织
ls_header_inx-distr_chan = abap_true."分销渠道
ls_header_inx-division = abap_true."产品组
ls_header_inx-purch_no_c = abap_true."客户参考
ls_header_inx-cust_grp3 = abap_true."订单变更原因
* ls_header_inx-created_by = abap_true."制单工号
* ls_header_inx-sales_grp = abap_true."销售组
* ls_header_inx-sales_off = abap_true."销售办事处
*
* ls_header_inx-sd_doc_cat = abap_true."SD 凭证类别
* ls_header_inx-doc_date = abap_true."凭证日期 (接收/发送日期)
* ls_header_inx-price_date = abap_true."定价日期和汇率
* ls_header_inx-exchg_rate = abap_true."定价和统计直接引用的汇率
* ls_header_inx-dlvschduse = abap_true. "使用标识
* ls_header_inx-ship_type = abap_true. "装运类型
* ls_header_inx-s_proc_ind = abap_true. "特殊标识
* ls_header_inx-pymt_meth = abap_true. "付款方式
* ls_header_in-pmnttrms = abap_true. "付款条件
* ls_header_inx-ref_1 = abap_true."你的参考 CRM 订单号
* ls_header_inx-incoterms1 = abap_true."贸易条款
* IF i_head-kunag IS NOT INITIAL.
lt_partners-partn_role = 'AG'."合作伙伴功能
lt_partners-partn_numb = '0001000000'.
APPEND lt_partners.
lt_partners-partn_role = 'WE'."合作伙伴功能
lt_partners-partn_numb = '0004000000'.
APPEND lt_partners.
* ENDIF.
* LOOP AT t_item.
CLEAR lt_items_in.
lt_items_in-itm_number = '10'."t_item-posnr."行项目
lt_items_in-material = '000000160000000006'."t_item-matnr."物料
lt_items_in-plant = '1011'."t_item-werks."工厂
lt_items_in-sales_unit = 'EA'."t_item-vrkme."单位
lt_items_in-tax_class1 = '1'."t_item-taxm1."物料税分类
* lt_items_in-store_loc = '1011'."t_item-lgort."库存地点
APPEND lt_items_in.
CLEAR lt_items_inx.
lt_items_inx-updateflag = lv_update."更新标识
lt_items_inx-itm_number = '10'.
lt_items_inx-material = abap_true.
lt_items_inx-plant = abap_true.
lt_items_inx-sales_unit = abap_true.
lt_items_inx-tax_class1 = abap_true.
* lt_items_inx-store_loc = abap_true.
APPEND lt_items_inx.
* schedules
CLEAR lt_schedules_in.
lt_schedules_in-itm_number = '10'."."行项目
lt_schedules_in-req_qty = '1'."t_item-kwmeng."以销售单位计的订单数量
lt_schedules_in-req_date = '20220908'."t_item-etdat."交货日期
APPEND lt_schedules_in.
CLEAR lt_schedules_inx.
lt_schedules_inx-updateflag = lv_update."更新标识
lt_schedules_inx-itm_number = '10'."t_item-posnr."行项目
lt_schedules_inx-req_qty = abap_true."以销售单位计的订单数量
lt_schedules_inx-req_date = abap_true."交货日期
APPEND lt_schedules_inx.
CLEAR:lt_conditions_in.
lt_conditions_in-itm_number = '10'."t_item-posnr. "行项目
lt_conditions_in-cond_type = 'ZP00'. "定价条件
lt_conditions_in-cond_value = '10'."t_item-kzwi1."条件金额
lt_conditions_in-currency = 'CNY'. "货币码
lt_conditions_in-cond_p_unt = '1'. "条件单位
APPEND lt_conditions_in.
CLEAR:lt_conditions_inx.
lt_conditions_inx-updateflag = lv_update."更新标识
lt_conditions_inx-itm_number = '10'."t_item-posnr."行项目
lt_conditions_inx-cond_type = 'ZP00'. "定价条件
lt_conditions_inx-cond_value = abap_true.
lt_conditions_inx-currency = abap_true.
lt_conditions_inx-cond_p_unt = abap_true.
APPEND lt_conditions_inx.
* ENDLOOP.
ls_logic_switch = 'G'.
CALL FUNCTION 'BAPI_CONTRACT_CREATEFROMDATA'
EXPORTING
* SALESDOCUMENTIN =
contract_header_in = ls_header_in
contract_header_inx = ls_header_inx
* SENDER =
* BINARY_RELATIONSHIPTYPE = ' '
* INT_NUMBER_ASSIGNMENT = ' '
* BEHAVE_WHEN_ERROR = ' '
logic_switch = ls_logic_switch
IMPORTING
salesdocument = lv_vbeln
TABLES
return = lt_return
contract_items_in = lt_items_in
contract_items_inx = lt_items_inx
contract_partners = lt_partners
contract_conditions_in = lt_conditions_in
contract_conditions_inx = lt_conditions_inx
contract_cfgs_ref = order_cfgs_ref
contract_cfgs_inst = order_cfgs_inst
contract_cfgs_value = order_cfgs_value
partneraddresses = lt_partneraddresses.
CLEAR:lv_check,lv_message.
LOOP AT lt_return WHERE type CA 'EAX'.
lv_message = lv_message && lt_return-message.
lv_check = 'E'.
ENDLOOP.
IF lv_check = 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
ENDIF.
"-----------------------------@斌将军-----------------------------
定期更文,欢迎关注