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.
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.
🎯 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.
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
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).
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.
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.
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
| Feature | Session Method | Call Transaction |
|---|---|---|
| Processing | Asynchronous (background) | Synchronous (immediate) |
| Speed | Slower | Faster |
| Error log | Full log in SM35 | Limited, error table only |
| Can schedule? | Yes, via SM35 | No |
| Rollback support | Yes (session can be cancelled) | Limited |
| Use case | Large data migration | Small 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.
🔗 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
| BAPI | What It Does |
|---|---|
BAPI_CUSTOMER_CREATEFROMDATA1 | Create a customer master record |
BAPI_MATERIAL_SAVEDATA | Create or change a material master |
BAPI_VENDOR_CREATE | Create a vendor master record |
BAPI_SALESORDER_CREATEFROMDAT2 | Create a sales order |
BAPI_PO_CREATE1 | Create a purchase order |
BAPI_ACC_DOCUMENT_POST | Post an accounting document |
BAPI_TRANSACTION_COMMIT | Commit changes made by other BAPIs |
BAPI_TRANSACTION_ROLLBACK | Rollback 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.
RETURN (type BAPIRET2). Check for entries with TYPE = 'E' or 'A' before committing. If any error exists, call BAPI_TRANSACTION_ROLLBACK instead.
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.
The three-part structure of an IDoc
| Record Type | What It Contains | Analogy |
|---|---|---|
| Control Record | Routing info: sender, receiver, message type, IDoc type, port | Address on an envelope |
| Data Records | The actual business data, organized into segments | Letters inside the envelope |
| Status Records | Processing history: created, sent, received, processed, errors | Delivery tracking stamps |
Common IDoc types
| IDoc Type | Business Document |
|---|---|
ORDERS | Purchase orders (purchasing) |
ORDERS05 | Sales orders |
INVOIC | Invoices |
DESADV | Delivery notes (shipping notifications) |
MATMAS | Material master data |
CREMAS | Vendor master data |
DEBMAS | Customer master data |
WMMBID | Inventory movements |
Key IDoc transactions
| Transaction | Purpose |
|---|---|
| WE02 / WE05 | View IDocs by number or date |
| WE19 | Test IDoc processing (simulate inbound/outbound) |
| WE20 | Partner profiles — configure who sends what |
| WE21 | Ports — configure communication channels |
| BD64 | Distribution model (ALE configuration) |
| BD87 | Reprocess 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 Type | Behavior | Use Case |
|---|---|---|
| sRFC (Synchronous) | Caller waits for response | Real-time interfaces where you need immediate results |
| aRFC (Asynchronous) | Caller does not wait | Fire-and-forget operations |
| tRFC (Transactional) | Guaranteed once-only execution | Data transfers that must not duplicate |
| qRFC (Queued) | Ordered processing via queues | Interfaces where order matters |
| bgRFC (Background) | Modern replacement for tRFC and qRFC | All 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
RETURNtable. - 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
- BDC Recording: Use SHDB to record a simple transaction (e.g.,
MM01orXK01). Complete one example, save, and examine the generated ABAP code. Understand each BDC_INSERT call. - 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.
- BAPI Call: Call
BAPI_MATERIAL_GETDETAILfor any material number. Display the returned data. Understand how the RETURN table communicates success or failure. - BAPI Create + Commit: Write a program that calls
BAPI_MATERIAL_SAVEDATAto create a material, checks the RETURN table, and callsBAPI_TRANSACTION_COMMITonly if no errors. Then check MM03 to verify the material was created. - IDoc Exploration: In transaction WE02, browse existing IDocs in the system. Examine their structure — identify Control, Data, and Status records.
- File Upload: Write a program that uses
GUI_UPLOADto read a text file from your PC and display its contents.
Test: Kon Banega Crorepati?
5 questions. ₹1 Crore. Prove you understood BDC, BAPI & IDoc. No pressure — restart anytime.
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 us