2009年11月10日 星期二

BAPI_GOODSMVT_CREATE

庫存盤點在作SCAN BARCODE之後依盤虧盤盈的結果依相同的PLANTStorage Location BY BATCH 去作311 Movement
使用BAPI_GOODSMVT_CREATE 來處理異動
基本結構為六項:Headergm_codegm_head_retmat_docgm_itemreturn


REPORT  ZBEN_AUTO_GT.
************************************************************************
* Data type definition segment
************************************************************************
*Header
DATA: GM_HEADER LIKE BAPI2017_GM_HEAD_01.
*GM_code
DATA: BEGIN OF GM_CODE.
    INCLUDE STRUCTURE BAPI2017_GM_CODE.
DATA: END OF GM_CODE.
*GM_head_ret
DATA: BEGIN OF GM_HEADRET.
    INCLUDE STRUCTURE BAPI2017_GM_HEAD_RET.
DATA: END OF GM_HEADRET.
*Mat_doc
DATA: MAT_DOC LIKE BAPI2017_GM_HEAD_RET-MAT_DOC.
*GM_item
DATA: BEGIN OF GM_ITEM OCCURS 100.
    INCLUDE STRUCTURE BAPI2017_GM_ITEM_CREATE.
DATA: END OF GM_ITEM.
*Return Msg
DATA: 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
************************************************************************
**Header
GM_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.
**Code
GM_CODE-GM_CODE = '04'.
**Item
GM_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'
EXPORTING
GOODSMVT_HEADER    = GM_HEADER
GOODSMVT_CODE = GM_CODE   "Transfer posting
*   IMPORTING
*    GOODSMVT_HEADRET = GM_HEADRET
*    MATERIALDOCUMENT = MAT_DOC
*    MATDOCUMENTYEAR   =
  TABLES
GOODSMVT_ITEM = GM_ITEM
RETURN     = ERRMSG
  EXCEPTIONS
OTHERS     = 1.

IF ERRMSG[] IS INITIAL.
  REFRESH: GM_ITEM, ERRMSG.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
  WAIT = 'X'.
ELSE.
*  MESSAGE = ERRMSG-MESSAGE.
  EXIT.
ENDIF.

沒有留言:

張貼留言