BAPI
ABAP Developmentadvanced

BAPI Part 8: EXTENSIONIN — Saving Custom Fields with BAPIs

Key takeaway

Pass custom (ZZ) fields through BAPIs: EXTENSIONIN with BAPIPAREX, the BAPE structures (e. g. BAPE VBAK/BAPE VBAKX, BAPE VBAP/BAPE VBAPX for sales orders), appending fields to the right structures, filling VALUEPART1–4, and the typical reasons why custom fields are not saved.

Explanation

📌 KEY POINTS
✅ EXTENSIONIN (table of BAPIPAREX) carries custom field values: STRUCTURE = name of the extension structure, VALUEPART1–4 = the structure's content as text.

✅ For sales orders: add ZZ fields to VBAK/VBAP (append) and to BAPE_VBAK/BAPE_VBAKX, VBAKKOZ/VBAKKOZX (header) or BAPE_VBAP/BAPE_VBAPX, VBAPKOZ/VBAPKOZX (item).

✅ The X structure (BAPE_VBAKX) needs 'X' for each custom field, just like standard X structures.

⚠️ Custom fields are "not saved" mostly because an append structure is missing somewhere, the key (VBELN/POSNR) is wrong or the X entry is missing.

━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE

Part 6 mapped standard fields. Many projects also need their own fields on orders, POs or FI documents.

━━━━━━━━━━━━━━━━━━━━
▶ 1. HOW EXTENSIONIN WORKS

The BAPI interface cannot change for each customer, so custom data travels as generic text in BAPIPAREX:

  • STRUCTURE = 'BAPE_VBAK'
  • VALUEPART1 = content of a BAPE_VBAK structure (VBELN + ZZ fields), moved as characters.

The BAPI maps it back into the custom fields of the document.\n\n━━━━━━━━━━━━━━━━━━━━\n▶ 2. SALES ORDER SETUP (BAPI_SALESORDER_CREATEFROMDAT2 / _CHANGE)\n• Append ZZ field to VBAK (SE11).

  • Append the same field to BAPE_VBAK and VBAKKOZ (type as in VBAK).
  • Append a CHAR1 field with the same name to BAPE_VBAKX and VBAKKOZX.
  • Item level analog: VBAP, BAPE_VBAP, VBAPKOZ, BAPE_VBAPX, VBAPKOZX.

━━━━━━━━━━━━━━━━━━━━
▶ 3. FILLING THE EXTENSION

  • BAPE_VBAK-VBELN: empty for create (or the order number for change); ZZ field value.
  • Move the structure to VALUEPART1 (character-like fields only — for packed/decimal fields use character-typed append fields or the application's documented conversion).
  • Second entry with STRUCTURE = 'BAPE_VBAKX' and 'X' flags.

━━━━━━━━━━━━━━━━━━━━
▶ 4. OTHER APPLICATIONS

  • Purchase orders (BAPI_PO_CREATE1): BAPI_TE_MEPOHEADER/…X, BAPI_TE_MEPOITEM/…X with CI_EKKODB/CI_EKPODB includes.
  • FI (BAPI_ACC_DOCUMENT_POST): EXTENSION2 + BAdI ACC_DOCUMENT or EXTENSION1 + BTE RWBAPI01.

Always check the BAPI documentation for its extension concept.

━━━━━━━━━━━━━━━━━━━━
▶ 5. TROUBLESHOOTING

  • Append missing in one of the four structures → value ignored.
  • Field types differ between structures → shifted values.
  • Non-character fields in VALUEPART → garbage.
  • Missing X structure entry → not saved.
  • Debug the BAPI's mapping (e.g. search for BAPE_VBAK in the BAPI code) to see what arrives.

━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP

  1. In a sandbox, append ZZPROJECT (CHAR10) to VBAK, BAPE_VBAK, VBAKKOZ and CHAR1 to BAPE_VBAKX, VBAKKOZX.
  2. Extend the Part 2 program with EXTENSIONIN (code example).
  3. Verify VBAK-ZZPROJECT after creation.

✅ CHECKPOINT: you can pass and troubleshoot custom fields through BAPI extensions.

Code example

ABAP Code
* ===== Extension for sales order header field ZZPROJECT =====* Appends (all with ZZPROJECT): VBAK, BAPE_VBAK, VBAKKOZ  (CHAR10)*                               BAPE_VBAKX, VBAKKOZX       (CHAR1 flag) DATA: lt_extin   TYPE STANDARD TABLE OF bapiparex,      ls_extin   TYPE bapiparex,      ls_bape    TYPE bape_vbak,      ls_bapex   TYPE bape_vbakx. * ----- value structure -----CLEAR ls_bape.ls_bape-zzproject = 'PRJ-2026'.               " VBELN stays empty for createls_extin-structure  = 'BAPE_VBAK'.ls_extin-valuepart1 = ls_bape.                " character-like structure -> textAPPEND ls_extin TO lt_extin. * ----- flag structure -----CLEAR: ls_extin, ls_bapex.ls_bapex-zzproject  = 'X'.ls_extin-structure  = 'BAPE_VBAKX'.ls_extin-valuepart1 = ls_bapex.APPEND ls_extin TO lt_extin. * ----- pass it to the BAPI (see Part 2 for the other parameters) -----* CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'*   EXPORTING order_header_in  = ls_header*             order_header_inx = ls_headerx*   IMPORTING salesdocument    = lv_vbeln*   TABLES    return           = lt_return*             order_items_in   = lt_items*             order_partners   = lt_partners*             extensionin      = lt_extin. * ===== Item level: BAPE_VBAP / BAPE_VBAPX with POSNR =====* ls_bape_item-posnr     = '000010'.* ls_bape_item-zzproject = 'PRJ-2026'.* ls_extin-structure = 'BAPE_VBAP'. ls_extin-valuepart1 = ls_bape_item. * ===== Check after save =====* SELECT SINGLE zzproject FROM vbak INTO lv_proj WHERE vbeln = lv_vbeln.

Real project scenario

A project field on sales orders was filled by the EDI interface but always empty in VBAK. The developer had appended ZZPROJECT to VBAK and BAPE_VBAK, but not to VBAKKOZ/VBAKKOZX, which the BAPI uses internally to transfer values into the order.
After completing the appends and adding the BAPE_VBAKX entry, the field was saved. The team documented the full list of structures per BAPI in their interface guidelines.

Common mistakes

  • Missing appends in one of the extension structures.
  • Different field types/lengths across structures.
  • Packed fields in VALUEPART without conversion.
  • No X structure entry.
  • Wrong key (POSNR) for item extensions.

Best practices

  • Document the structure list per BAPI.
  • Use character-like custom fields where possible.
  • Always send value and X structures.
  • Verify saved values after test calls.
  • Debug the BAPI mapping when values are lost.

Interview angle

Questions: "How do you pass custom fields to a BAPI?", "Why is my custom field not saved via BAPI_SALESORDER_CREATEFROMDAT2?"
Strong answer: EXTENSIONIN (BAPIPAREX) with STRUCTURE and VALUEPART1–4; sales order: append field to VBAK, BAPE_VBAK, VBAKKOZ and flag to BAPE_VBAKX, VBAKKOZX (item analog); send value + X structure; typical failures: missing append, type mismatch, packed fields, missing X, wrong POSNR; PO uses BAPI_TE_MEPOHEADER/ITEM, FI uses EXTENSION1/2 with BTE/BAdI.

Practice this lesson

Quick check

1. Which EXTENSIONIN entries are needed to save a custom sales order header field?

2. A custom field value passed via EXTENSIONIN arrives shifted/garbled. Likely cause?

3. Which structures need the custom header field for sales order BAPIs (value side)?

Interview questions

1. A sales interface populated EXTENSIONIN with a custom header field, but the field is never saved. How do you troubleshoot?

Answer it in your own words first, then compare.

2. Difference between BAPI and RFC.

Answer it in your own words first, then compare.

Practice more with Interview AI →

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

Interview questions on this topic

Related SAP topics