ERPClimb logoERPClimb
IDoc
ABAP Developmentadvanced 7 min read

IDoc Part 9: IDoc Extension and Custom Segments

Lessons are open to try during our launch period. Some advanced content may move to Pro later. AI practice limits apply separately.

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.

In this lessonShow sections

Visual overview

IDoc Part 9: IDoc Extension and Custom Segments — learning sheetFlow: Create Z1ORDITEM and ZORDERS05 in a sandbox; release them → Assign in WE82 and in a test partner profile → Fill the segment in the outbound exit (code example) and check the IDoc in WE02. Key ideas: CREATE THE SEGMENT (WE31); CREATE THE EXTENSION (WE30); ASSIGNMENT; FILLING OUTBOUND. Watch out: Released segments can only be changed compatibly (new fields at the end via new segment version) — plan fields carefully before release.ERPClimb.com / ABAP / LESSON 9/10 / LEARNING SHEETIDoc Part 9: IDoc Extension and Custom Segments1 · HOW IT FLOWS1Create Z1ORDITEM andZORDERS05 in a sandbox;release them2Assign in WE82 and in atest partner profile3Fill the segment in theoutbound exit (codeexample) and check the…2 · KEY IDEAS EXPLAINEDCreate The Segment (WE31)Name Z1ORDITEM with fields (e.g. ZZPROJECT CHAR10,ZZCOSTCENTER CHAR10).Character fields only (SDATA is character data).Create The Extension (WE30)Object type: extension, name ZORDERS05, linkedbasic type ORDERS05.Add Z1ORDITEM as child of E1EDP01 (item),occurrence e.g. min 0 max 1.AssignmentWE82: message type ORDERS, basic type ORDERS05,extension ZORDERS05, release.WE20: in the outbound (or inbound) parameters forthe partner, enter extension ZORDERS05.Filling OutboundThe standard outbound FM calls customerexits/BAdIs while building segments, e.g. forsales documents (ORDRSP) enhancement SDEDI001 /…In the exit: when the parent segment E1EDP01 wasjust appended, append Z1ORDITEM with the item'sdata.3 · REMEMBER · WATCH OUTRememberAn extension (e.g. ZORDERS05) adds customer segments (Z1…) as childrenof standard segments of a basic type — without modifying it.Steps: segment WE31 → extension WE30 → release both → WE82 (messagetype + basic type + extension) → partner profile uses the extension.Outbound: fill the Z segment in the application's IDoc exit/BAdI afterthe parent segment; inbound: read it in the exit/BAdI of the inbound…!Watch outReleased segments can only bechanged compatibly (new fields atthe end via new segment version) —plan fields carefully beforerelease.4 · IN A REAL PROJECTA supplier needed the buyer's project number on every PO item. The team built ZORDERS05 with Z1ORDITEM underE1EDP01 and filled it in the purchasing IDoc exit. In QA, the segment was missing because the partner profilestill had no extension entered. After adding ZORDERS05 to the partner profile, the IDocs contained the…Original ERPClimb learning sheet • Verify against your SAP release and edition

Expert visual walkthrough

ABAP DEVELOPMENT ACADEMY · Architecture hierarchyERPClimb.com

IDoc Extension and Custom Segments

IDoc · Chapter-specific technical teaching map

Architecture hierarchy

1Top level

Basic type

2Related level

Z extension

3Related level

Custom segment

4Related level

Population exit

Tutor's chapter 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…

In a real project

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…

Watch out for

• 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.

Conceptual study map, not an SAP configuration screenshot or a guaranteed runtime sequence. Consult the lesson for implementation prerequisites and exceptions.

The situation: a 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.

Explanation

Part 2 of this series mentioned extensions in passing; now it's time to actually build one for ORDERS. An extension, such as ZORDERS05, adds customer segments (named Z1…) as children of standard segments belonging to a basic type, without modifying that basic type at all.

The process has several steps. First, create the segment in WE31: name it, for example, Z1ORDITEM, with fields such as ZZPROJECT CHAR10 and ZZCOSTCENTER CHAR10 — only character fields are allowed, since SDATA itself is character data — and release the segment, through Edit → Set release, once it's final.

Second, create the extension in WE30: its object type is "extension," named ZORDERS05 and linked to the basic type ORDERS05, with Z1ORDITEM added as a child of E1EDP01 (the item segment), given an occurrence such as min 0 max 1, and then released.

Third, assign everything together: in WE82, link message type ORDERS, basic type ORDERS05, and extension ZORDERS05, and release that assignment; in WE20, enter extension ZORDERS05 in the outbound (or inbound) parameters for the relevant partner; and the control record field CIMTYP is what actually carries ZORDERS05 at runtime.

Filling the segment outbound happens inside the standard outbound function module's customer exits or BAdIs, which get called while it builds the IDoc's segments — for example, for sales document confirmations (ORDRSP), enhancement SDEDI001 with exit EXIT_SAPLVEDC_003, or for purchase orders (ORDERS outbound), enhancement MM06E001 with exit EXIT_SAPLEINM_002; check SMOD for the exact names on your release. Inside the exit, once the parent segment E1EDP01 has just been appended, you append Z1ORDITEM right after it with the item's custom data.

Reading the segment inbound works the same way in reverse: inbound ORDERS (processed by IDOC_INPUT_ORDERS) offers exits in enhancement VEDA0001, such as EXIT_SAPLVEDA_001, for processing segments; inside it, you read Z1ORDITEM and fill your custom fields, for example through a VBAP append.

Segments, extensions, and their assignments are all transportable, but their release status must match across every system in the landscape — note also that once a segment is released, it can only be changed compatibly, meaning new fields can only be added at the end via a new segment version, so field layouts need careful planning before release.

To practice, create Z1ORDITEM and ZORDERS05 in a sandbox and release them, assign them in WE82 and in a test partner profile, then fill the segment in the outbound exit as shown in the code example and check the resulting IDoc in WE02. By the end, you should be able to extend a standard IDoc and both fill and read its 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'.          " skip this logic entirely for partners not using our extension * Last appended segment is the one just built by SAPDESCRIBE TABLE int_edidd LINES lv_lines.                " find the index of the last rowREAD TABLE int_edidd INTO ls_edidd INDEX lv_lines.       " that last row is the E1EDP01 SAP just appended for this itemIF sy-subrc = 0 AND ls_edidd-segnam = 'E1EDP01'.         " double-check it really is the item segment, not something else  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

Watch out

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.

Do this

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.

In the interview

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

0 of 3 questions attempted

Question 1 of 3

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

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1How do you extend an IDoc without modifying SAP?

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

Try a related Code Lab

This published exercise covers the same SAP topic. Apply the ideas in a hands-on scenario, then return to review your answers.

Open: Custom Segment Added at Wrong Hierarchy →

See it in code

Each example starts from a requirement, shows the design, then the code step by step with a plain-language explanation of every part.

Was this lesson helpful?

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.