干货:
前面两篇文章分别介绍了销售订单抬头和行项目上屏幕增强的案例。
屏幕上增加了俩字段,那BAPI创建修改的时候怎么处理?
怎么把增强字段值写进去?
使用BAPI的EXTENSIONIN参数
可以增强的表有VBAP VBAK VBEP
Adjust the following structures for customer enhancements to table VBAP:
a) VBAPKOZ
b) VBAPKOZX
c) BAPE_VBAP
d) BAPE_VBAPX
If you need to use custom fields for VBAK you must adjust the following structures for customer enhancements to table VBAK:
a) VBAKKOZ
b) VBAKKOZX
c) BAPE_VBAK
d) BAPE_VBAKX
If you need to use custom fields for VBEP you must adjust the following structures for customer enhancements to table VBEP:
a) VBEPKOZ
b) VBEPKOZX
c) BAPE_VBEP
d) BAPE_VBEPX
告知了如果要使用bapi做增强的话,需要增强的表和结构
接着上次的案例,增强了VBAK VBAP,所以还需要维护另外的八个结构
item:
Header:
然后BAPI参考如下
REPORT zlm_create_so.标签:03,增强,inx,partners,Demo,lt,ls,extensionin,order From: https://blog.51cto.com/u_15680210/5757802
PARAMETERS p_kunnr TYPE kunnr DEFAULT '1001'.
PARAMETERS p_vkorg TYPE vkorg DEFAULT '1000'.
PARAMETERS p_vtweg TYPE vtweg DEFAULT '12'.
PARAMETERS p_spart TYPE spart DEFAULT '00'.
PARAMETERS p_werks TYPE werks_d DEFAULT '1200'.
PARAMETERS p_lgort TYPE lgort_d DEFAULT ' '.
PARAMETERS p_vstel TYPE vstel DEFAULT '1200'.
PARAMETERS p_matnr TYPE matnr DEFAULT 'L-40F'.
DATA:ls_order_header_in LIKE bapisdhd1.
DATA:ls_order_header_inx LIKE bapisdhd1x.
DATA:lt_order_items_in LIKE TABLE OF bapisditm.
DATA:lt_order_items_inx LIKE TABLE OF bapisditmx.
DATA:ls_order_items_in LIKE bapisditm.
DATA:ls_order_items_inx LIKE bapisditmx.
DATA:lt_order_partners LIKE TABLE OF bapiparnr.
DATA:ls_order_partners LIKE LINE OF lt_order_partners.
DATA:lt_schedules_in LIKE TABLE OF bapischdl .
DATA:lt_schedules_inx LIKE TABLE OF bapischdlx .
DATA:ls_schedules_in LIKE bapischdl .
DATA:ls_schedules_inx LIKE bapischdlx .
DATA:lt_order_conditions_in LIKE TABLE OF bapicond .
DATA:lt_order_conditions_inx LIKE TABLE OF bapicondx .
DATA:ls_order_conditions_in LIKE bapicond .
DATA:ls_order_conditions_inx LIKE bapicondx .
DATA: lt_return LIKE TABLE OF bapiret2.
DATA: ls_return LIKE bapiret2.
DATA:lv_salesdocument LIKE bapivbeln-vbeln.
DATA:ls_bape_vbap TYPE bape_vbap,
ls_bape_vbapx TYPE bape_vbapx.
DATA:ls_bape_vbakx TYPE bape_vbakx.
DATA:ls_bape_vbak TYPE bape_vbak.
DATA:lt_extensionin LIKE TABLE OF bapiparex.
DATA:ls_extensionin LIKE bapiparex.
CLEAR ls_order_header_in.
ls_order_header_in-doc_type = 'TA'."订单类型
ls_order_header_in-sales_org = p_vkorg.
ls_order_header_in-distr_chan = p_vtweg."分销渠道
ls_order_header_in-division = p_spart."产品组
ls_order_header_in-purch_no_c = 'test'.
CLEAR ls_order_header_inx.
ls_order_header_inx-doc_type = 'X'.
ls_order_header_inx-sales_org = 'X'.
ls_order_header_inx-distr_chan = 'X'.
ls_order_header_inx-division = 'X'.
*ls_order_header_inx-sales_off = 'X'.
ls_order_header_inx-ass_number = 'X'.
ls_order_header_inx-updateflag = '1'.
ls_order_header_inx-purch_no_c = 'X'.
CLEAR ls_order_items_in.
CLEAR lt_order_items_in[].
ls_order_items_in-itm_number = '10'."只有一个行项目
ls_order_items_in-material = p_matnr.
ls_order_items_in-plant = p_werks.
ls_order_items_in-store_loc = p_lgort.
ls_order_items_in-target_qty = 1.
ls_order_items_in-ship_point = p_vstel."装运点
ls_order_items_in-target_qu = 'KAR'.
ls_order_items_in-sales_unit = 'KAR'.
APPEND ls_order_items_in TO lt_order_items_in.
CLEAR lt_schedules_in[].
CLEAR ls_schedules_in.
ls_schedules_in-itm_number = '10'."只有一个行项目
ls_schedules_in-req_qty = 1.
APPEND ls_schedules_in TO lt_schedules_in.
CLEAR ls_schedules_inx.
CLEAR lt_schedules_inx[].
ls_schedules_inx-updateflag = 'X'.
ls_schedules_inx-itm_number = 'X'.
ls_schedules_inx-req_qty = 'X'.
APPEND ls_schedules_inx TO lt_schedules_inx.
"售达方默认
CLEAR ls_order_partners.
ls_order_partners-partn_role = 'AG'.
ls_order_partners-partn_numb = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.
"送达方
CLEAR ls_order_partners.
ls_order_partners-partn_role = 'WE'.
ls_order_partners-partn_numb = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.
"付款方
CLEAR ls_order_partners.
ls_order_partners-partn_role = 'RE'.
ls_order_partners-partn_numb = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.
"收票方
CLEAR ls_order_partners.
ls_order_partners-partn_role = 'RG'.
ls_order_partners-partn_numb = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.
*&------------------------针对 增强字段的赋值------------------------------
CLEAR ls_extensionin.
CLEAR lt_extensionin[].
*& header 增强字段赋值
ls_bape_vbak-zlm_comment = 'ZLM_COMMENT'.
ls_extensionin-structure = 'BAPE_VBAK'.
CALL METHOD cl_abap_container_utilities=>fill_container_c
EXPORTING
im_value = ls_bape_vbak
IMPORTING
ex_container = ls_extensionin-valuepart1.
APPEND ls_extensionin TO lt_extensionin.
CLEAR ls_extensionin.
ls_bape_vbakx-zlm_comment = 'X'.
ls_extensionin-structure = 'BAPE_VBAKX'.
ls_extensionin-valuepart1 = ls_bape_vbakx.
APPEND ls_extensionin TO lt_extensionin.
CLEAR ls_extensionin.
*& item 增强字段赋值
ls_bape_vbap-vbeln = space.
ls_bape_vbap-posnr = '000010'.
ls_bape_vbap-item_comment = 'ITEM_COMMENT'.
ls_extensionin-structure = 'BAPE_VBAP'.
CALL METHOD cl_abap_container_utilities=>fill_container_c
EXPORTING
im_value = ls_bape_vbap
IMPORTING
ex_container = ls_extensionin-valuepart1.
APPEND ls_extensionin TO lt_extensionin.
CLEAR ls_extensionin.
ls_bape_vbapx-vbeln = space.
ls_bape_vbapx-posnr = '000010'.
ls_bape_vbapx-item_comment = 'X'.
ls_extensionin-structure = 'BAPE_VBAPX'.
ls_extensionin-valuepart1 = ls_bape_vbapx.
APPEND ls_extensionin TO lt_extensionin.
*&------------------------*&------------------------*&------------------------
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = ls_order_header_in
order_header_inx = ls_order_header_inx
IMPORTING
salesdocument = lv_salesdocument
TABLES
return = lt_return
order_items_in = lt_order_items_in
order_items_inx = lt_order_items_inx
order_partners = lt_order_partners
order_schedules_in = lt_schedules_in
order_schedules_inx = lt_schedules_inx
extensionin = lt_extensionin.
IF lv_salesdocument IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
WRITE lv_salesdocument