庫存盤點在作SCAN BARCODE之後依盤虧盤盈的結果依相同的PLANT與Storage Location BY BATCH 去作311 Movement
使用BAPI_GOODSMVT_CREATE 來處理異動
基本結構為六項:Header、gm_code、gm_head_ret、mat_doc、gm_item、return
REPORT ZBEN_AUTO_GT.************************************************************************* Data type definition segment*************************************************************************HeaderDATA: GM_HEADER LIKE BAPI2017_GM_HEAD_01.*GM_codeDATA: BEGIN OF GM_CODE. INCLUDE STRUCTURE BAPI2017_GM_CODE.DATA: END OF GM_CODE.*GM_head_retDATA: BEGIN OF GM_HEADRET. INCLUDE STRUCTURE BAPI2017_GM_HEAD_RET.DATA: END OF GM_HEADRET.*Mat_docDATA: MAT_DOC LIKE BAPI2017_GM_HEAD_RET-MAT_DOC.*GM_itemDATA: BEGIN OF GM_ITEM OCCURS 100. INCLUDE STRUCTURE BAPI2017_GM_ITEM_CREATE.DATA: END OF GM_ITEM.*Return MsgDATA: BEGIN OF ERRMSG OCCURS 10. INCLUDE STRUCTURE BAPIRET2.DATA: END OF ERRMSG.
************************************************************************* Selection screen definition segment************************************************************************PARAMETERS: P_MATNR LIKE MCHB-MATNR OBLIGATORY.PARAMETERS: P_WERKS LIKE MCHB-WERKS OBLIGATORY.PARAMETERS: P_LGORT LIKE MCHB-LGORT OBLIGATORY.
************************************************************************* Main program entry**************************************************************************HeaderGM_HEADER-PSTNG_DATE = '20091031'. "SY-DATUM.GM_HEADER-DOC_DATE = '20091031'. "SY-DATUM.** IF PACK_NO NE SPACE.* GM_HEADER-REF_DOC_NO = POITEM-PACK_NO "DELIVER NOTE - GR* GM_HEADER-HEADER_TXT = POITEM-PACK_NO " FOR GT** ENDIF.**CodeGM_CODE-GM_CODE = '04'.**ItemGM_ITEM-MATERIAL = ' 2C P 906011A F001'.GM_ITEM-PLANT = 1000.GM_ITEM-STGE_LOC = ' 14A 1'.GM_ITEM-BATCH = ' 5M C1680002'.GM_ITEM-MOVE_TYPE = '311'.GM_ITEM-MVT_IND = ''.GM_ITEM-ENTRY_QNT = 2.GM_ITEM-ENTRY_UOM = 'EA'.GM_ITEM-MOVE_STLOC = ' 1A 01'.GM_ITEM-NO_TRANSFER_REQ = 'X'.APPEND GM_ITEM.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'EXPORTINGGOODSMVT_HEADER = GM_HEADERGOODSMVT_CODE = GM_CODE "Transfer posting* IMPORTING* GOODSMVT_HEADRET = GM_HEADRET* MATERIALDOCUMENT = MAT_DOC* MATDOCUMENTYEAR = TABLESGOODSMVT_ITEM = GM_ITEMRETURN = ERRMSG EXCEPTIONSOTHERS = 1.
IF ERRMSG[] IS INITIAL. REFRESH: GM_ITEM, ERRMSG. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'.ELSE.* MESSAGE = ERRMSG-MESSAGE. EXIT.ENDIF.
沒有留言:
張貼留言