Now accepting guest editorial from SAP, Oracle, Workday and ServiceNow practitioners.Pitch a guide
The Sign-Off Table

Lesson 5 of 6

Filling and reading custom segments

7 min

Listen to this lesson

0:00 / 10:14

The extension defines where the data goes; ABAP in a customer exit puts it there. SAP's outbound and inbound IDoc function modules call customer exits at defined points, and those exits are where custom segments are appended (outbound) or read (inbound). Searchers know them as the ORDERS05, INVOIC02 or DESADV "user exits".

Where the exits are

MessageDirectionFunction moduleEnhancement and exit
ORDERS / ORDCHG (purchase order)OutboundIDOC_OUTPUT_ORDERSMM06E001, EXIT_SAPLEINM_002 (data segments for outbound purchasing documents)
ORDRSP (order acknowledgment)InboundIDOC_INPUT_ORDRSPMM06E001 also adapts tolerance checks and supplier material adoption
INVOIC (billing)OutboundIDOC_OUTPUT_INVOICLVEDF001, EXIT_SAPLVEDF_002 (data segments)
INVOIC (supplier invoice)InboundIDOC_INPUT_INVOIC_MRMMRMH0002 (including EXIT_SAPLMRMH_014 and EXIT_SAPLMRMH_015)
DESADV / DELVRY (outbound delivery)OutboundIDOC_OUTPUT_DELVRYV56K0001, EXIT_SAPLV56K_002
ORDERS (sales order)InboundIDOC_INPUT_ORDERSVEDA0001 (sales order inbound exits)

Commonly used IDoc customer exits. Check names and interfaces in SMOD for your release before building on them.

Customer exits are activated through an enhancement project in CMOD: you assign the SAP enhancement (for example LVEDF001) to a project, implement the include behind the function exit, and activate the project. SAP's documentation for extending outbound function modules walks through exactly this for MM06E001: project, component EXIT_SAPLEINM_002, include ZXM06U02, and the custom segment declared in the customer TOP include.

Finding and testing the right exit

Start in SMOD with the enhancement name and read the documentation of each function exit: when it is called, what it receives and what it may change. Then confirm the call point in practice. For outbound exits, output a test document in CMD and set a breakpoint in your include; for inbound exits, use WE19 with the inbound function module option in debug mode, which SAP provides exactly for developer tests of extended types. Some exits are called through dynamic calls, so a breakpoint in the calling function module is often the quickest way to see where the exit fires.

Write down what you found in the extension register: exit name, call point, the parameters you rely on. That note is what the next upgrade test checks first.

The outbound pattern

The data-segment exit is called once for every segment SAP adds to the IDoc. Your code therefore checks which segment was just added and appends the custom segment right after the right parent. SAP fills hierarchy level and parent segment number from the extension definition, so you only provide the segment name and data.

CASE int_edidd-segnam.
  WHEN 'E1EDP01'.
    " read the core agreement for this billing item (illustrative)
    DATA(ls_core) = zcl_cmc_core_agr_reader=>for_billing_item( ... ).
    IF ls_core IS NOT INITIAL.
      CLEAR int_edidd.
      int_edidd-segnam = 'Z1CMCCORE'.
      int_edidd-sdata = ls_core.
      APPEND int_edidd.
    ENDIF.
ENDCASE.

The sketch shows the shape, not a copy-paste solution: the exact parameters of EXIT_SAPLVEDF_002 and how you identify the billing item differ by release, so Kenji's developers read the exit documentation in SMOD first. Note the design choice: the include calls a small class, ZCL_CMC_CORE_AGR_READER, which reads the agreement through Contoso's own CDS view ZI_CMC_CoreAgreement. The include stays a two-line adapter; the logic sits in a class that can be unit-tested and checked by ATC.

Outbound processing with the exit: SAP builds standard segments, the exit appends the custom one under each item.
The Sign-Off Table · thesignofftable.com/academy/sap-edi-209

The inbound pattern

Inbound exits work the other way round: SAP's inbound function module loops over the data records, and the exit receives segments it does not know so your code can read them and move the values into the application document, for example into a custom field on the sales order item. Two rules keep inbound exits safe: never let the exit raise an unhandled error (return a proper error status so the IDoc goes to 51 with a readable message), and never write SAP tables directly; use the document's own update logic or released interfaces.

Thin includeThe CMOD include only routes: which segment, which call. No SELECTs, no business rules.
Reader or mapper classOne Z class per extension, unit-tested, reading through CDS views or documented interfaces.
Clear failure behaviorOutbound: missing data means no segment (occurrence 0), not a dump. Inbound: errors become IDoc status records with messages.
ATC cleanClean core checks and code inspector run on the class like on any custom code.
Good practice for exit code that fills or reads custom segments.
The Sign-Off Table · thesignofftable.com/academy/sap-edi-209
Key points
  • Exits differ by message: MM06E001 (purchasing), LVEDF001 (billing INVOIC), V56K0001 (outbound deliveries), MRMH0002 (supplier invoices), VEDA0001 (inbound sales orders).
  • Activate exits through a CMOD project; the data-segment exit is called once per segment, so check the segment name.
  • Keep the include thin and the logic in a tested class that reads through CDS views or documented interfaces.
  • Outbound: no data, no segment. Inbound: errors become readable IDoc statuses, never direct table writes.

Check your understanding · not graded

Lesson check

  1. 1. Which enhancement contains the data-segment exit for outbound purchase order IDocs?

  2. 2. Why does exit code check int_edidd-segnam with a CASE statement?

  3. 3. Which exit enhancement is commonly used for custom segments on outbound billing INVOIC IDocs?

  4. 4. What should an inbound exit do when the custom segment holds invalid data?