BAPI_GOODSMVT_CREATE 的应用

货物移动的bapi  BAPI_GOODSMVT_CREATE
其中 参数 : GOODSMVT_CODE 有
GMCODE Table T158G - 01 - MB01 - Goods Receipts for Purchase Order
*                      02 - MB31 - Goods Receipts for Prod Order
*                      03 - MB1A - Goods Issue
*                      04 - MB1B - Transfer Posting
*                      05 - MB1C - Enter Other Goods Receipt
*                      06 - MB11
*                      07 - MB04

给个01的例子

DATA:goodsmvt_header  LIKE  bapi2017_gm_head_01,
     goodsmvt_headret LIKE  bapi2017_gm_head_ret,
     goodsmvt_item TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
     gt_return  TYPE TABLE OF bapiret2 WITH HEADER LINE.
******省略
  LOOP AT lt_head INTO ls_head.
    CLEAR:goodsmvt_header,goodsmvt_headret,gt_return[],gt_return,return1[],return1.
    goodsmvt_header-doc_date   = sy-datum.
    goodsmvt_header-pstng_date = sy-datum.
    LOOP AT gt_data INTO gs_data WHERE ebeln = ls_head-ebeln .
      goodsmvt_item-plant      = gs_data-werks.
      goodsmvt_item-material   = gs_data-matnr.
      goodsmvt_item-move_type  = '101'.
      goodsmvt_item-mvt_ind    = 'B'.
      goodsmvt_item-entry_qnt  =  gs_data-menge3.
      SELECT SINGLE lgort INTO goodsmvt_item-stge_loc FROM ztmm001 WHERE werks = goodsmvt_item-plant.
      goodsmvt_item-po_number  =  gs_data-ebeln.
      goodsmvt_item-po_item    =  gs_data-ebelp.
      APPEND goodsmvt_item.
      CLEAR goodsmvt_item.
    ENDLOOP.

    CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
      EXPORTING
        goodsmvt_header  = goodsmvt_header
        goodsmvt_code    = '01'
      IMPORTING
        goodsmvt_headret = goodsmvt_headret
*       MATERIALDOCUMENT =
*       MATDOCUMENTYEAR  =
      TABLES
        goodsmvt_item    = goodsmvt_item
        return           = gt_return[].

    LOOP AT gt_return WHERE type = 'E' OR type = 'A'.
      MOVE-CORRESPONDING gt_return TO return1.
      APPEND return1.
      CLEAR:return1.
      error_flag = 'X'.
    ENDLOOP.
    IF erro_flag = 'X'.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      EXIT.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ENDIF.

 

你可能感兴趣的:(sap,bapi)