SAPFree generatorPDF, Excel, Word exportSAP S/4HANA

SAP BAPI_PRODORD_CREATE and RELEASE ABAP Code Template

Integrations from MES, planning tools or e-commerce front ends often need to create production orders in SAP without a user typing in CO01. This template builds the ABAP skeleton for the standard BAPI route, with return handling and a controlled commit.

Fill in

Generated code
Download:

Create the production order

DATA: ls_orderdata TYPE bapi_pp_order_create,
      ls_return    TYPE bapiret2,
      lv_order     TYPE bapi_order_key-order_number,
      lv_type      TYPE bapi_order_copy-order_type.

ls_orderdata-material         = 'FG-10045'.
ls_orderdata-plant            = '1000'.
ls_orderdata-order_type       = 'PP01'.
ls_orderdata-quantity         = '250'.
ls_orderdata-basic_start_date = '20261102'.
ls_orderdata-basic_end_date   = '20261106'.

CALL FUNCTION 'BAPI_PRODORD_CREATE'
  EXPORTING
    orderdata    = ls_orderdata
  IMPORTING
    return       = ls_return
    order_number = lv_order
    order_type   = lv_type.

IF ls_return-type CA 'EA'.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  WRITE: / 'Create failed:', ls_return-message.
  RETURN.
ENDIF.

Release the order and commit

DATA: lt_orders TYPE STANDARD TABLE OF bapi_order_key,
      ls_order  TYPE bapi_order_key,
      lt_detail TYPE STANDARD TABLE OF bapi_order_return,
      ls_ret2   TYPE bapiret2.

ls_order-order_number = lv_order.
APPEND ls_order TO lt_orders.

CALL FUNCTION 'BAPI_PRODORD_RELEASE'
  IMPORTING
    return        = ls_ret2
  TABLES
    orders        = lt_orders
    detail_return = lt_detail.

IF ls_ret2-type CA 'EA'.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.
  WRITE: / 'Order', lv_order, 'created and released'.
ENDIF.

Call from an HTTP or queue wrapper (outline)

* Wrap the two blocks above in a function module marked remote-enabled,
* or expose it through an OData / SOAP service in your integration layer.
* Keep one LUW per order: create, release, then commit once.
* Log lv_order and the return messages for support.

Verify structure and parameter names (for example MATERIAL vs MATERIAL_LONG, and the RELEASE parameters) in SE37 and SE11 on your release, because they differ between ECC and S/4HANA versions. Authorisation, order type defaults, production versions and BOM/routing selection come from the material master and Customizing, so test in a sandbox with real master data. This is a starting skeleton, not production-ready code.

Safe write-back design for SAP

Optional: a short design note on approvals, logging and rollback for integrations that create SAP production orders.

Optional. The tool and every export work without this. No spam.

How to use the template

Enter a material, plant, order type, quantity and basic dates, and copy the code into a test report. The first block calls BAPI_PRODORD_CREATE and checks the return message. The second block releases the new order and commits. Run it in a sandbox against a material with a valid BOM, routing and production version, and compare the result in CO03.

How the BAPI sequence works

BAPI_PRODORD_CREATE builds the order in memory from the material master and routing; nothing is saved until BAPI_TRANSACTION_COMMIT runs. Releasing is a separate BAPI and uses the order number returned by the create call. Always test the return structure for types E and A, roll back on failure and commit once at the end so you do not leave half-built orders. Using WAIT = 'X' makes the commit synchronous, so a following read finds the data.

  • Do not call COMMIT WORK inside a loop of many orders without checking returns.
  • Dates not supplied are scheduled by SAP from the routing.
  • Planned order conversion has its own BAPI; do not use create for that case.

Common mistakes

The most common failures are a missing production version, an order type not allowed for the plant and unit of measure conversion on quantity. Another is using the BAPI to update a table directly after creation, which breaks statuses. Treat all inbound data as untrusted: validate the material and plant before calling, and put approvals in place for any automated write-back.

Frequently Asked Questions

Do I need BAPI_TRANSACTION_COMMIT?

Yes. The production order BAPIs do not commit the database transaction themselves. Without BAPI_TRANSACTION_COMMIT the order exists only in the session and disappears when the program ends. Use WAIT = 'X' when subsequent steps depend on the order being saved.

How do I create an order from a planned order?

Use the planned order conversion route: the planned order number is passed to the create call, and the order inherits quantity, dates and production version from the planned order. Check the BAPI structure for your release for the exact field name.

Is BAPI_PRODORD_CREATE released for use in S/4HANA?

It is widely used and still present in S/4HANA, but check SAP's released API list for your release and consider the cloud APIs, such as the production order OData service, if you are on S/4HANA Cloud where classic BAPIs may not be allowed.

How should errors be handled?

Check RETURN after each call for message types E and A, roll back with BAPI_TRANSACTION_ROLLBACK and log the message text plus the input values. Do not retry blindly; a missing master data error will fail again until fixed.

Netray works with SAP partners on integrations where write-back to SAP needs human approval and a clear audit trail. If you are connecting MES or an AI agent to production orders, we can help design that safely.