WhatsApp
SAP Technical

IDoc in SAP ABAP - Inbound, Outbound, Extension & Debugging

Best Online Career

SAP Consultant

May 16, 2026
IDoc in SAP ABAP - Inbound, Outbound, Extension & Debugging

IDoc Creation in SAP ABAP: End-to-End Process Explained

If you've been involved in SAP project integration, you've probably come across IDoc. IDoc. When you're communicating information between two SAP systems or connecting SAP using an outside program, IDocs are at the heart of this communication. However, for many developers the entire IDoc process from its creation up to debugging is undefined.

This guide provides a comprehensive step-by-step guide to IDoc for SAP ABAP and covers the basics of what IDocs are as well as how to create custom IDocs and how to make inbound IDocs within SAP ABAP as well as how IDoc extensions function and most importantly, how to troubleshoot IDocs throughout the process. No matter if you're just starting out or want to improve your integration skills, this guide covers everything you need to know.

What Is IDoc in SAP ABAP?

IDoc is an acronym for Intermediate Document. In SAP ABAP the term "IDoc" refers to IDoc can be described as an IDoc is a common data container that is used to exchange business information between SAP systems as well as between SAP as well as other systems that are not SAP. It operates as message format -Think about it like an envelope, which is used to carry business information that is structured across the boundaries of a system.

IDocs are extensively used for EDI (Electronic Data Interchange), ALE (Application Link Enabling) and middleware-based integrations, such as SAP P/P and SAP Integration Suite.

Structure of an IDoc

Every IDoc within SAP ABAP is comprised of three components:

  • Control Record (EDI_DC40): Contains information about routing and administrative details such as the sender recipient, sender, message type as well as IDoc type. There is always only one control record for each IDoc.
  • Data Record (EDI_DD40): Contain the actual business information, divided into segments. A IDoc could contain a number of data records.
  • Status Record (EDI_DS40): Track the processing history of the IDoc Each step that the IDoc completes adds an informational status record.

Key Terminology

  • Basic IDoc Type (IDoc Type): The standard structure template (e.g. the ORDERS05 template to purchase order)
  • message type: The business context of the information (e.g. ORDERERS, DESADV, INVOIC)
  • Segment The Segment is a data element inside an IDoc like the rows of fields
  • Direction: 1 = Outbound (SAP sends), 2 = Inbound (SAP receives)

IDoc Creation in SAP ABAP: Step by Step

Let's take a look at the IDoc creation process in SAP ABAP starting from scratch covering the standard and custom IDoc types.

Step 1: Define the Basic IDoc Type (WE31 + WE30)

In WE31 -- Create Segment:

Each segment contains the fields (like an arrangement). You can define the fields and their data elements as well as lengths.

  • Go to the transaction WE31
  • Enter a segment's name (must start with Z to allow for customization, e.g., ZORDERS_SEG)
  • Add fields that contain the data element and lengths.
  • Save and then activate the segment

In WE30 -- Create IDoc Type:

  • Go to the transaction WE30
  • Choose a name for the IDoc name (e.g., ZORDERS01)
  • Choose "Create New" and choose "Basic Type"
  • Place your segments in your root node ( BEGIN_DOCNUM)
  • Set the minimum/maximum number of times each segment
  • Save and then activate

Step 2: Define the Message Type (WE81)

  • Go to the transaction WE81.
  • Create a brand new type of message (e.g., ZORDERS_MSG)
  • Write a description, then save

Step 3: Link IDoc Type to Message Type (WE82)

  • Go to the transaction WE82
  • Create an entry that links your message by typing ZORDERS_MSG to your IDoc type ZORDERS01
  • Save

Step 4: Create Partner Profile (WE20)

  • Go to the transaction WE20.
  • Select or create a partner profil (partner number, type of partner)
  • To outbound: Add an outbound parameter that includes the type of message and the IDoc type.
  • For inbound: include an inbound parameter. Then choose the function module to take care of the IDoc
  • Save

Step 5: Write ABAP Code to Populate and Send the IDoc

To create an outbound IDoc to be outbound, you must fill in with control records, create segment data, then invoke an ordinary function module.

Data: ls_edidc TYPE Edidc and lt_edidd STANDARD TABLE OF Edidd, Ls_edidd TYPE Edidd, Lt_edids STANDARD TABLE OF TYPE Edids. " Fill Control Record ls_edidc-mestyp = 'ZORDERS_MSG'. ls_edidc-idoctp = 'ZORDERS01'. ls_edidc-rcvprt = 'LS'. ls_edidc-rcvprn = 'RECEIVER_SYSTEM'. ls_edidc-sndprt = 'LS'. ls_edidc-sndprn = 'SENDER_SYSTEM'. " Fill Segment Data ls_edidd-segnam = 'ZORDERS_SEG'. Ls_edidd-sdata is 'Your business information is here'. APPEND ls_edidd TO lt_edidd. " Create and Send IDoc CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' EXPORTING master_idoc_control = ls_edidc TABLES communication_idoc_control = lt_edids master_idoc_data = lt_edidd EXCEPTIONS error_in_idoc_control = 1 error_writing_idoc_status = 2 error_outbound_partner_fct = 3 no_partner_profile_found = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE 'IDoc creation failed' TYPE 'E'. ENDIF.

Custom IDoc Creation in SAP ABAP

Custom IDoc creation within SAP ABAP is needed in cases where your business processes don't meet the requirements of one of the typical SAP IDoc categories. It follows the WE31 - WE30 – WE81 and WE82-WE20 paths however, with your own customized segmentation and field.

Tips for Custom IDoc Creation

  • Always precede the custom IDoc segments and types using or Z or Y.
  • Keep segment names under 27 characters
  • Reuse existing data elements in the ABAP Dictionary wherever possible to take over field documentation and validation of the domain
  • The fields of the Group are logically related within the same sector
  • Take note of the maximum number of instances carefully. IDoc segments may be required (1:1) as well as repeatable (1:n)

How to Create Inbound IDoc in SAP ABAP

Making an inbound IDoc within SAP ABAP involves creating a system that can take an IDoc from a different software and to process it through the standard or custom function module.

Step 1: Define the Inbound Function Module

The inbound function module should be equipped with the following interfaces:

FUNCTION z_inbound_idoc_process IMPORTING input_method TYPE bdwfap_par-inputmethd mass_processing TYPE bdwfap_par-mass_proc TABLES idoc_contrl STRUCTURE edidc idoc_data STRUCTURE edidd idoc_status STRUCTURE bdidocstat return_variables STRUCTURE bdwfretvar serialization_info STRUCTURE bdserialid EXCEPTIONS wrong_function_called = 1. " Parse idoc_data segments and process business logic here LOOP AT idoc_data INTO DATA(ls_data) WHERE segnam = 'ZORDERS_SEG'. " Remove and analyze fields in the ls_data-sdata endpoint. " Set the success the status DATA(ls_status) = the value of bdidocstat( the docnum is idoc_contrl 1]-docnum status = 53 MSGTY = 'S' Msgid = 'B1' and Msgno = "011" ). Append ls_status IDOC_STATUS. Then, you can end the operation.

Step 2: Register the Function Module

  • Go to the transaction WE57
  • Connect your function module to the message type as well as the basic IDoc type
  • Save

Step 3: Configure the Partner Profile for Inbound (WE20)

In WE20 Under the partner's inbound parameters add the functionality module, and then set your processing method (immediate or through a background job).

IDoc Extension in SAP ABAP

A IDoc extension within SAP ABAP permits you to create custom fields for the standard SAP IDoc type without modifying the existing. This is the preferred method when an existing IDoc type meets your needs but requires some additional fields.

Steps to Create an IDoc Extension

Step 1: Create a Custom Segment (WE31)

Create a new segment using only the fields you require (not duplicates of the segment you already have).

Step 2: Create the Extension Type (WE30)

  • In WE30, type in the name of a new character (e.g., ZORDERS01E)
  • Choose "Create New" and choose "Extension Type"
  • You must enter the reference Basic Type ( ORDERS05)
  • Create your Z-segment and place it under the appropriate parent segment.
  • Save and then activate

Step 3: Create a Reduction (WE74) -- Optional

If you'd like to eliminate segments that you don't need create a reduction in your extension.

Step 4: Link Extension to Message Type (WE82)

In WE82, modify the entry for the message type to reference the extension type, not the default type.

Using an IDoc extension keeps your customization upgrade-safe. If SAP releases an updated version of its standard IDoc type your extension will continue to function, without recoding.

How to Debug IDoc in SAP ABAP

Debugging IDocs is among the most essential skills required by anyone who is an SAP Integration developer. Let's go over the most important scenarios.

How to Debug Outbound IDoc in SAP ABAP

Method 1: Use WE02 / WE05 to Inspect IDoc Status

  • Enter the transaction and select WE02 (or WE05
  • Filter your messages by type date, type or by partner
  • Double-click on the IDoc to view the status of its records as well as control records and data segments.
  • Status 03: Data sent to port Status 12 = Dispatching OK Status 02: Error when passing data

Method 2: Set a Breakpoint in the Outbound Function Module

  • Find the outbound processing function module in the definition of the port (WE21)
  • Create an outside breakpoint either in SE37 or SE80
  • Start the business transaction (e.g. or save the sales order)
  • The debugger will stop at your breakpoint. take a look at your IDoc controls and the data structure

Method 3: Use Transaction WE19 to Re-trigger an Existing IDoc

  • Visit WE19 and enter the IDoc number.
  • Modify segment data if needed
  • Process the IDoc to test outbound handling, without the need to create new documents for business

How to Debug Inbound IDoc in SAP ABAP

Method 1: Set Breakpoint in the Inbound Function Module

  • Find out which module is responsible for processing the Inbound IDoc (check your WE57/WE20 profile of your partner)
  • Start the function module from SE37
  • Set an external breakpoint or session breakpoint prior to the start of the process
  • Re-process or send an inbound IDoc -The debugger will stop at the breakpoint you set.

Method 2: Use BD87 to Reprocess Failed IDocs

  • Go to the transaction Go to transaction
  • Filter for IDocs with an error status (e.g. status 51 = Error within the application document)
  • Choose the IDoc and then click "Execute" to reprocess
  • Make sure to check the latest status records to see the latest result of the processing

Method 3: Use WE19 for Inbound Simulation

  • Within WE19 Enter your existing IDoc number, or make one using a document
  • Modify segment data as required
  • Inbound as an executable to test the logic of your inbound function module without needing to wait on an external system

Common IDoc Status Codes

Status Code Direction Meaning
01 Outbound IDoc created
02 Outbound Error in passing data to the port
03 Outbound Data is passed to the port in a good way.
12 Outbound Dispatch OK
30 Inbound IDoc is ready for processing inbound
51 Inbound Error in application document
53 Inbound Application document posted
64 Inbound IDoc is ready to be transferred to the application

IDoc in SAP ABAP Step by Step: Quick Reference Checklist

This is a step-by-step overview of the process from beginning to end IDoc production within SAP ABAP:

  • WE31 - Customize and enable custom segments by using the required fields
  • WE30 - Make the basic IDoc type (or Extension Type) with these segments
  • WE81 - Define the type of message for your IDoc
  • WE82 -- Link the Message Type to the IDoc Type
  • WE20 Configure the Partner Profile using outbound and/or inbound parameters
  • WE57 - Create the function inbound module (for the inbound IDocs)
  • code in ABAP Write the outbound population logic, or the inbound processing function module
  • WE19/BD87 -Debug and test using these transactions

Best Practices for IDoc Development in SAP ABAP

  • Always stick to IDoc types that are IDoc types that are standard IDoc type first, before you create custom ones. SAP has more than 500 of the standard IDoc types.
  • Utilize IDoc extensions in lieu of creating custom IDoc types when just some fields are required to be added to the standard type
  • Be sure to handle errors in a specific manner within your function module for inbound and then write relevant status messages.
  • Make use of the transaction SALE (ALE Configuration) to establish the distribution system and logical model prior to conducting tests
  • Check IDocs frequently by using WE02, WE05 as well as IDocs regularly using BD87 within production settings
  • Never code partner numbers in hardcode or port names. utilize configuration tables or customized entries instead.
  • All processing errors that are inbound to a custom Z-table that can be used for business traceability

Conclusion

The understanding of IDoc and IDoc-based integrations in SAP ABAP from its definition to the custom IDoc creation as well as inbound IDoc configuration, IDoc extensions, and investigating both inbound and outbound flow -- will give you the full picture of SAP's most effective data exchange system. If you follow the step-by-step procedure described in this document you will be able to confidently plan and build IDoc-based integrations across any SAP system.

If you're configuring a basic ALE scenario or creating an elaborate EDI pipeline that involves outside partners, the fundamentals discussed here -starting with WE31 segment creation to BD87 error processing are the essential skills that each seriously SAP ABAP developer requires to have in their toolbox.

Looking to master SAP ABAP integration and IDoc development? Explore hands-on SAP ABAP training programs at Best Online Career— designed by industry experts to take your career from beginner to job-ready.

Tags

#idoc in sap abap#custom idoc creation in sap abap#how to debug outbound idoc in sap abap#how to debug the idoc in sap abap#what is idoc in sap abap#how to create custom idoc in sap abap#how to create idoc in sap abap#how to create inbound idoc in sap abap#how to debug an idoc in sap abap#how to debug inbound idoc in sap abap#idoc creation in sap abap#idoc extension in sap abap#idoc in sap abap step by step

Share this article

Help others discover this valuable SAP content

About Best Online Career

Experienced SAP consultant with expertise in various SAP modules. Dedicated to helping professionals advance their SAP careers through quality training and guidance.

Related Articles