IDoc
ABAP Developmentadvanced

IDoc Part 9: IDoc Extension and Custom Segments

Key takeaway

Add custom data to standard IDocs: create segments (WE31), an extension of the basic type (WE30), link it in WE82 and the partner profile, fill the segment outbound in user exits/BAdIs (e. g. customer exit for ORDERS/INVOIC), read it inbound, and release and transport correctly.

Explanation

📌 KEY POINTS
✅ An extension (e.g. ZORDERS05) adds customer segments (Z1…) as children of standard segments of a basic type — without modifying it.

✅ Steps: segment WE31 → extension WE30 → release both → WE82 (message type + basic type + extension) → partner profile uses the extension.

✅ Outbound: fill the Z segment in the application's IDoc exit/BAdI after the parent segment; inbound: read it in the exit/BAdI of the inbound FM.

⚠️ Released segments can only be changed compatibly (new fields at the end via new segment version) — plan fields carefully before release.

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

Part 2 mentioned extensions. Now we build one for ORDERS.

━━━━━━━━━━━━━━━━━━━━
▶ 1. CREATE THE SEGMENT (WE31)

  • Name Z1ORDITEM with fields (e.g. ZZPROJECT CHAR10, ZZCOSTCENTER CHAR10).
  • Character fields only (SDATA is character data).
  • Release the segment (Edit → Set release) when final.

━━━━━━━━━━━━━━━━━━━━
▶ 2. CREATE THE EXTENSION (WE30)

  • Object type: extension, name ZORDERS05, linked basic type ORDERS05.
  • Add Z1ORDITEM as child of E1EDP01 (item), occurrence e.g. min 0 max 1.
  • Release the extension.

━━━━━━━━━━━━━━━━━━━━
▶ 3. ASSIGNMENT

  • WE82: message type ORDERS, basic type ORDERS05, extension ZORDERS05, release.
  • WE20: in the outbound (or inbound) parameters for the partner, enter extension ZORDERS05.
  • Control record field CIMTYP = ZORDERS05.

━━━━━━━━━━━━━━━━━━━━
▶ 4. FILLING OUTBOUND

  • The standard outbound FM calls customer exits/BAdIs while building segments, e.g. for sales documents (ORDRSP) enhancement SDEDI001 / exit EXIT_SAPLVEDC_003 and for purchase orders (ORDERS outbound) enhancement MM06E001 / EXIT_SAPLEINM_002 — check SMOD for your release.
  • In the exit: when the parent segment E1EDP01 was just appended, append Z1ORDITEM with the item's data.

━━━━━━━━━━━━━━━━━━━━
▶ 5. READING INBOUND

  • Inbound ORDERS (IDOC_INPUT_ORDERS) offers exits in enhancement VEDA0001 (e.g. EXIT_SAPLVEDA_001 to process segments). Read Z1ORDITEM and fill the custom fields (e.g. via VBAP append).

━━━━━━━━━━━━━━━━━━━━
▶ 6. TRANSPORT

Segments, extension and assignments are transportable; release status must be the same in all systems.

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

  1. Create Z1ORDITEM and ZORDERS05 in a sandbox; release them.
  2. Assign in WE82 and in a test partner profile.
  3. Fill the segment in the outbound exit (code example) and check the IDoc in WE02.

✅ CHECKPOINT: you can extend a standard IDoc and fill/read custom segments.

Code example

ABAP Code
* ===== Outbound: fill Z segment after the item segment =====* Code in the ZX include of the outbound IDoc customer exit (see SMOD for exact name,* e.g. EXIT_SAPLEINM_002 for purchase order IDocs). Typical parameters:*   INT_EDIDD (table of data records built so far), CONTROL_RECORD_OUT (CIMTYP) DATA: ls_edidd    TYPE edidd,      lv_lines    TYPE i,      ls_e1edp01  TYPE e1edp01,      ls_z1orditm TYPE z1orditem. * Only for IDocs using our extensionCHECK control_record_out-cimtyp = 'ZORDERS05'. * Last appended segment is the one just built by SAPDESCRIBE TABLE int_edidd LINES lv_lines.READ TABLE int_edidd INTO ls_edidd INDEX lv_lines.IF sy-subrc = 0 AND ls_edidd-segnam = 'E1EDP01'.  ls_e1edp01 = ls_edidd-sdata. * Read the custom data for this item (buffer in real code)  PERFORM get_item_project USING ls_e1edp01-posex                           CHANGING ls_z1orditm-zzproject.   CLEAR ls_edidd.  ls_edidd-segnam = 'Z1ORDITEM'.  ls_edidd-sdata  = ls_z1orditm.  APPEND ls_edidd TO int_edidd.         " child of the E1EDP01 just builtENDIF. * ===== Inbound: read Z segment (inbound exit of IDOC_INPUT_ORDERS) =====* LOOP AT idoc_data WHERE docnum = idoc_contrl-docnum AND segnam = 'Z1ORDITEM'.*   ls_z1orditm = idoc_data-sdata.*   " transfer to item custom field (e.g. via VBAP append / BDC field in the exit)* ENDLOOP. * ===== Definition objects =====* WE31 Z1ORDITEM (released)  WE30 ZORDERS05 extends ORDERS05, Z1ORDITEM under E1EDP01* WE82 ORDERS/ORDERS05/ZORDERS05  WE20 partner parameter: extension ZORDERS05

Real project scenario

A supplier needed the buyer's project number on every PO item. The team built ZORDERS05 with Z1ORDITEM under E1EDP01 and filled it in the purchasing IDoc exit. In QA, the segment was missing because the partner profile still had no extension entered.
After adding ZORDERS05 to the partner profile, the IDocs contained the segment. The team also learned that the released segment could not simply get a new field later — the next requirement needed a new segment version.

Common mistakes

  • Extension not entered in the partner profile.
  • Non-character fields in segments.
  • Appending the Z segment at the wrong position (wrong parent).
  • Changing released segments incompatibly.
  • Missing WE82 assignment.

Best practices

  • Design segment fields fully before release.
  • Check CIMTYP before filling in exits.
  • Fill segments right after their parent.
  • Buffer custom data lookups.
  • Transport all definition objects together.

Interview angle

Questions: "How do you add custom fields to a standard IDoc?", "Where do you fill a custom segment?"
Strong answer: create segment WE31 (character fields, release), extension WE30 linked to basic type with Z segment under parent, WE82 assignment, partner profile extension (CIMTYP); fill in outbound customer exit/BAdI after parent segment in INT_EDIDD; read inbound in exit of the inbound FM; released segments need new versions for changes.

Practice this lesson

Quick check

1. A custom segment exists in an IDoc extension, but outbound IDocs don't contain it. Most likely cause?

2. What is the correct relationship between the transactions WE31 and WE30 when building a custom IDoc structure?

3. What is an IDoc extension used for?

Interview questions

1. How do you extend an IDoc without modifying SAP?

Answer it in your own words first, then compare.

2. A logistics partner requires a regulatory identifier that the standard DESADV IDoc does not contain. How do you deliver it?

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