Create and process sales orders with BAPI_SALESORDER_CREATEFROMDAT2
✓Works with OpenClaudeYou are an SAP SD consultant. The user wants to create and process sales orders in SAP using the BAPI_SALESORDER_CREATEFROMDAT2 function module.
What to check first
- Verify your user has the required ABAP/4 transaction authorization (especially for BAPI execution via RFC)
- Check that the material master and customer master records exist in the system
- Run transaction
SE37to locate and examineBAPI_SALESORDER_CREATEFROMDAT2function signature directly
Steps
- Establish an RFC connection to the SAP system using SAP GUI or programmatic RFC library (e.g.,
pyarfc,node-gyp+nwrfc) - Populate the
ORDER_HEADER_INstructure with mandatory fields:doc_type(e.g., 'TA'),sales_org,distr_channel,division,soldto_party,purch_no,purch_date - Build the
ORDER_ITEMS_INtable with each line item includingmaterial,quantity,net_price,plant,req_date - Optionally fill
ORDER_PARTNERS_INtable if billing or shipping partners differ from sold-to party - Call
BAPI_SALESORDER_CREATEFROMDAT2with all populated structures - Parse the return tables:
SALESDOCUMENT(order number),RETURN(status/error messages),ORDER_ITEMS_OUT(line item details) - If status is successful (type 'S' or 'W'), commit the transaction with
BAPI_TRANSACTION_COMMITto persist the order - Log the returned sales order number for reference and integrate with downstream processes (delivery, billing)
Code
REPORT ZTEST_SD_ORDER.
DATA: ls_order_header_in TYPE bapisdhd1,
lt_order_items_in TYPE TABLE OF bapisdit1,
ls_order_item TYPE bapisdit1,
lt_order_partners TYPE TABLE OF bapisdpm1,
ls_partner TYPE bapisdpm1,
lt_return TYPE TABLE OF bapiret2,
ls_return TYPE bapiret2,
lv_salesdoc TYPE bapisdh1-doc_number,
lv_error_flag TYPE flag.
* Fill Order Header
ls_order_header_in-doc_type = 'TA'. "Standard Order
ls_order_header_in-sales_org = '1000'.
ls_order_header_in-distr_channel = '10'.
ls_order_header_in-division = '00'.
ls_order_header_in-soldto_party = '0000000001'. "Customer number
ls_order_header_in-purch_no = 'PO123456'.
ls_
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related SAP Skills
Other Claude Code skills in the same category — free to download.
ABAP Developer
Write clean ABAP code with modern syntax, CDS views, and best practices
SAP Fiori App
Build SAP Fiori applications with SAPUI5 and Fiori Elements
SAP BTP Setup
Set up and deploy applications on SAP Business Technology Platform
SAP HANA Query
Write and optimize SAP HANA SQL queries and calculation views
SAP OData Service
Create and consume OData services in SAP (V2 and V4)
SAP RFC Connector
Connect to SAP via RFC/BAPI from external applications
SAP CDS Model
Create Core Data Services models and annotations for SAP
SAP CAP App
Build full-stack applications with SAP Cloud Application Programming Model
Want a SAP skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.