Skip to content

BAPI_GOODSMVT_CREATE

Post goods movements (GR, GI, transfer) programmatically — the standard BAPI for MM inventory postings.

Purpose

BAPI_GOODSMVT_CREATE creates material document entries for goods movements: goods receipt against a purchase order (101), goods issue to a cost center (201/261), stock transfer (311), and others. Always requires BAPI_TRANSACTION_COMMIT after a successful call.

Signature (key parameters)

Parameter Direction Type Description
GOODSMVT_HEADER Importing BAPI2017_GM_HEAD_01 Posting date, document date
GOODSMVT_CODE Importing BAPI2017_GM_CODE GM code (determines transaction type)
GOODSMVT_ITEM Tables BAPI2017_GM_ITEM_CREATE Line items — material, plant, qty, move type
GOODSMVT_HEADRET Exporting BAPI2017_GM_HEAD_RET Created document number
RETURN Tables BAPIRET2 Messages — always check

GM codes

GM_CODE Movement
01 Goods receipt for purchase order
02 Goods receipt for order (production)
03 Goods receipt for other
04 Goods issue
05 Transfer posting / other
06 Release GR blocked stock
07 Subsequent delivery

Example — goods receipt against PO (movement type 101)

DATA: ls_header  TYPE bapi2017_gm_head_01,
      ls_code    TYPE bapi2017_gm_code,
      lt_items   TYPE STANDARD TABLE OF bapi2017_gm_item_create,
      ls_headret TYPE bapi2017_gm_head_ret,
      lt_return  TYPE STANDARD TABLE OF bapiret2.

ls_header-pstng_date = sy-datum.
ls_header-doc_date   = sy-datum.
ls_header-pr_uname   = sy-uname.

ls_code-gm_code = '01'.   " goods receipt for PO

APPEND VALUE #(
  plant      = '1000'
  stge_loc   = '0001'
  material   = '000000000000000100'
  po_number  = '4500012345'
  po_item    = '00010'
  move_type  = '101'
  entry_qnt  = '10'
  entry_uom  = 'PC'
) TO lt_items.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
  EXPORTING
    goodsmvt_header = ls_header
    goodsmvt_code   = ls_code
  IMPORTING
    goodsmvt_headret = ls_headret
  TABLES
    goodsmvt_item  = lt_items
    return         = lt_return.

" Check for errors before committing
DATA lv_has_error TYPE abap_bool VALUE abap_false.
LOOP AT lt_return INTO DATA(ls_ret) WHERE type CA 'EA'.
  lv_has_error = abap_true.
  WRITE: / 'Error:', ls_ret-message.
ENDLOOP.

IF lv_has_error = abap_false.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING wait = abap_true.
  WRITE: / 'Material document:', ls_headret-mat_doc, ls_headret-doc_year.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.

Common pitfalls

Always call BAPI_TRANSACTION_COMMIT or ROLLBACK

The goods movement is buffered until a commit or rollback. If the program ends without either, nothing is posted.

Check RETURN before committing

Always scan the RETURN table for entries with TYPE = 'E' (error) or TYPE = 'A' (abort) before calling BAPI_TRANSACTION_COMMIT. A non-empty return does not automatically mean failure — informational messages (TYPE = 'I' or 'S') are normal.

  • Material number format: Pass in internal format (with leading zeros) or convert with CONVERSION_EXIT_ALPHA_INPUT first.
  • Movement type vs GM code: The GM code determines the allowed movement types in GOODSMVT_ITEM. Movement type 101 only works with GM code 01.
  • Storage location: Must exist in the plant. Check in MMBE.

See also

  • BAPI_TRANSACTION_COMMIT — always pair with BAPI calls that write data
  • Transaction MB51 — material document list (verify posted documents)
  • Transaction MMBE — stock overview

Comments