1. GM_Code 01: Goods receipt for purchase order
2. GM_Code 02: Goods receipt for production order
3. GM_Code 03: Goods issue
4. GM_Code 04: Transfer posting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | IV_AUFNR Importing Type AUFNR METHOD CREATE_GOODSMOVEMENT_TO_ORDER. DATA: ls_goodsmvt_header TYPE bapi2017_gm_head_01, ls_goodsmvt_code TYPE bapi2017_gm_code, lt_return2 TYPE bapiret2_t, lv_mblpo TYPE mblpo, lt_order_component TYPE TABLE OF bapi_order_component, lt_order_header TYPE TABLE OF bapi_order_header1, lt_goodsmvt_item TYPE TABLE OF bapi2017_gm_item_create. FIELD-SYMBOLS: <fs_goodsmvt_item> LIKE LINE OF lt_goodsmvt_item, <fs_order_component> LIKE LINE OF lt_order_component. ls_goodsmvt_header-pstng_date = sy-datum. ls_goodsmvt_header-doc_date = sy-datum. ls_goodsmvt_code-gm_code = '02'. get_order_component( EXPORTING aufnr = iv_aufnr IMPORTING order_component = lt_order_component order_header = lt_order_header return2 = lt_return2 ). lv_mblpo = 0. LOOP AT lt_order_component ASSIGNING <fs_order_component> WHERE movement_type = '101' AND storage_location IS NOT INITIAL. lv_mblpo = lv_mblpo + 1. APPEND INITIAL LINE TO lt_goodsmvt_item ASSIGNING <fs_goodsmvt_item>. <fs_goodsmvt_item>-orderid = iv_aufnr. <fs_goodsmvt_item>-order_itno = lv_mblpo. <fs_goodsmvt_item>-material = <fs_order_component>-material. <fs_goodsmvt_item>-plant = <fs_order_component>-prod_plant. <fs_goodsmvt_item>-stge_loc = <fs_order_component>-storage_location. <fs_goodsmvt_item>-entry_qnt = <fs_order_component>-req_quan. <fs_goodsmvt_item>-entry_uom = <fs_order_component>-entry_uom. <fs_goodsmvt_item>-quantity = <fs_order_component>-req_quan. <fs_goodsmvt_item>-base_uom = <fs_order_component>-base_uom. <fs_goodsmvt_item>-batch = <fs_order_component>-batch. <fs_goodsmvt_item>-move_type = <fs_order_component>-movement_type. <fs_goodsmvt_item>-mvt_ind = 'F'. UNASSIGN <fs_goodsmvt_item>. ENDLOOP. CALL FUNCTION 'BAPI_GOODSMVT_CREATE' EXPORTING goodsmvt_header = ls_goodsmvt_header goodsmvt_code = ls_goodsmvt_code TABLES goodsmvt_item = lt_goodsmvt_item return = lt_return2. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'. ENDMETHOD. |