SAP BAPI_GOODSMVT_CREATE ABAP Code Generator
BAPI_GOODSMVT_CREATE is the standard way to post goods receipts, issues and transfers from your own code or from middleware. This generator gives you the full call, error handling and commit sequence.
Fill in
Goods movement posting
REPORT ZR_POST_GOODS_MOVEMENT.
DATA: ls_header TYPE bapi2017_gm_head_01,
ls_code TYPE bapi2017_gm_code,
ls_headret TYPE bapi2017_gm_head_ret,
lt_item TYPE STANDARD TABLE OF bapi2017_gm_item_create,
ls_item TYPE bapi2017_gm_item_create,
lt_return TYPE STANDARD TABLE OF bapiret2,
ls_return TYPE bapiret2,
lv_error TYPE abap_bool.
ls_header-pstng_date = sy-datum.
ls_header-doc_date = sy-datum.
ls_header-header_txt = 'Posted by ZR_POST_GOODS_MOVEMENT'.
ls_code-gm_code = '05'.
ls_item-material = 'FG-100045'.
ls_item-plant = '1010'.
ls_item-stge_loc = '0001'.
ls_item-move_type = '501'.
ls_item-entry_qnt = 25.
ls_item-entry_uom = 'EA'.
APPEND ls_item TO lt_item.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = ls_header
goodsmvt_code = ls_code
IMPORTING
goodsmvt_headret = ls_headret
TABLES
goodsmvt_item = lt_item
return = lt_return.
LOOP AT lt_return INTO ls_return WHERE type CA 'EAX'.
lv_error = abap_true.
WRITE: / ls_return-type, ls_return-message.
ENDLOOP.
IF lv_error = abap_true.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
WRITE: / 'Material document:', ls_headret-mat_doc, ls_headret-doc_year.
ENDIF.Goods movement codes
01 goods receipt for purchase order, 02 goods receipt for production order, 03 goods issue, 04 transfer posting, 05 other goods receipts, 06 reversal of goods movements, 07 subsequent adjustment for subcontracting. Movement type 501 must be valid for code 05.
Skeleton for ECC and S/4HANA on-premise. Items for purchase order receipts need PO number and item (PO_NUMBER, PO_ITEM). In S/4HANA the long material field MATERIAL_LONG may be required for 40-character material numbers. Test with the TESTRUN parameter first and verify structure names in SE37 for your release.
Want posting logic wrapped in a safe API?
Optional: discuss how to expose SAP postings through an approval-based interface instead of direct calls.
Optional. The tool and every export work without this. No spam.
How to use the generator
Set the goods movement code, movement type and item data, then copy the code into a report. Run it first in a test client with TESTRUN set, read the RETURN table, and only then run it for real. For purchase order receipts add the reference fields to the item, and set the movement type to 101.
The BAPI commit pattern
Standard BAPIs do not commit on their own. You check the RETURN table for messages of type E, A or X, then call BAPI_TRANSACTION_COMMIT when it is clean or BAPI_TRANSACTION_ROLLBACK when it is not. Using WAIT = X makes the commit synchronous, so the material document exists in the database when your next statement runs. Without it, a read straight afterwards can miss the document.
Reading the result
A successful call returns the material document number and year in GOODSMVT_HEADRET and a success message in RETURN. Check the document in MB03 and the stock effect in MMBE. Errors such as missing storage location, blocked material or period closed come back as messages in RETURN rather than short dumps.
Common mistakes
Calling the commit even when RETURN has errors, passing quantities in the wrong unit, and posting from several parallel jobs on the same material and plant, which causes lock errors.
- Convert material numbers to internal format if needed
- Handle lock errors with a retry
- Never write to stock tables directly
Frequently Asked Questions
What does TESTRUN do in BAPI_GOODSMVT_CREATE?
Setting TESTRUN to X runs all checks and returns the messages you would get on a real posting, but writes nothing to the database. It is the safest way to validate an integration with real data before going live.
Why do I need BAPI_TRANSACTION_COMMIT?
BAPIs are written not to commit, so the caller controls the transaction and can group several BAPI calls. If you forget the commit, the posting is rolled back when your program ends and no material document remains.
How do I post a goods receipt against a purchase order?
Use goods movement code 01, movement type 101, and fill PO_NUMBER and PO_ITEM in the item. The system derives material and plant from the order. Provide quantity and unit, and make sure the order item is not already fully delivered.
Does this work for S/4HANA?
Yes, the BAPI remains available in S/4HANA on-premise, backed by the material document tables of the new data model. Newer cloud releases push you toward released APIs and OData services, so check the release notes before choosing.
Netray helps SAP teams build integrations with human approval on every write-back. If you are wrapping posting BAPIs in an API or an assistant, ask for a design review.
Related Tools
SAP OData V2 and V4 Query Options Reference
A lookup table of OData system query options, filter operators and functions, showing which work in V2, which in V4, and an example for each.
SAPSAP ABAP Outbound IDoc Code Generator (MASTER_IDOC_DISTRIBUTE)
Fill in message type, IDoc type, receiver and a segment, and get an ABAP skeleton that creates and dispatches an outbound IDoc.
SAPSAP Integration Readiness Assessment
Answer ten questions about interfaces, monitoring, API use, security and ownership to see how ready your SAP integration landscape is for change.
SAPSAP IDoc Interface Go-Live Checklist
A practical checklist covering configuration, testing, monitoring and cutover steps before an IDoc interface goes into production.
More SAP tools
See all- SAP Sales Document Types Reference
- SAP Pricing Procedure Design Worksheet
- SAP Item Category Determination Reference
- SAP Delivery Block Reasons Template
- SAP Credit Management Checklist
- SAP Output Determination Checklist
- SAP Billing Types Reference
- SAP Incompletion Log Checklist
- SAP SD Tables Reference (VBAK, VBAP, LIKP, VBRK and More)