MB21 预留

1、MB21创建预留

1.1、MB21前台操作

输入物料等信息,保存即可

 

1.2、调用BAPI:BAPI_RESERVATION_CREATE1

"-----------------------------------------@斌将军--------------------------------------------
DATA
:ls_header TYPE bapi2093_res_head,
   ls_atpcheck    TYPE bapi2093_atpcheck, ls_calcheck
TYPE bapi2093_calcheck, lv_res TYPE bapi2093_res_key-reserv_no, lt_item TYPE TABLE OF bapi2093_res_item, ls_item TYPE bapi2093_res_item, lt_extensionin TYPE TABLE OF bapiparex WITH HEADER LINE, ls_resb_append TYPE zwms_resb_append, lt_pro TYPE TABLE OF bapi_profitability_segment, ls_pro TYPE bapi_profitability_segment, lt_return TYPE TABLE OF bapiret2, ls_return TYPE bapiret2. *ls_header-plant = '1000'."工厂 ls_header-res_date = '20220316'."预订基准日期 ls_header-move_type = '311'."移动类型 ls_header-vendor_no = '0000100000'."供应商 ls_header-move_plant = '1000'."收货工厂/发货工厂 ls_header-move_stloc = '1029'."收货/发货库存地点 *ls_header-costcenter = '1000'."成本中心 *ls_header-orderid = '1000'."订单号 *ls_header-wbs_elem = '1000'."WBS 要素 ls_calcheck-calcheck = 'X'."标识,工厂日历是否应该检查
ls_atpcheck-atpcheck 'X'."ATP检查
CLEAR:ls_item. ls_item-material = 'HYM01'."物料编号(18 个字符) ls_item-plant = '1000'."工厂 ls_item-stge_loc = '1001'."存储地点 ls_item-batch = ''."批次编号 ls_item-entry_qnt = 1."以录入项单位表示的数量 ls_item-entry_uom = 'ST'."条目单位 ls_item-req_date = '20220316'."组件的需求日期 ls_item-item_text = '111'."项目文本 APPEND ls_item TO lt_item. CLEAR:ls_resb_append. ls_resb_append-rspos = '1'. ls_resb_append-sobkz = 'Q'. lt_extensionin-structure = 'ZWMS_RESB_APPEND'. lt_extensionin-valuepart1 = ls_resb_append. APPEND lt_extensionin. CALL FUNCTION 'BAPI_RESERVATION_CREATE1' EXPORTING reservationheader = ls_header * TESTRUN =    atpcheck             = ls_atpcheck calcheck = ls_calcheck * RESERVATION_EXTERNAL = IMPORTING reservation = lv_res TABLES reservationitems = lt_item profitabilitysegment = lt_pro extensionin = lt_extensionin return = lt_return. IF lv_res IS NOT INITIAL. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ENDIF.
"-----------------------------------------@斌将军--------------------------------------------

1.3、增强字段

里面涉及到特殊库存标识SOBKZ,在RESB表中存在,但是在BAPI中没有,需要用增强导入

创建结构:

BADI:MB_RES_BAPI_CREATE1

  
"-----------------------------------------@斌将军--------------------------------------------
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_resb_append TYPE zwms_resb_append. LOOP AT it_extension_in INTO ls_extension. IF ls_extension-structure = 'ZWMS_RESB_APPEND'. ls_resb_append = ls_extension-valuepart1. READ TABLE resb ASSIGNING FIELD-SYMBOL(<fs_resb>) INDEX ls_resb_append-rspos. IF sy-subrc EQ 0. <fs_resb>-sobkz = ls_resb_append-sobkz."特殊标识 ENDIF. ENDIF. ENDLOOP. ENDMETHOD.
"-----------------------------------------@斌将军--------------------------------------------

调用BAPI时,传入特殊标识,RSPOS传入个行号就行

2、MB22修改预留

修改已完成标识

 调用BAPI:BAPI_RESERVATION_CHANGE

"-----------------------------------------@斌将军--------------------------------------------
DATA
:lv_reservation TYPE bapi2093_res_key-reserv_no, lt_reservationitems_changed TYPE TABLE OF bapi2093_res_item_change, ls_reservationitems_changed TYPE bapi2093_res_item_change, lt_reservationitems_changedx TYPE TABLE OF bapi2093_res_item_changex, ls_reservationitems_changedx TYPE bapi2093_res_item_changex, lt_reservationitems_new TYPE TABLE OF bapi2093_res_item_new, ls_reservationitems_new TYPE bapi2093_res_item_new, lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE. DATA:lv_check TYPE char1, lv_message TYPE char200. lv_reservation = 2989. CLEAR:ls_reservationitems_changed. ls_reservationitems_changed-res_item = 1."预留 / 相关需求的项目编号 ls_reservationitems_changed-withdrawn = 'X'."该预定的最后发货KZEAR APPEND ls_reservationitems_changed TO lt_reservationitems_changed. CLEAR:ls_reservationitems_changedx. ls_reservationitems_changedx-res_item = 1."预留 / 相关需求的项目编号 ls_reservationitems_changedx-withdrawn = 'X'."该预定的最后发货KZEAR APPEND ls_reservationitems_changedx TO lt_reservationitems_changedx. CALL FUNCTION 'BAPI_RESERVATION_CHANGE' EXPORTING reservation = lv_reservation TABLES reservationitems_changed = lt_reservationitems_changed reservationitems_changedx = lt_reservationitems_changedx * RESERVATIONITEMS_NEW = return = lt_return. 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 = 'X'. ENDIF.
"-----------------------------------------@斌将军--------------------------------------------

对于增强字段,需要看BADI:MB_RES_BAPI_CHANGE是否为SAP内部使用。

如果只被内部使用,则不能增强,就不能进入与创建相似的extensionin_to_resb方法中,不能实现与创建相同的增强字段更新逻辑

定期更文,欢迎关注

 
 
 
 
 
 
 
 
 
 
 
 
posted @ 2022-03-16 17:02  斌将军  阅读(949)  评论(0编辑  收藏  举报