We can use BAPI_RESERVATION_CREATE1 for tcode mb21 to create order.
But it do not have field werks lgort umwrk umlgo stock. So we need to enhancement.
BADI: MB_RES_BAPI_CREATE1 for MB21.
创建项目预留的增强
在系统标准功能中使用MB21不能创建项目预留,
因此需要用BAPI:BAPI_RESERVATION_CREATE1来创建项目预留,
但BAPI里面没有提供可以传入特殊库存字段从而创建特殊预留的功能本中心,因此需要增强此BAPI。
触发时间:
用BAPI_RESERVATION_CREATE1创建预留时触发。
增强步骤:
1、使用TCODE:SE11创建结构ZSRESB_APPEND。
Fields:
RSPOS
SOBKZ
PSPEL
KNTTP
KZBWS
UMWRK
UMLGO
2、使用事务代码SE19实施BADI: MB_RES_BAPI_CREATE1,
创建实施BADI:ZMB_RES_BAPI_CREATE1
对BADI中的方法EXTENSIONIN_TO_RESB进行实施。
METHOD if_ex_mb_res_bapi_create1~extensionin_to_resb.
DATA: ls_extension LIKE LINE OF it_extension_in.
DATA: ls_resb LIKE LINE OF resb.
DATA: ls_zresb TYPE zsresb_append.
DATA: l_index TYPE sy-tabix.
break zzwanglp.
break handshiwh.
break handqiuy.
LOOP AT it_extension_in INTO ls_extension.
IF ls_extension-structure = ‘ZSRESB_APPEND’.
MOVE ls_extension-valuepart1 TO ls_zresb-rspos.
MOVE ls_extension-valuepart2 TO ls_zresb-sobkz.
MOVE ls_extension-valuepart3 TO ls_zresb-pspel.
MOVE ls_extension-valuepart4+0(1) TO ls_zresb-knttp.
MOVE ls_extension-valuepart4+1(1) TO ls_zresb-kzbws.
READ TABLE resb INTO ls_resb INDEX ls_zresb-rspos.
IF sy-subrc IS INITIAL.
ls_resb-sobkz = ls_zresb-sobkz.
ls_resb-pspel = ls_zresb-pspel.
ls_resb-knttp = ls_zresb-knttp.
ls_resb-kzbws = ls_zresb-kzbws.
ls_resb-umwrk = ls_zresb-umwrk.
MODIFY resb FROM ls_resb INDEX ls_zresb-rspos TRANSPORTING sobkz pspel knttp kzbws .
ENDIF.
ENDIF.
ENDLOOP.
ENDMETHOD.
3、使用BAPI:BAPI_RESERVATION_CREATE1创建项目预留,代码如下所示:
* 预留创建数据定义
DATA: BEGIN OF ls_header.
INCLUDE STRUCTURE bapi2093_res_head.
DATA: END OF ls_header.
DATA: BEGIN OF lt_item OCCURS 0.
INCLUDE STRUCTURE bapi2093_res_item.
DATA: END OF lt_item.
DATA: BEGIN OF lt_return OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA: END OF lt_return.
DATA: BEGIN OF lt_ext OCCURS 0.
INCLUDE STRUCTURE bapiparex.
DATA: END OF lt_ext.
DATA: BEGIN OF lt_pro OCCURS 0.
INCLUDE STRUCTURE bapi_profitability_segment.
DATA: END OF lt_pro.
DATA l_rspos LIKE resb-rspos.
DATA: wa_resb TYPE zresb_extend.
CLEAR wa_resb.
CLEAR g_rsnum.
CLEAR l_rspos.
PERFORM clear_bapi_data.
CLEAR:it_mm_resb,it_mm_resb[].
ls_header–res_date = sy–datum. “基准日期
ls_header-move_type = wa_mm_087-bwart . “移动类型
ls_header-created_by = sy-uname.
ls_header-move_plant = p_werks.
ls_header-move_stloc = p_umlgo.
* ls_header-wbs_element = p_pspnr.
LOOP AT it_tab INTO wa_tab WHERE check = ‘X’.
lt_item-material = wa_tab-matnr. “物料编码WWW.HOT583.COM
lt_item-entry_qnt = wa_tab-bdmng. “需求数量
lt_item-plant = wa_tab-werks. “库存地点
lt_item-movement = ‘X’. “允许预留的货物移动www.hot583.com
lt_item-acct_man = ‘X’.
lt_item-gl_account = wa_mm_087-hkont . “总账科目
lt_item-item_text = wa_tab-sgtxt. “行文本
l_rspos = l_rspos + 1.
IF c2 = ‘X’.
CLEAR wa_mm_resb.
wa_mm_resb-rspos = l_rspos.
wa_mm_resb-umlgo = wa_tab-umlgo.
wa_mm_resb-umpla = wa_tab-umpla.
APPEND wa_mm_resb TO it_mm_resb.
lt_item-acct_man = ”.
lt_ext-structure = ‘ZSRESB_APPEND’.
lt_ext-valuepart1 = l_rspos.
lt_ext-valuepart4 = wa_resb.
APPEND lt_ext.
ENDIF.
IF c1 = ‘X’.
lt_ext–structure = ‘ZSRESB_APPEND’.
lt_ext–valuepart1 = l_rspos.
lt_ext–valuepart2 = ‘Q’.
lt_ext–valuepart3 = wa_tab–pspel.
wa_resb–knttp = ‘Q’.
wa_resb–kzbws = ‘M’.
lt_ext–valuepart4 = wa_resb.
APPEND lt_ext.
ENDIF.
APPEND lt_item.
ENDLOOP.
CALL FUNCTION ‘BAPI_RESERVATION_CREATE1’
EXPORTING
reservationheader = ls_header
IMPORTING
reservation = p_rsnum
TABLES
reservationitems = lt_item
return = lt_return
extensionin = lt_ext
profitabilitysegment = lt_pro.
我的微信公众号【 hot583 】 或者在这个链接联系我
本文链接 : http://www.hot583.com/2022/07/05/sample_interface_00001650/
本文为作者原创,如果这篇文章对您有用,欢迎转载,
转载请务必注明来源《今日热点在看》http://www.hot583.com/
微信原文《全文完》