BDC, BAPI & IDoc

ABAP BDC, BAPI & IDoc: Data Migration & Interfaces 2026 | ABAP Zero to Hero
ABAP Zero to Hero

Chapter 13  ·  Real-World Skills

BDC, BAPI & IDoc

How to move data in and out of SAP — batch input, business APIs, and IDoc interfaces. The interface skills every real project needs.

Chapter 13 of 20 20 min read Part 3: Real-World 10 Interview Q&A

SAP does not live in isolation. Every company that runs SAP also has other systems — CRM, e-commerce, legacy databases, third-party warehouses, custom mobile apps. And every company eventually migrates data from old systems into SAP when they go live.

This is where the three interface techniques you will learn in this chapter come in: BDC for bulk data upload, BAPI for standardized business operations, and IDoc for system-to-system data exchange.

Why this matters Interface development is one of the highest-demand ABAP skills in the market. Whenever you hear “integration” or “data migration”, these three techniques are what make it happen.

🎯 What You Will Learn in This Chapter

  • What BDC is and when to use it for data migration
  • The difference between Session Method and Call Transaction
  • How to record a BDC session using SHDB
  • What a BAPI is and why it is upgrade-safe
  • How to call a BAPI and commit changes with BAPI_TRANSACTION_COMMIT
  • What an IDoc is and its three-part structure
  • Common IDoc types and the role of ALE
  • Different RFC types (sRFC, aRFC, tRFC, qRFC, bgRFC)
  • How to upload and download files with GUI_UPLOAD / GUI_DOWNLOAD

📥 Technique 1: BDC (Batch Data Communication)

BDC is SAP’s technique for uploading large volumes of data by simulating user input on standard transactions. You record the steps a user takes, save them as a batch input session, and run the session to create thousands of records automatically.

Analogy Imagine having to enter 5,000 customer records manually. BDC is like hiring 5,000 temporary users who each enter one record — except it is a single program that does all 5,000 automatically.

When to use BDC

  • Data migration — moving legacy data into a new SAP system during go-live
  • Bulk uploads — loading thousands of records at once (customers, materials, vendors)
  • When no BAPI exists — BDC works on any transaction, BAPI only where SAP provides one
  • One-time data loads — initial setup of master data or transactional data

Recording a BDC session — SHDB

1 Open SHDB

Transaction SHDB is the BDC recording tool. Click New Recording, enter a name (e.g., Z_MM01_REC) and the transaction code you want to record (e.g., MM01 for material master).

2 Perform the transaction manually

SAP records every screen field you enter. Fill in one complete example record from start to finish. When the transaction completes, click Save on the recording.

3 View the generated code

SHDB generates ABAP code that replays the recording using BDC_OPEN_GROUP, BDC_INSERT, and BDC_CLOSE_GROUP. Copy this code into your ABAP program.

4 Adapt and loop

Wrap the recording inside a loop over your source data (uploaded file, internal table). Replace the hardcoded field values with variables from your data.

Session Method vs Call Transaction

FeatureSession MethodCall Transaction
ProcessingAsynchronous (background)Synchronous (immediate)
SpeedSlowerFaster
Error logFull log in SM35Limited, error table only
Can schedule?Yes, via SM35No
Rollback supportYes (session can be cancelled)Limited
Use caseLarge data migrationSmall batch, real-time validation

Session Method — Code Example

" 1. Open the session
CALL FUNCTION 'BDC_OPEN_GROUP'
  EXPORTING
    client = sy-mandt
    group  = 'ZBDC_SESSION'
    user   = sy-uname
    keep   = 'X'.

" 2. Loop over source data
LOOP AT lt_data INTO DATA(ls_data).
  CLEAR lt_bdcdata.
  PERFORM add_bdc_field USING 'BDC_CURSOR' 'RMMG1-MATNR'.
  PERFORM add_bdc_field USING 'BDC_OKCODE' '/00'.
  PERFORM add_bdc_field USING 'RMMG1-MATNR' ls_data-matnr.
  " ... more fields ...

  CALL FUNCTION 'BDC_INSERT'
    EXPORTING
      tcode     = 'MM01'
    TABLES
      dynprotab = lt_bdcdata.
ENDLOOP.

" 3. Close the session
CALL FUNCTION 'BDC_CLOSE_GROUP'.

" 4. Run the session in SM35
" SM35 → Select session → Process → Foreground/Background

" Helper FORM to build BDC data
FORM add_bdc_field USING fname fval.
  DATA: ls_bdcdata TYPE bdcdata.
  ls_bdcdata-fnam = fname.
  ls_bdcdata-fval = fval.
  APPEND ls_bdcdata TO lt_bdcdata.
ENDFORM.

Call Transaction — Code Example

LOOP AT lt_data INTO DATA(ls_data).
  CLEAR lt_bdcdata.
  " Build bdcdata for this record
  PERFORM add_bdc_field USING 'BDC_CURSOR' 'RMMG1-MATNR'.
  PERFORM add_bdc_field USING 'BDC_OKCODE' '/00'.
  PERFORM add_bdc_field USING 'RMMG1-MATNR' ls_data-matnr.

  CALL TRANSACTION 'MM01'
    USING lt_bdcdata
    MODE 'N'                " N = no display, E = errors only, A = all screens
    UPDATE 'S'              " S = synchronous, A = asynchronous, L = local
    MESSAGES INTO lt_messages.

  " Check messages for errors
  LOOP AT lt_messages INTO DATA(ls_msg) WHERE msgtyp = 'E' OR msgtyp = 'A'.
    WRITE: / 'Error:', ls_msg-msgv1, ls_msg-msgv2.
  ENDLOOP.
ENDLOOP.
BDC is not upgrade-safe Because BDC depends on screen field names, if SAP changes a screen layout during an upgrade, your BDC program breaks. This is why BAPIs are preferred for new development.

🔗 Technique 2: BAPI (Business API)

A BAPI is a standardized, RFC-enabled function module that exposes a business operation in SAP. Instead of simulating user input on a screen (like BDC), you call a documented, upgrade-safe function that performs the operation directly.

Why BAPIs are better than BDC

  • Upgrade-safe — SAP guarantees BAPI interfaces across releases
  • Documented — every BAPI has clear input/output parameters and return messages
  • Remote-enabled — can be called from external systems via RFC/HTTP
  • Standardized error handling — every BAPI returns a RETURN table with type, code, and message
  • Business-level — you call “create customer”, not “fill screen 1, press enter, fill screen 2…”

Common BAPIs

BAPIWhat It Does
BAPI_CUSTOMER_CREATEFROMDATA1Create a customer master record
BAPI_MATERIAL_SAVEDATACreate or change a material master
BAPI_VENDOR_CREATECreate a vendor master record
BAPI_SALESORDER_CREATEFROMDAT2Create a sales order
BAPI_PO_CREATE1Create a purchase order
BAPI_ACC_DOCUMENT_POSTPost an accounting document
BAPI_TRANSACTION_COMMITCommit changes made by other BAPIs
BAPI_TRANSACTION_ROLLBACKRollback changes made by other BAPIs

Anatomy of a BAPI call

DATA: ls_header   TYPE bapimathead,
      ls_client   TYPE bapi_mara,
      ls_clientx  TYPE bapi_marax,
      lt_return   TYPE TABLE OF bapiret2.

" 1. Fill input structures
ls_header-material = 'ZTEST001'.
ls_header-ind_sector = 'M'.
ls_header-matl_type  = 'FERT'.
ls_client-base_uom = 'PC'.
ls_clientx-base_uom = 'X'.  " X marks the field as changed

" 2. Call the BAPI
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
  EXPORTING
    headdata       = ls_header
    clientdata     = ls_client
    clientdatax    = ls_clientx
  TABLES
    returnmessages = lt_return.

" 3. Check the return table
READ TABLE lt_return INTO DATA(ls_return)
  WITH KEY type = 'E'.
IF sy-subrc = 0.
  WRITE: / 'Error:', ls_return-message.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
  " 4. Commit only if no errors
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.
  WRITE: / 'Material created successfully.'.
ENDIF.
Always check the RETURN table Every BAPI returns a table called RETURN (type BAPIRET2). Check for entries with TYPE = 'E' or 'A' before committing. If any error exists, call BAPI_TRANSACTION_ROLLBACK instead.
BAPI_TRANSACTION_COMMIT is not optional Without it, your BAPI changes are stored in the SAP LUW but never written to the database. The program appears to succeed but no data is saved. Always call COMMIT with WAIT = 'X' to ensure the commit completes before the program moves on.

📨 Technique 3: IDoc (Intermediate Document)

An IDoc is SAP’s standard container for exchanging business documents between systems. When SAP sends a purchase order to a supplier, when two SAP systems share customer master data, when SAP receives invoice data from a bank — that data travels as an IDoc.

Analogy Think of an IDoc as an envelope. The envelope has a routing label on the outside (control record), business documents inside (data records), and a delivery history stamped on it (status records).

The three-part structure of an IDoc

Record TypeWhat It ContainsAnalogy
Control RecordRouting info: sender, receiver, message type, IDoc type, portAddress on an envelope
Data RecordsThe actual business data, organized into segmentsLetters inside the envelope
Status RecordsProcessing history: created, sent, received, processed, errorsDelivery tracking stamps

Common IDoc types

IDoc TypeBusiness Document
ORDERSPurchase orders (purchasing)
ORDERS05Sales orders
INVOICInvoices
DESADVDelivery notes (shipping notifications)
MATMASMaterial master data
CREMASVendor master data
DEBMASCustomer master data
WMMBIDInventory movements

Key IDoc transactions

TransactionPurpose
WE02 / WE05View IDocs by number or date
WE19Test IDoc processing (simulate inbound/outbound)
WE20Partner profiles — configure who sends what
WE21Ports — configure communication channels
BD64Distribution model (ALE configuration)
BD87Reprocess failed IDocs

What is ALE?

ALE (Application Link Enabling) is SAP’s technology for distributing master and transactional data between SAP systems (or SAP and external systems) using IDocs. It is commonly used in:

  • Central master data distribution (one system owns customer master, others receive it)
  • Multi-system ERP landscapes
  • SAP-to-SAP communication across modules
  • SAP-to-SAP or SAP-to-third-party integrations

📡 RFC Types — How SAP Talks to Other Systems

RFC (Remote Function Call) is the protocol SAP uses to invoke function modules in remote systems. BAPIs typically use RFC for external calls.

RFC TypeBehaviorUse Case
sRFC (Synchronous)Caller waits for responseReal-time interfaces where you need immediate results
aRFC (Asynchronous)Caller does not waitFire-and-forget operations
tRFC (Transactional)Guaranteed once-only executionData transfers that must not duplicate
qRFC (Queued)Ordered processing via queuesInterfaces where order matters
bgRFC (Background)Modern replacement for tRFC and qRFCAll new interfaces

📁 File Upload/Download — GUI_UPLOAD / GUI_DOWNLOAD

Most BDC and BAPI programs start with data from a file. Here is how to upload it.

Upload a file from the user’s PC

DATA: lt_raw_data TYPE TABLE OF string,
      lv_filename TYPE string.

" Ask user to select a file
CALL METHOD cl_gui_frontend_services=>file_open_dialog
  CHANGING
    file_table = DATA(lt_files)
    rc         = DATA(lv_rc).

READ TABLE lt_files INTO DATA(ls_file) INDEX 1.
lv_filename = ls_file-filename.

" Upload the file
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename   = lv_filename
    filetype   = 'ASC'
  TABLES
    data_tab   = lt_raw_data
  EXCEPTIONS
    file_open_error = 1
    OTHERS          = 2.

IF sy-subrc <> 0.
  MESSAGE 'Error opening file' TYPE 'E'.
ENDIF.

Download to the user’s PC

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename = 'C:\temp\report.xlsx'
    filetype = 'ASC'
  TABLES
    data_tab = lt_output.

📝 Chapter Summary

  • BDC — simulates user input on standard transactions. Used for bulk data migration. Session Method processes in background (SM35); Call Transaction runs immediately.
  • BAPI — standardized, upgrade-safe function modules that expose business operations. Always check the RETURN table.
  • BAPI_TRANSACTION_COMMIT — required to save changes made by BAPIs. Without it, nothing is written to the database.
  • IDoc — SAP’s container for system-to-system data exchange. Three parts: Control Record, Data Records, Status Records.
  • ALE — SAP’s technology for distributing data via IDocs. Uses distribution models, partner profiles, and ports.
  • RFC — protocol for remote function calls. Types: sRFC, aRFC, tRFC, qRFC, bgRFC.
  • GUI_UPLOAD / GUI_DOWNLOAD — the standard way to move files between the user’s PC and SAP.
  • Prefer BAPI over BDC for new development. Use BDC only when no BAPI exists.

🎤 Interview Questions & Answers

BDC, BAPI, and IDoc are some of the most common interview topics — especially for developers working on integration and migration projects. Know these cold.

1 What is BDC in ABAP and when do you use it?

BDC (Batch Data Communication) is a technique for uploading large amounts of data into SAP by simulating user input on standard transactions. You record the steps a user takes, generate a batch input session, and run it to create hundreds or thousands of records. BDC is used for data migration (legacy to SAP), bulk uploads, and automating repetitive data entry.

2 What is the difference between Session Method and Call Transaction?

Session Method creates a batch input session that runs in the background. It processes data asynchronously, provides error logs (SM35), and can be scheduled. Call Transaction processes data immediately in the same program run, is faster, but provides limited error logging and locks the session. Session Method is safer for large data; Call Transaction is faster for smaller real-time processing.

3 What is a BAPI and why is it used?

A BAPI (Business API) is a standardized, RFC-enabled function module that provides a stable interface to SAP business objects. BAPIs are used for interfacing SAP with external systems (e-commerce, CRM, custom applications) and for internal automation. BAPIs are officially supported, documented, and upgrade-safe, unlike calling standard function modules directly.

4 What is BAPI_TRANSACTION_COMMIT?

BAPI_TRANSACTION_COMMIT is a standard BAPI used to commit changes made by other BAPIs. When you call a BAPI that creates or modifies data, the changes are stored in the SAP LUW (Logical Unit of Work) but not saved to the database. You must call BAPI_TRANSACTION_COMMIT with WAIT = 'X' to write the changes permanently. Without it, the data is not saved.

5 What is an IDoc?

IDoc (Intermediate Document) is SAP’s standard data container for exchanging business documents between SAP and external systems (or between SAP systems). An IDoc has a three-part structure: Control Record (routing information), Data Records (the actual business data in segments), and Status Records (processing history). IDocs are the backbone of SAP’s ALE technology.

6 What are the different IDoc types?

IDoc types correspond to business documents. Common ones include: ORDERS (purchase orders), ORDERS05 (sales orders), INVOIC (invoices), DESADV (delivery notes), MATMAS (material master), CREMAS (vendor master), DEBMAS (customer master), and WMMBID (inventory movements). Each IDoc type has a defined structure of segments that match the business document.

7 What is ALE?

ALE (Application Link Enabling) is SAP’s technology for distributing data between SAP systems or between SAP and external systems using IDocs. It supports two distribution models: push (central system broadcasts data) and pull (receiving system requests data). ALE uses distribution models, message types, ports, partner profiles, and RFC destinations to control what data flows where.

8 What is RFC? What are its types?

RFC (Remote Function Call) is SAP’s protocol for calling function modules in a remote SAP system. Types include: Synchronous RFC (sRFC) — caller waits for response; Asynchronous RFC (aRFC) — caller does not wait; Transactional RFC (tRFC) — guaranteed once-only execution; Queued RFC (qRFC) — ordered processing; and Background RFC (bgRFC) — modern replacement supporting both tRFC and qRFC. BAPIs are typically called via RFC.

9 How do you upload a file in ABAP?

Use GUI_UPLOAD function module to upload files from the user’s PC or application server to SAP. You specify the filename, file type (BIN or ASC), and target internal table. For downloading, use GUI_DOWNLOAD. For application server files, use OPEN DATASET, READ DATASET, and CLOSE DATASET statements.

10 What is the difference between BDC and BAPI?

BDC simulates user input on screens — you record a transaction, create a session, and run it. It is not upgrade-safe because screen fields can change. BAPI is a stable, documented interface to business objects — officially supported by SAP, upgrade-safe, and RFC-enabled. Use BAPI for new interfaces and BDC for legacy migrations when no BAPI exists.

🛠 Practice Task for This Chapter

Try at least one of these exercises. The more you practice, the more confident you will be in interviews.

  1. BDC Recording: Use SHDB to record a simple transaction (e.g., MM01 or XK01). Complete one example, save, and examine the generated ABAP code. Understand each BDC_INSERT call.
  2. BDC Session: Write a program that uploads a CSV file of 5 materials, creates a BDC session, and processes it in SM35. Check the log for errors.
  3. BAPI Call: Call BAPI_MATERIAL_GETDETAIL for any material number. Display the returned data. Understand how the RETURN table communicates success or failure.
  4. BAPI Create + Commit: Write a program that calls BAPI_MATERIAL_SAVEDATA to create a material, checks the RETURN table, and calls BAPI_TRANSACTION_COMMIT only if no errors. Then check MM03 to verify the material was created.
  5. IDoc Exploration: In transaction WE02, browse existing IDocs in the system. Examine their structure — identify Control, Data, and Status records.
  6. File Upload: Write a program that uses GUI_UPLOAD to read a text file from your PC and display its contents.
Why this matters Interviewers frequently ask: “Have you worked with BDC or BAPI?” Being able to describe a real example — what you uploaded, how you handled errors, whether you used Session or Call Transaction — demonstrates you have hands-on experience, not just theory.
🎯 Chapter 13 Challenge

Test: Kon Banega Crorepati?

5 questions. ₹1 Crore. Prove you understood BDC, BAPI & IDoc. No pressure — restart anytime.

₹1,000 ₹10,000 ₹1,00,000 ₹10,00,000 ₹1 Crore
Question 1 of 5
Score: 0
Q1
🏆
You Did It!
0/5Correct Answers
You won ₹0
➡️ Next Chapter

➡️ Next Chapter

You can now move data in and out of SAP. In Chapter 14, you will learn Smart Forms & Adobe Forms — how to print invoices, purchase orders, and delivery notes.

Chapter 14 Smart Forms & Adobe Forms →
Want to Learn Faster?

Explore Our Instructor-Led SAP & IT Courses

Self-study works. But if you want guided training, real project practice, and placement support — here are the courses we offer. Book a free demo before you decide.

WhatsApp WhatsApp us
Call Now Button