Introduction:
In SAP ABAP, the BDC (Batch Data Communication) Session Method is a widely used technique for uploading large volumes of data into SAP transactions. Unlike the Call Transaction method, the Session Method stores the transaction data in a session, allowing it to be executed later through SM35. This provides better monitoring, detailed error logs and the ability to reprocess failed records.
However, in real-world business scenarios, manually executing sessions from SM35 is not always practical. Organizations often require BDC sessions to be processed automatically during off-business hours or according to a predefined schedule. This is where background job scheduling becomes valuable.
In this blog, I will demonstrate how to:
- Upload data from a local file using GUI_UPLOAD.
- Create a BDC session using BDC_OPEN_GROUP, BDC_INSERT, and BDC_CLOSE_GROUP.
- Automatically process the BDC session by scheduling the standard SAP program RSBDCSUB as a background job using JOB_OPEN and JOB_CLOSE.
- Monitor the background job execution using SM37 and verify the BDC session processing.
Architecture Overview:
The following diagram represents the end-to-end flow of the BDC session method with automatic background job scheduling.
+---------------------+
| Input File (Excel) |
| / Txt File |
+----------+----------+
|
v
+----------------------+
| GUI_UPLOAD |
| Read file into |
| Internal Table |
+----------+-----------+
|
v
+----------------------+
| Prepare BDC Data |
| (BDC_DYNPRO & |
| BDC_FIELD) |
+----------+-----------+
|
v
+----------------------+
| BDC Session Creation |
| BDC_OPEN_GROUP |
| BDC_INSERT |
| BDC_CLOSE_GROUP |
+----------+-----------+
|
v
+----------------------+
| Background Job |
| JOB_OPEN |
| SUBMIT RSBDCSUB |
| JOB_CLOSE |
+----------+-----------+
|
v
+----------------------+
| Background Processing |
| RSBDCSUB Executes |
| BDC Session |
+----------+-----------+
|
+------------------+
| |
v v
+------------------+ +------------------+
| SM35 | | SM37 |
| BDC Session Log | | Job Monitoring |
+------------------+ +------------------+
Flow Explanation:
1. Input File
a. The user selects a text file containing material master data.
2. GUI_UPLOAD
a. The program uploads the file from the presentation server into an internal table.
3. Prepare BDC Data
a. The program prepares the screen and field values using BDC_DYNPRO and BDC_FIELD.
4. Create the BDC Session
a. BDC_OPEN_GROUP creates the session.
b. BDC_INSERT adds each transaction to the session.
c. BDC_CLOSE_GROUP finalizes the session.
5. Schedule Background Job
a. JOB_OPEN creates a background job.
b. The standard SAP program RSBDCSUB is submitted to the job.
c. JOB_CLOSE starts the job immediately.
6. Background Processing
a. RSBDCSUB processes the BDC session automatically without user intervention.
7. Monitoring
a. Use SM35 to review the BDC session status and error logs.
b. Use SM37 to monitor the background job execution and job log.
Implementation:
Step 1: Go to the SHDB transaction and click on 'new recording.'
Step 2: Provide the transaction code and select the update mode.
Step 3: Press Enter. The system will navigate to the MM01 initial screen.
Step 4: Click Enter. In the Select View(s) screen, choose Basic Data 1 and click the ✓.
Step 5: Enter the material description and select Each (EA) as the base unit of measure.
Step 6: Save the material. After saving, the system records all the actions performed in the transaction, as shown below.
Step 7: Locate the recording you created in the list. Select it, then click Program. The system will automatically generate the BDC screen recording code.
Step 8: Enter the report program name, specify the package and then save the program.
Step 9: Copy the generated report program name. Go to SE38, enter the report program name and click Display.
Step 10: The generated report contains the BDC screen recording code. Copy the required BDC recording logic into your custom program. Then use the BDC Session function modules BDC_OPEN_GROUP, BDC_INSERT, and BDC_CLOSE_GROUP and pass the required parameters to create and process the BDC session.
REPORT zbdc_session_method
NO STANDARD PAGE HEADING LINE-SIZE 255.
TYPES : BEGIN OF ty_data,
matnr TYPE matnr,
mbrsh TYPE mbrsh,
mtart TYPE mtart,
END OF ty_data.
DATA : lt_data TYPE TABLE OF ty_data.
DATA : ls_data TYPE ty_data.
DATA : lv_file TYPE string.
DATA: lt_bdcdata TYPE TABLE OF bdcdata,
ls_bdcdata TYPE bdcdata.
" ---- Data declarations for background job / RSBDCSUB
DATA: gv_group TYPE apqi-groupid VALUE 'A001', " BDC session/group name
lv_jobname TYPE tbtcjob-jobname VALUE 'ZBDC_PROCESS_A001',
lv_jobcount TYPE tbtcjob-jobcount.
PARAMETERS : p_file TYPE localfile.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_file.
*include bdcrecx1_s.
START-OF-SELECTION.
lv_file = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file
* FILETYPE = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = lt_data
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
* DEST = FILLER8
group = 'A001'
* HOLDDATE = FILLER8
keep = 'X'
user = sy-uname
EXCEPTIONS
client_invalid = 1
destination_invalid = 2
group_invalid = 3
group_is_locked = 4
holddate_invalid = 5
internal_error = 6
queue_error = 7
running = 8
system_lock_error = 9
user_invalid = 10
OTHERS = 11.
IF sy-subrc <> 0.
WRITE: / 'Error opening BDC group. Return code:', sy-subrc.
RETURN.
ENDIF.
*perform open_group.
LOOP AT lt_data INTO ls_data.
PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RMMG1-MATNR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'ENTR'.
PERFORM bdc_field USING 'RMMG1-MATNR'
ls_data-matnr.
PERFORM bdc_field USING 'RMMG1-MBRSH'
ls_data-mbrsh.
PERFORM bdc_field USING 'RMMG1-MTART'
ls_data-mtart.
PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.
PERFORM bdc_field USING 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'
'X'.
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'MAKT-MAKTX'
'Test Material ( Session method )'.
PERFORM bdc_field USING 'BDC_CURSOR'
'MARA-MATKL'.
PERFORM bdc_field USING 'MARA-MEINS'
'EA'.
PERFORM bdc_field USING 'MARA-MATKL'
'A001'.
PERFORM bdc_dynpro USING 'SAPLSPO1' '0300'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=YES'.
*perform bdc_transaction using 'MM01'.
*
*perform close_group.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'MM01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
dynprotab = lt_bdcdata
EXCEPTIONS
internal_error = 1
not_open = 2
queue_error = 3
tcode_invalid = 4
printing_invalid = 5
posting_invalid = 6
OTHERS = 7.
IF sy-subrc <> 0.
WRITE: / 'Error inserting BDC record for material:', ls_data-matnr,
'Return code:', sy-subrc.
ENDIF.
REFRESH : lt_bdcdata.
ENDLOOP.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
not_open = 1
queue_error = 2
OTHERS = 3.
IF sy-subrc = 0.
WRITE:' Data inserted and Session closed successfully'.
* Trigger RSBDCSUB in background to process the BDC session
" 1. Open background job
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_jobname
IMPORTING
jobcount = lv_jobcount
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc <> 0.
WRITE: / 'Error opening background job. Return code:', sy-subrc.
ELSE.
" 2. Submit RSBDCSUB as a step within the job
SUBMIT rsbdcsub
WITH qname = gv_group
WITH from = 'X'
WITH zuart = 'N' " N = no dialog, fully background
VIA JOB lv_jobname NUMBER lv_jobcount
AND RETURN.
IF sy-subrc <> 0.
WRITE: / 'Error submitting RSBDCSUB. Return code:', sy-subrc.
ELSE.
" 3. Close the job and start it immediately
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_jobcount
jobname = lv_jobname
strtimmed = 'X' " start immediately
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
OTHERS = 8.
IF sy-subrc = 0.
WRITE: / 'Background job', lv_jobname, 'scheduled successfully',
/ 'to process BDC session:', gv_group.
ELSE.
WRITE: / 'Error closing/starting background job. Return code:', sy-subrc.
ENDIF.
ENDIF.
ENDIF.
ELSE.
WRITE: / 'Error closing BDC group. Return code:', sy-subrc.
ENDIF.
FORM bdc_dynpro USING program dynpro.
CLEAR ls_bdcdata.
ls_bdcdata-program = program.
ls_bdcdata-dynpro = dynpro.
ls_bdcdata-dynbegin = 'X'.
APPEND ls_bdcdata TO lt_bdcdata.
ENDFORM.
* Insert field *
FORM bdc_field USING fnam fval.
CLEAR ls_bdcdata.
ls_bdcdata-fnam = fnam.
ls_bdcdata-fval = fval.
APPEND ls_bdcdata TO lt_bdcdata.
ENDFORM. Step 11: To automate the execution of the BDC session without manual intervention, SAP provides a background job mechanism. This process uses the standard function modules JOB_OPEN and JOB_CLOSE and the standard SAP program RSBDCSUB.
* Trigger RSBDCSUB in background to process the BDC session
" 1. Open background job
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_jobname
IMPORTING
jobcount = lv_jobcount
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc <> 0.
WRITE: / 'Error opening background job. Return code:', sy-subrc.
ELSE.
" 2. Submit RSBDCSUB as a step within the job
SUBMIT rsbdcsub
WITH qname = gv_group
WITH from = 'X'
WITH zuart = 'N' " N = no dialog, fully background
VIA JOB lv_jobname NUMBER lv_jobcount
AND RETURN.
IF sy-subrc <> 0.
WRITE: / 'Error submitting RSBDCSUB. Return code:', sy-subrc.
ELSE.
" 3. Close the job and start it immediately
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_jobcount
jobname = lv_jobname
strtimmed = 'X' " start immediately
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
OTHERS = 8.
IF sy-subrc = 0.
WRITE: / 'Background job', lv_jobname, 'scheduled successfully',
/ 'to process BDC session:', gv_group.
ELSE.
WRITE: / 'Error closing/starting background job. Return code:', sy-subrc.
ENDIF.
ENDIF.
ENDIF.
ELSE.
WRITE: / 'Error closing BDC group. Return code:', sy-subrc.
ENDIF. Step 12: After executing the program, you will be prompted to select the input file. The file should contain the records to be uploaded.
Step 13: This is the input file I created and saved on my local desktop.
PATH: "C:\Users\Lenovo\Desktop\BDC_Session_Method.txt"
Step 14: Enter the file path and then click Execute to start the BDC processing.
After execution, the program displays the message "Data inserted and session closed successfully", indicating that the BDC session has been created successfully.
Step 15: Go to SM35 and click on Process.
Process the screen recording step by step.
If the screen recording is processed successfully without any errors, all records will be inserted into the database tables as expected.
If any error occurs during the screen processing, the corresponding record will fail to be posted to the database. You can review the error log in SM35, correct the issue and reprocess the failed session.
Step 16: Go to the MARA table using transaction SE11 or SE16N. Enter the material number and execute the database table to verify that the material records have been inserted successfully.
Step 17 : Go to transaction SM36 to schedule the background job
, provide the job name and click on the step tab.
Step 18: Add the Report Program to the Background Job
In the Step screen, enter the name of the report program you created. Then click the Check button to validate the program details that will be executed in the background.
Step 19: Monitor the Background Job
Go to transaction SM37 to monitor the background job. Enter the job name and click 'Execute' to view the job status.
we can see the step list overview here
IF your background job runs successfully, it has shows status should be finished
Verifying Background Job Execution
After the report schedules the background job using JOB_OPEN, SUBMIT RSBDCSUB VIA JOB, and JOB_CLOSE, the execution can be verified using transaction SM37.
1. Background Job Status (SM37)
The first screenshot shows the Job Overview screen in transaction SM37.
What it indicates:
- Job Name: ZBDC_PROCESS_A001
This is the background job created by the report.
- Status: Finished (Green)
Indicates that the background job was completed successfully without any runtime errors.
- Start Date & Start Time
Shows when the background job started execution.
- Duration
Displays the total execution time of the job.
- Spool Icon
Indicates that a spool request was generated. - The spool contains the execution log and output of the background job.
Spool Output:
The second screenshot shows the spool generated after executing the standard program RSBDCSUB.What it indicates
The spool title:
Batch input: Process all sessions still to be processed
This confirms that the standard SAP program 'RSBDCSUB' was executed successfully.
The spool displays details such as the following:
- Session Name
- Processing Date
- Processing Time
- Background Job Number
- Queue ID
For example:
Session: A001
Date: 16.07.2026
Time : 11:48:28
Job No.: 11482800This information confirms that the BDC session A001 was picked up and processed by the background job.
Conclusion:
Automating BDC session processing through background jobs improves efficiency, reduces manual effort and ensures reliable execution of batch data uploads. I hope this blog helps you understand the complete process from session creation to successful background execution.