SAP BAPI_PO_CREATE1 ABAP Code Skeleton Generator
Creating purchase orders from a file, a web shop or another system is a standard integration task, and BAPI_PO_CREATE1 is the usual route. This generator gives you the full call with the matching X structures filled in.
Fill in
ABAP call skeleton
DATA: ls_header TYPE bapimepoheader,
ls_headerx TYPE bapimepoheaderx,
lt_item TYPE STANDARD TABLE OF bapimepoitem,
ls_item TYPE bapimepoitem,
lt_itemx TYPE STANDARD TABLE OF bapimepoitemx,
ls_itemx TYPE bapimepoitemx,
lt_sched TYPE STANDARD TABLE OF bapimeposchedule,
ls_sched TYPE bapimeposchedule,
lt_schedx TYPE STANDARD TABLE OF bapimeposchedulx,
ls_schedx TYPE bapimeposchedulx,
lt_return TYPE STANDARD TABLE OF bapiret2,
lv_ebeln TYPE bapimepoheader-po_number.
ls_header-comp_code = '1000'.
ls_header-doc_type = 'NB'.
ls_header-vendor = '0000100000'.
ls_header-purch_org = '1000'.
ls_header-pur_group = '001'.
ls_headerx-comp_code = 'X'.
ls_headerx-doc_type = 'X'.
ls_headerx-vendor = 'X'.
ls_headerx-purch_org = 'X'.
ls_headerx-pur_group = 'X'.
ls_item-po_item = '00010'.
ls_item-material = 'RM-1001'.
ls_item-plant = '1000'.
ls_item-quantity = '100'.
ls_item-net_price = '12.50'.
APPEND ls_item TO lt_item.
ls_itemx-po_item = '00010'.
ls_itemx-po_itemx = 'X'.
ls_itemx-material = 'X'.
ls_itemx-plant = 'X'.
ls_itemx-quantity = 'X'.
ls_itemx-net_price = 'X'.
APPEND ls_itemx TO lt_itemx.
ls_sched-po_item = '00010'.
ls_sched-sched_line = '0001'.
ls_sched-delivery_date = '20261130'.
ls_sched-quantity = '100'.
APPEND ls_sched TO lt_sched.
ls_schedx-po_item = '00010'.
ls_schedx-sched_line = '0001'.
ls_schedx-po_itemx = 'X'.
ls_schedx-sched_linex = 'X'.
ls_schedx-delivery_date = 'X'.
ls_schedx-quantity = 'X'.
APPEND ls_schedx TO lt_schedx.Call, check and commit
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = ls_header
poheaderx = ls_headerx
IMPORTING
exppurchaseorder = lv_ebeln
TABLES
return = lt_return
poitem = lt_item
poitemx = lt_itemx
poschedule = lt_sched
poschedulex = lt_schedx.
LOOP AT lt_return TRANSPORTING NO FIELDS WHERE type CA 'EA'.
EXIT.
ENDLOOP.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING wait = 'X'.
WRITE: / 'Created PO', lv_ebeln.
ENDIF.Skeleton only. Check parameter and structure names in SE37 for your release, convert vendor and material to internal format with conversion exits as needed, and test in a sandbox. Add authorization checks and logging before production use. Do not run it against production data without approval.
Review of your PO integration
Want a second pair of eyes on your PO creation mapping and error handling? Our team can take a look.
Optional. The tool and every export work without this. No spam.
How to use the skeleton
Fill in company code, document type, vendor, purchasing organization and group, then material, plant, quantity, price and delivery date. The tool produces ABAP that fills the header, item and schedule line structures along with their flag counterparts, calls the BAPI and then checks the RETURN table before committing. Paste it into a function module or report, replace constants with variables from your source data and loop the item section for multiple lines.
Why the X structures matter
BAPI_PO_CREATE1 only takes over fields whose flag is set to X in the matching X structure. If you fill the value but forget the flag, the field is silently ignored and the order is created with defaults or fails later. Schedule lines also need the item number and schedule line number in both the value and the flag structure. Quantity and price in the item must match your unit of measure and price unit.
- Header: POHEADER with POHEADERX
- Item: POITEM with POITEMX
- Schedule line: POSCHEDULE with POSCHEDULEX
- Messages come back in RETURN as BAPIRET2
Error handling and commit
The BAPI does not commit by itself. After the call, look for messages of type E or A in RETURN, and roll back if any are found; otherwise call BAPI_TRANSACTION_COMMIT. Do not commit inside a loop without checking each order. For high volume loads consider batching and a staging log table so you can retry failed rows. In S/4HANA, also evaluate the released OData API for purchase orders if you integrate from outside ABAP.
Frequently Asked Questions
Why is my field not saved by BAPI_PO_CREATE1?
Most likely the matching X flag is not set. The BAPI only transfers fields where the corresponding structure field in POHEADERX, POITEMX or POSCHEDULEX is set to X. Check also that the field is permitted for your document type and customizing.
Do I need BAPI_TRANSACTION_COMMIT?
Yes. The BAPI prepares the order, but nothing is saved until you call BAPI_TRANSACTION_COMMIT. If the RETURN table contains an error or abort message, call BAPI_TRANSACTION_ROLLBACK instead and log the messages.
Can I use it to change an existing PO?
No, creation and change use different BAPIs. Use BAPI_PO_CHANGE for changes. It takes the PO number and the same style of value and X structures, plus item numbers for the lines you want to change.
Is there a modern alternative in S/4HANA?
Yes. SAP provides released OData and SOAP APIs for purchase orders in the SAP Business Accelerator Hub, which are the better choice for outside integrations. BAPIs remain usable inside the system, but check the release notes for your version.
If you are integrating orders from another system and want help designing the mapping and error handling, we can review it with you.
Related Tools
SAP Open PO Items ABAP SELECT Generator
Fill in plant, document type and dates to generate ABAP Open SQL that lists open PO items with received quantity from EKBE.
SAPSAP MM Tables and Key Fields Reference
Searchable list of the core SAP MM tables with their primary key fields and what each stores, including S/4HANA changes.
SAPSAP MM Transaction Codes Reference
Searchable list of the SAP MM transaction codes consultants and buyers use daily, grouped by purchasing, inventory, invoice verification and MRP.
SAPSAP Three-Way Match and Invoice Tolerance Calculator
Enter PO price, received quantity, invoice quantity and price, and tolerance to see price and quantity variances and whether the invoice would block.