MB1A bapi测试

来源:互联网 发布:什么是2g3g4g网络 编辑:程序博客网 时间:2024/06/11 04:55

 * BAPI_TEST FOR MB1A

*& T158G 有具体的代码与事物码对应关系
* GMCODE  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_mb1a_test.

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 = '03'.

  itab-move_type  = '261'.
  itab-plant      = '1000'.
  itab-material   = '5010-04577'.
  itab-entry_qnt = 1.
  itab-reserv_no = '0035677912'.
  itab-res_item  = '1515'.
  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.

原创粉丝点击