移动标识:MVT_IND

,
  • 移动标识:MVT_IND
  • 货物移动事务代码:GM_CODE
    • 01 MB01 按采购订单的货物移动
    • 02 MB31 按生产订单的货物移动
    • 03 MB1A 货物提取(工单退料)
    • 04 MB1B 转移过帐
    • 05 MB1C 其他收货
    • 06 MB11 货物移动
    • 07 MB04 "物料供应"消耗的事后调整
DATA LS_HEADER         TYPE BAPI2017_GM_HEAD_01.
DATA LS_CODE           TYPE BAPI2017_GM_CODE.
DATA LV_REDOC          TYPE BAPI2017_GM_HEAD_RET-MAT_DOC.     "返回的凭证号码
DATA LT_ITEM           TYPE STANDARD TABLE OF BAPI2017_GM_ITEM_CREATE.
DATA LS_ITEM           TYPE BAPI2017_GM_ITEM_CREATE.
DATA LT_RETURN         TYPE STANDARD TABLE OF BAPIRET2.
DATA LS_RETURN         TYPE BAPIRET2.


"抬头数据
LS_HEADER-PSTNG_DATE = SY-DATUM.
LS_HEADER-DOC_DATE = SY-DATUM.

"分配事务代码--过账码
LS_CODE-GM_CODE = '03'.

"ITEM
CLEAR GS_ALV.
LOOP AT GT_ALV INTO GS_ALV WHERE SEL = 'X'.
  LS_ITEM-MATERIAL = GS_ALV-MATNR1.             "料号
  LS_ITEM-PLANT = GS_ALV-WERKS.                 "工厂
  LS_ITEM-STGE_LOC = GS_ALV-LGORT.              "库存地点
  LS_ITEM-MOVE_TYPE = '261'.                    "移动类型(库存管理)
  LS_ITEM-ORDERID =   GS_ALV-AUFNR.             "工单
  LS_ITEM-RESERV_NO = GS_ALV-RSNUM.             "预留/相关需求的编号 RESB~RSNUM
  LS_ITEM-RES_ITEM = GS_ALV-RSPOS.              "预留/相关需求的项目编号 RESB~RSPOS
  LS_ITEM-ENTRY_QNT = GS_ALV-ZCMNG.           "发料数量
  LS_ITEM-ENTRY_UOM = GS_ALV-MEINS.             "计量单位

  APPEND LS_ITEM TO LT_ITEM.
ENDLOOP.

"BAPI
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
  GOODSMVT_HEADER  = LS_HEADER
  GOODSMVT_CODE    = LS_CODE
IMPORTING
  MATERIALDOCUMENT = LV_REDOC
TABLES
  GOODSMVT_ITEM    = LT_ITEM
  RETURN           = LT_RETURN.

IF ( LINE_EXISTS( LT_RETURN[ TYPE = 'A' ] ) ) OR ( LINE_EXISTS( LT_RETURN[ TYPE = 'E' ] ) ).
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

  DATA: LT_MSG_TAB TYPE ESP1_MESSAGE_TAB_TYPE,
        WA_MSG_TAB LIKE LINE OF LT_MSG_TAB.

  LOOP AT LT_RETURN INTO LS_RETURN WHERE TYPE = 'A' OR TYPE = 'E'.
    WA_MSG_TAB-MSGID  = LS_RETURN-ID.
    WA_MSG_TAB-MSGTY  = LS_RETURN-TYPE.
    WA_MSG_TAB-MSGNO  = LS_RETURN-NUMBER.
    WA_MSG_TAB-MSGV1  = LS_RETURN-MESSAGE_V1.
    WA_MSG_TAB-MSGV2  = LS_RETURN-MESSAGE_V2.
    WA_MSG_TAB-MSGV3  = LS_RETURN-MESSAGE_V3.
    WA_MSG_TAB-MSGV4  = LS_RETURN-MESSAGE_V4.
    WA_MSG_TAB-LINENO = LS_RETURN-ROW.
    APPEND WA_MSG_TAB TO LT_MSG_TAB.
  ENDLOOP.

  CALL FUNCTION 'C14Z_MESSAGES_SHOW_AS_POPUP'
  TABLES
    I_MESSAGE_TAB = LT_MSG_TAB.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
    WAIT = 'X'.
ENDIF.