BAPI Part 6: Mapping Header, Item, Partner and Schedule Data
Map external data into complex BAPI structures: header/item/partner/schedule/condition tables, item number consistency, partner roles and conversions, units and currencies, date formats, change BAPIs with UPDATEFLAG (I/U/D), and a reusable mapping layer.
Explanation
📌 KEY POINTS
✅ Complex BAPIs link tables by keys: item number (ITM_NUMBER) connects items, schedules, conditions and X structures.
✅ Values must be in internal format: ALPHA-converted numbers, internal units (CUNIT), partner functions (AG/WE), currency amounts with the right decimals.
✅ Change BAPIs (e.g. BAPI_SALESORDER_CHANGE) use UPDATEFLAG: I insert, U update, D delete — per header, item and schedule.
⚠️ A separate, tested mapping layer prevents the most common interface errors: wrong formats and inconsistent keys.
━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE
Part 2 created an order with a minimal structure. Real interfaces bring many items, partners, schedules and prices.
━━━━━━━━━━━━━━━━━━━━
▶ 1. KEYS AND CONSISTENCY
- ORDER_ITEMS_IN ITM_NUMBER '000010' must match ORDER_SCHEDULES_IN-ITM_NUMBER and ORDER_CONDITIONS_IN-ITM_NUMBER.
- X structures repeat the keys (ITM_NUMBER, SCHED_LINE).
- Header-level partners have ITM_NUMBER '000000'; item partners carry the item number.
━━━━━━━━━━━━━━━━━━━━
▶ 2. PARTNERS
- Internal partner functions: AG (sold-to), WE (ship-to), RE (bill-to), RG (payer) — in English logon shown as SP/SH/BP/PY. Convert with CONVERSION_EXIT_PARVW_INPUT.
- Numbers with leading zeros (ALPHA).
━━━━━━━━━━━━━━━━━━━━
▶ 3. UNITS, CURRENCIES, AMOUNTS
- Units: CONVERSION_EXIT_CUNIT_INPUT (external 'PC' → internal 'ST' depending on language).
- Amounts in BAPIs are usually external format (BAPICURR); for internal→external conversions use BAPI_CURRENCY_CONV_TO_EXTERNAL / _TO_INTERNAL when needed (e.g. JPY without decimals).
- Dates: YYYYMMDD in DATS fields.
━━━━━━━━━━━━━━━━━━━━
▶ 4. CONDITIONS (PRICES)
- ORDER_CONDITIONS_IN: ITM_NUMBER, COND_TYPE, COND_VALUE, CURRENCY; plus _INX flags.
- Only for condition types that allow manual entry.
━━━━━━━━━━━━━━━━━━━━
▶ 5. CHANGE BAPIS
BAPI_SALESORDER_CHANGE: SALESDOCUMENT, ORDER_HEADER_INX-UPDATEFLAG = 'U'; items with UPDATEFLAG 'U' (change), 'I' (add), 'D' (delete) and X flags only for changed fields.
━━━━━━━━━━━━━━━━━━━━
▶ 6. MAPPING LAYER
- A class ZCL_SO_MAPPER with method map( external data ) → BAPI tables; unit-testable.
- Validation before the BAPI (mandatory fields, known materials) gives clearer errors.
- Value mapping tables (external code → SAP code) in Z customizing.
━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP
- Extend the Part 2 example with a ship-to partner, two items and a manual price condition.
- Change the quantity of item 20 with BAPI_SALESORDER_CHANGE (code example).
- Deliberately mismatch an item number and observe RETURN.
✅ CHECKPOINT: you can map complex documents and changes consistently into BAPI structures.
Code example
* ===== Change item quantity with BAPI_SALESORDER_CHANGE =====REPORT zbapi_so_change. PARAMETERS: p_vbeln TYPE vbeln_va OBLIGATORY, p_posnr TYPE posnr_va DEFAULT '000020', p_qty TYPE kwmeng DEFAULT 8. DATA: ls_headerx TYPE bapisdh1x, lt_items TYPE STANDARD TABLE OF bapisditm, ls_item TYPE bapisditm, lt_itemsx TYPE STANDARD TABLE OF bapisditmx, ls_itemx TYPE bapisditmx, lt_sched TYPE STANDARD TABLE OF bapischdl, ls_sched TYPE bapischdl, lt_schedx TYPE STANDARD TABLE OF bapischdlx, ls_schedx TYPE bapischdlx, lt_return TYPE STANDARD TABLE OF bapiret2, ls_return TYPE bapiret2, lv_error TYPE abap_bool. START-OF-SELECTION. ls_headerx-updateflag = 'U'. " header: change * Item: key + update flag (no field changes on item level here) ls_item-itm_number = p_posnr. APPEND ls_item TO lt_items. ls_itemx-itm_number = p_posnr. ls_itemx-updateflag = 'U'. APPEND ls_itemx TO lt_itemsx. * Schedule line: new quantity, same keys, X flag for REQ_QTY only ls_sched-itm_number = p_posnr. ls_sched-sched_line = '0001'. ls_sched-req_qty = p_qty. APPEND ls_sched TO lt_sched. ls_schedx-itm_number = p_posnr. ls_schedx-sched_line = '0001'. ls_schedx-updateflag = 'U'. ls_schedx-req_qty = 'X'. APPEND ls_schedx TO lt_schedx. CALL FUNCTION 'BAPI_SALESORDER_CHANGE' EXPORTING salesdocument = p_vbeln order_header_inx = ls_headerx TABLES return = lt_return order_item_in = lt_items order_item_inx = lt_itemsx schedule_lines = lt_sched schedule_linesx = lt_schedx. LOOP AT lt_return INTO ls_return WHERE type CA 'EA'. lv_error = abap_true. WRITE: / ls_return-message. ENDLOOP. IF lv_error = abap_true. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. WRITE: / 'Order changed'. ENDIF. * ===== Partner function conversion for external codes =====* CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'* EXPORTING input = 'SH' IMPORTING output = lv_parvw. " -> 'WE'Real project scenario
A customer EDI feed sent ship-to partners with role "SH" and units "PC". Orders were created with the sold-to as ship-to and wrong units, causing deliveries to the wrong address.
The team built ZCL_SO_MAPPER with conversion exits for partner functions and units, a value mapping table for customer-specific codes, and unit tests with real sample files. Wrong-address deliveries stopped, and new customers were onboarded by filling mapping tables.
Common mistakes
- External partner codes (SH/SP) instead of internal (WE/AG).
- Item numbers not consistent across items, schedules, conditions.
- External units without conversion.
- Change BAPI without UPDATEFLAG or with X flags for unchanged fields.
- Mapping logic scattered across programs.
Best practices
- Central, unit-tested mapping class.
- Conversion exits for partners, units, numbers.
- Consistent keys in all related tables and X tables.
- Pre-validate mandatory data.
- Value mapping tables for external codes.
Interview angle
Questions: "How do you add a ship-to partner in the sales order BAPI?", "How do you change a quantity with BAPI_SALESORDER_CHANGE?", "What is UPDATEFLAG?"
Strong answer: ORDER_PARTNERS with internal role WE (convert SH via CONVERSION_EXIT_PARVW_INPUT) and ALPHA-converted number; ITM_NUMBER links items, schedules, conditions and X tables; change BAPI with header UPDATEFLAG U, item/schedule UPDATEFLAG U/I/D and X only for changed fields; units via CUNIT conversion; central mapping class.
Practice this lesson
Quick check
1. In BAPI_SALESORDER_CREATEFROMDAT2, how is the ship-to partner passed?
2. Which conversion turns external partner function 'SH' into the internal code?
3. Preferred way to update sales orders is:
Interview questions
1. A sales order upload passed valid header and item data but omitted schedule lines and X structures; orders were created with zero quantity or missing values. Explain the mapping rules.
Answer it in your own words first, then compare.
2. How do you design a robust batch that posts thousands of BAPIs?
Answer it in your own words first, then compare.
Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.
More lessons in this topic
- BAPI Part 1: What a BAPI Is and How to Find One
- BAPI Part 10: "Success but No Document" — Debugging BAPI Problems
- BAPI Part 2: Calling a BAPI — Inputs, X Structures, RETURN and Commit
- BAPI Part 3: BAPI vs RFC vs OData
- BAPI Part 4: Understanding BAPI RETURN Messages
- BAPI Part 5: Commit, WAIT, Rollback and the SAP LUW
- BAPI Part 7: Test Run, Simulation and Safe BAPI Execution
- BAPI Part 8: EXTENSIONIN — Saving Custom Fields with BAPIs