货物移动,MB31,MB1A等

来源:互联网 发布:js访问style标签样式 编辑:程序博客网 时间:2024/06/10 05:06

* 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
*  B - Goods movement for purchase order
*  F - Goods movement for production order
*  L - Goods movement for delivery note
*  K - Goods movement for kanban requirement (WM - internal only)
*  O - Subsequent adjustment of "material-provided" consumption
*  W - Subsequent adjustment of proportion/product unit material
*
REPORT zbapi_goodsmovement.

DATABEGIN OF gmhead.
        INCLUDE STRUCTURE bapi2017_gm_head_01.
DATAEND OF gmhead.

DATABEGIN OF gmcode.
        INCLUDE STRUCTURE bapi2017_gm_code.
DATAEND OF gmcode.

DATABEGIN OF mthead.
        INCLUDE STRUCTURE bapi2017_gm_head_ret.
DATAEND OF mthead.

DATABEGIN OF itab OCCURS 100.
        INCLUDE STRUCTURE bapi2017_gm_item_create.
DATAEND OF itab.

DATABEGIN OF errmsg OCCURS 10.
        INCLUDE STRUCTURE bapiret2.
DATAEND OF errmsg.

DATA: wmenge LIKE iseg-menge,
      documnet_num LIKE mseg-mblnr.

START-OF-SELECTION.
  gmhead-pstng_date = sy-datum.
  gmcode-gm_code = '02'.

  itab-move_type  = '101'.
  itab-mvt_ind    = 'F'.
  itab-plant      = '1000'.
  itab-material   = '5010-04577'.
  itab-entry_qnt  = 2.
  itab-orderid  = '000038340902'.
  itab-stge_loc = 'K100'.
  APPEND itab.

  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
    EXPORTING
      goodsmvt_header  = gmhead
      goodsmvt_code    = gmcode
      goodsmvt_headret = mthead
    IMPORTING
      materialdocument = documnet_num
    TABLES
      goodsmvt_item    = itab
      return           = errmsg.

   LOOP AT errmsg WHERE type = 'E' OR
                       type = 'A'.
    WRITE:/ errmsg-message.

  ENDLOOP.

  IF sy-subrc <> 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    WRITE: documnet_num.
  ENDIF.

原创粉丝点击