Introduction to BDC Call Transaction Method

Batch Data Communication (BDC) Call Transaction Method is a widely used technique in SAP for automating data entry processes in a more flexible and immediate way. Unlike the Session Method, which stores data in a batch session for later execution, the Call Transaction Method processes transactions immediately in the system.

This tutorial will cover:

  • How to develop a BDC program using the Call Transaction Method
  • Reading input data and mapping it to SAP fields
  • Executing transactions in real-time using CALL TRANSACTION
  • Error handling and log generation

1. Overview of BDC Call Transaction Method

The BDC Call Transaction Method:
✔ Executes transactions immediately (Synchronous Processing).
✔ Requires manual error handling since no session is created.
✔ Is faster than the Session Method but less error-tolerant.

BDC Call Transaction Processing Flow

1️⃣ Read Data from an External File (CSV, Excel, or TXT)
2️⃣ Map Data to BDC Data Structure (BDCDATA)
3️⃣ Execute CALL TRANSACTION for Immediate Processing
4️⃣ Capture and Handle Errors


2. Developing a BDC Program Using Call Transaction Method

We will now create a BDC Call Transaction program to update Material Master (MM02) using an external input file.

Step 1: Define Data Structures

DATA: lt_bdcdata TYPE TABLE OF bdcdata,   " BDC Data Table
      ls_bdcdata TYPE bdcdata,            " BDC Data Structure
      lt_material TYPE TABLE OF string,   " Input Data Table
      lv_file TYPE string VALUE 'C:\temp\materials.txt',  " Input File Path
      lv_tcode TYPE tcode VALUE 'MM02'.   " Transaction Code

Step 2: Read Data from an Input File

DATA: lv_line TYPE string.

OPEN DATASET lv_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc <> 0.
  WRITE: 'Error opening file'.
  STOP.
ENDIF.

DO.
  READ DATASET lv_file INTO lv_line.
  IF sy-subrc <> 0. EXIT. ENDIF.
  APPEND lv_line TO lt_material.
ENDDO.

CLOSE DATASET lv_file.

Explanation:

  • Opens a flat file (materials.txt).
  • Reads material master records line by line.
  • Stores the data in lt_material for processing.

Step 3: Populate BDC Data Table (BDCDATA)

LOOP AT lt_material INTO lv_line.
  CLEAR: lt_bdcdata, ls_bdcdata.

  ls_bdcdata-program  = 'SAPLMGMM'. 
  ls_bdcdata-dynpro   = '0101'.
  ls_bdcdata-dynbegin = 'X'.
  APPEND ls_bdcdata TO lt_bdcdata.

  SPLIT lv_line AT ',' INTO DATA(lv_matnr) DATA(lv_mtart) DATA(lv_meins).

  ls_bdcdata-fnam = 'MATNR'.
  ls_bdcdata-fval = lv_matnr.
  APPEND ls_bdcdata TO lt_bdcdata.

  ls_bdcdata-fnam = 'MTART'.
  ls_bdcdata-fval = lv_mtart.
  APPEND ls_bdcdata TO lt_bdcdata.

  ls_bdcdata-fnam = 'MEINS'.
  ls_bdcdata-fval = lv_meins.
  APPEND ls_bdcdata TO lt_bdcdata.

  " Execute the Transaction using Call Transaction
  CALL TRANSACTION lv_tcode USING lt_bdcdata
    MODE 'N'   " No screen display
    UPDATE 'A' " Synchronous update
    MESSAGES INTO DATA(lt_messages).
  
ENDLOOP.

Explanation:
✔ Splits Material Number, Material Type, and Unit of Measure from input file.
✔ Populates BDC Data Table (BDCDATA).
✔ Uses CALL TRANSACTION to execute the transaction immediately.
Captures error messages using MESSAGES INTO lt_messages.


Step 4: Handling Errors in Call Transaction Method

Unlike the Session Method, which logs errors in SM35, the Call Transaction Method requires manual error handling.

1️⃣ Capture and Display Error Messages

DATA: lt_messages TYPE TABLE OF bapiret2.

CALL TRANSACTION lv_tcode USING lt_bdcdata
  MODE 'E'   " Display only errors
  UPDATE 'A' 
  MESSAGES INTO lt_messages.

LOOP AT lt_messages INTO DATA(ls_msg).
  WRITE: / ls_msg-msgtyp, ls_msg-msgid, ls_msg-msgnr, ls_msg-msgv1.
ENDLOOP.

2️⃣ Log Errors for Debugging

Instead of displaying errors immediately, you can store them in a log file:

OPEN DATASET 'C:\temp\error_log.txt' FOR OUTPUT IN TEXT MODE.

LOOP AT lt_messages INTO ls_msg.
  WRITE: ls_msg-msgtyp, ls_msg-msgid, ls_msg-msgnr, ls_msg-msgv1.
  TRANSFER ls_msg-msgv1 TO 'C:\temp\error_log.txt'.
ENDLOOP.

CLOSE DATASET 'C:\temp\error_log.txt'.

Explanation:
✔ Writes errors into a text file for later debugging.
✔ Useful when processing large data files where error logs need to be reviewed separately.


3. Advantages and Disadvantages of Call Transaction Method

FeatureAdvantagesDisadvantages
Processing ModeImmediate execution (Real-time)No automatic batch session
Error HandlingCaptures errors in internal tablesErrors must be handled manually
PerformanceFaster than Session MethodNo rollback option
Best Use CaseSmall, immediate updatesNot suitable for bulk data loads

4. Common Issues and Troubleshooting in Call Transaction

IssuePossible CauseSolution
Transaction fails with no messageMissing error handlingCapture MESSAGES INTO lt_messages
Some fields not updatedField names mismatchCheck SHDB recording for correct fields
BDC Mode not workingIncorrect mode usedUse MODE 'A' for debugging
Data inconsistenciesAsynchronous processing issuesUse UPDATE 'S' instead of UPDATE 'A'

Conclusion

The BDC Call Transaction Method is an efficient way to execute transactions in real-time, making it suitable for small and immediate updates.

Records transaction steps using SHDB.
Executes CALL TRANSACTION for real-time updates.
Implements manual error handling for failed records.


Next Tutorial: File Handling in BDC – Uploading and Processing Data Files →

👉 In the next tutorial, we will cover how to upload CSV, Excel, and text files, read them into an ABAP internal table, and process them in BDC.