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.
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 sectionsHide sections
Visual overview
Expert visual walkthrough
IDoc Extension and Custom Segments
IDoc · Chapter-specific technical teaching map
Architecture hierarchy
Basic type
Z extension
Custom segment
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.
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
* ===== 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 ZORDERS05Watch 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?
Question 2 of 3
What is the correct relationship between the transactions WE31 and WE30 when building a custom IDoc structure?
Question 3 of 3
What is an IDoc extension used for?
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
Interview questions on this topic
Related SAP topics
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.