MB21 创建预留


一、MB21

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

 

 二、调用BAPI:BAPI_RESERVATION_CREATE1

"-----------------------------------------@斌将军--------------------------------------------
DATA
:ls_header TYPE bapi2093_res_head, 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'."标识,工厂日历是否应该检查 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 = 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.
"-----------------------------------------@斌将军--------------------------------------------

三、增强字段

里面涉及到特殊库存标识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() INDEX ls_resb_append-rspos. IF sy-subrc EQ 0. -sobkz = ls_resb_append-sobkz."特殊标识 ENDIF. ENDIF. ENDLOOP. ENDMETHOD.
"-----------------------------------------@斌将军--------------------------------------------

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