Skip to content

SAP IDoc & BAPI — System Integration Guide

DodaTech Updated 2026-06-24 7 min read

In this tutorial, you'll learn about SAP IDoc & BAPI. We cover key concepts, practical examples, and best practices.

SAP IDoc and BAPI are the two primary technologies for integrating SAP systems with each other and with external applications — IDocs handle document-based asynchronous messaging while BAPIs provide synchronous function calls to SAP business objects.

What You'll Learn

You will learn the structure of IDocs, how to create and process them, BAPI method signatures, ALE configuration for system-to-system communication, and when to use IDoc vs BAPI for integration.

Why It Matters

Every SAP system must exchange data with other systems — customers send orders, suppliers send invoices, banks send statements, subsidiaries send financial data. IDocs and BAPIs provide standard, reliable, auditable integration methods that work across SAP and non-SAP systems.

Real-World Use

A retail chain receives purchase orders from 50 stores. Each store's system sends a BAPI call to create the order in S/4HANA. When the warehouse ships, an IDoc with delivery confirmation is automatically sent back to the store system — asynchronous, guaranteed delivery with error handling.

Learning Path

flowchart LR
  A["SAP ABAP"] --> B["ABAP Objects"]
  B --> C["IDoc & BAPI
You are here"] C --> D["SAP CPI"] D --> E["SAP Workflow"] style C fill:#f90,color:#fff

IDoc Architecture

flowchart LR
  A["Sender
System"] -->|"Outbound IDoc"| B["Port
(tRFC)"] B --> C["Partner
Profile"] C --> D["Receiver
System"] D -->|"Inbound IDoc"| E["Processing
Program"] E --> F["SAP
Application"]

IDoc Structure

An IDoc has three levels:

IDoc: ORDERS05 (Purchase Order)
Control Record:
  IDOC_NUMBER:    0000000010
  DIRECT:         1 (Outbound)
  STATUS:         30 (In Process)
  SENDER:         S4H_001
  RECEIVER:       ECC_001
  MESTYP:         ORDERS (Message Type)
  IDOCTYP:        ORDERS05

Data Records (Segments):
  E1EDK01 (Header):
    - BELNR: PO-1001 (Order number)
    - BLDAT: 20260624 (Document date)
    - LIFEX: 20260724 (Delivery date)

  E1EDP01 (Item):
    - POSNR: 10 (Item number)
    - MATNR: MAT-100 (Material)
    - MENGE: 500 (Quantity)

IDoc Message Types

Message Type Purpose IDoc Type
ORDERS Purchase order ORDERS05
INVOIC Invoice INVOIC02
MATMAS Material master MATMAS05
DEBMAS Customer master DEBMAS06
CREMAS Vendor master CREMAS06
STATUS IDoc status update STATUS02

Creating and Processing IDocs

Outbound IDoc via ABAP

* Fill IDoc segments
DATA: ls_edidc TYPE edidc,
      lt_edidd TYPE TABLE OF edidd.

ls_edidc-mestype = 'ORDERS'.
ls_edidc-idoctyp = 'ORDERS05'.

APPEND VALUE #(
  segnam = 'E1EDK01'
  sdata  = 'PO-1001 20260624 20260724'
) TO lt_edidd.

* Send IDoc using master IDoc function
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
  EXPORTING
    master_idoc_control = ls_edidc
  TABLES
    master_idoc_data    = lt_edidd.

Inbound IDoc Processing

When an IDoc arrives, SAP calls a function module based on the message type:

FUNCTION IDOC_INPUT_ORDERS.
* Called automatically when ORDERS IDoc arrives

  DATA: ls_e1edk01 TYPE e1edk01.

  LOOP AT idoc_containers INTO container.
    READ TABLE idoc_data INTO DATA(ls_data)
      WITH KEY segnam = 'E1EDK01'.
    ls_e1edk01 = ls_data-sdata.

    " Create purchase order in SAP
    CALL FUNCTION 'BAPI_PO_CREATE'
      EXPORTING
        purchaseorder = ls_e1edk01-belnr.
  ENDLOOP.

  " Return success
  IDOC_CONTROL_STATUS = '53'. " Success
ENDFUNCTION.

BAPI — Business Application Programming Interface

BAPIs are standard SAP methods for business objects. Each BAPI has a defined signature, is RFC-enabled, and includes error handling.

Common BAPIs

BAPI Purpose
BAPI_PO_CREATE Create purchase order
BAPI_SALESORDER_CREATEFROMDAT2 Create sales order
BAPI_MATERIAL_SAVEDATA Create/change material master
BAPI_ACC_DOCUMENT_POST Post accounting document
BAPI_USER_CREATE Create SAP user

Calling a BAPI

DATA: ls_header   TYPE bapisdh1,
      lt_items    TYPE TABLE OF bapisditm,
      lt_returns  TYPE TABLE OF bapiret2.

ls_header-doc_type = 'TA'.
ls_header-purch_no_c = 'ORDER-001'.

APPEND VALUE #(
  material = 'MAT-100'
  quantity = '10.000'
) TO lt_items.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
  EXPORTING
    sales_header_in    = ls_header
  TABLES
    sales_items_in     = lt_items
    return             = lt_returns.

LOOP AT lt_returns INTO DATA(ls_return)
     WHERE type = 'E'. " Error
  WRITE: / 'Error:', ls_return-message.
ENDLOOP.

IF sy-subrc <> 0.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.

ALE Configuration

ALE (Application Link Enabling) distributes IDocs between SAP systems:

ALE Configuration Steps (SALE):
  1. Define logical system (BD54)
  2. Assign logical system to client (SCC4)
  3. Create RFC destination (SM59)
  4. Create partner profile (WE20)
     - Partner: Logical system
     - Message type: ORDERS
     - IDoc type: ORDERS05
     - Process code: ORDE (triggers inbound function)
  5. Create distribution model (BD64)
  6. Generate partner profiles (BD82)
  7. Test with transaction WE19

IDoc vs BAPI

Aspect IDoc BAPI
Communication Asynchronous Synchronous
Delivery Guaranteed (tRFC) Request/response
Data volume Large (batch) Small (single transaction)
Error handling Status codes per segment Return table with messages
Mapping Segment-based Parameter-based
Use case Bulk data exchange Real-time transaction

Real-World Scenario: Order-to-Cash Integration

  1. External web shop calls BAPI_SALESORDER_CREATEFROMDAT2 to create order in S/4HANA
  2. S/4HANA ships goods and automatically creates outbound IDoc (DESADV) to notify the web shop
  3. Web shop's system receives the IDoc and updates shipment status
  4. When customer pays, S/4HANA creates outbound IDoc (INVOIC) to the web shop
  5. IDocs that fail to process are monitored in WE02 and can be reprocessed via WE19

Common Errors

1. IDoc Stuck with Status 02 or 51

Status 02 means the IDoc was transferred but not posted. Status 51 means the application error occurred. Check the IDoc log in WE02 and fix the data (e.g., missing material master).

2. Partner Profile Missing

Without a partner profile (WE20), the system does not know how to process an inbound IDoc. Define it by message type and process code.

3. BAPI Returns Errors

Always check the RETURN table from BAPIs. Errors like material not found or company code missing must be handled before COMMIT.

4. RFC Destination Not Working

Test RFC destinations with SM59. A failed connection prevents both BAPI and IDoc communication between systems.

5. Inbound Function Module Not Active

The function module that processes inbound IDocs must be active and linked to the process code in WE57.

6. Segment Exceeds Max Length

If an IDoc segment contains data exceeding its defined length, the IDoc fails. Check the segment definition in WE30.

Practice Questions

  1. What is an IDoc? Intermediate Document — SAP's standard format for asynchronous data exchange between systems.

  2. What is a BAPI? Business Application Programming Interface — a standard, RFC-enabled method for synchronous access to SAP business objects.

  3. What is the difference between synchronous and asynchronous integration? Synchronous (BAPI) waits for immediate response. Asynchronous (IDoc) sends data and continues — receipt is guaranteed but response comes later.

  4. What transaction monitors IDocs? WE02 (IDoc list) and WE05 (detailed IDoc display with segment data).

  5. What is ALE? Application Link Enabling — the SAP technology for configuring IDoc distribution between logical systems.

Challenge: A company acquires a subsidiary with a different ERP. Design an integration architecture using IDocs and BAPIs to share customer master data (DEBMAS), vendor master (CREMAS), and purchase orders (ORDERS) between the two SAP systems. Include error handling and monitoring.

FAQ

What is the difference between tRFC and qRFC?

tRFC (transactional RFC) ensures once-only delivery. qRFC (queued RFC) guarantees sequential processing in the correct order — important for IDocs that must arrive in sequence.

Can BAPIs be used from non-SAP systems?

Yes. BAPIs are RFC-enabled and can be called from Java, .NET, Python, or any language supporting RFC libraries (SAP Connector, SAPJCo, PyRFC).

What is the maximum size of an IDoc?

An IDoc can contain up to 9,999 segments of up to 1,000 characters each — practical maximum around 10 MB per IDoc.

What is WE19 used for?

WE19 allows you to test IDoc processing — you can manually enter an IDoc, process it inbound, and see the result without sending from the external system.

What is BAPI_Transaction_COMMIT?

A BAPI that commits the changes from the previous BAPI calls. Without it, BAPI changes are rolled back when the RFC connection closes.

**Durga Antivirus Pro** uses IDoc-style message patterns for its distributed threat intelligence feed — each signature update is an "IDoc" with a control record (version, timestamp) and data records (signature hashes, patterns) distributed to all connected endpoints.

What's Next

Tutorial What You'll Learn
SAP ABAP Programming Core ABAP programming for BAPI and IDoc processing
SAP Integration Suite (CPI) Modern cloud-based integration using CPI

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Updated 2026-06-24.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro