BDC Session – Automatic Execution from Report
Posted by Admin, under ABAP, BDC / LSMW, Function Modules, Quick Reference, Sample Code, TutorialWhen to Use:
Upload programs where you use BDC session method to create Sessions, which should later be executed using transaction SM35.
Requirements before you start:
You need to know the BDC Session name, which is usually an input parameter or is generated by the report programs.
Steps to execute BDC Session from the program:
Step 1: Get BDC Queue ID
CALL FUNCTION ‘BDC_OBJECT_SELECT’
EXPORTING
name = session name
session_creator = sy-uname
datatype = ‘BDC’
client = sy-mandt
qstate = ‘ ‘
date_from = sy-datum
date_to = sy-datum
TABLES
apqitab = itab_apqi
EXCEPTIONS
OTHERS = 1.
Queue ID (QID) = itab_apqi-qid
Step 2: Get Session Info
Get Session info for the queue ID from table APQI.
SELECT SINGLE * FROM apqi INTO session WHERE qid = QID (from Step 1).
Step3: Lock BDC Queue
CALL FUNCTION ‘ENQUEUE_BDC_QID’
EXPORTING
datatyp = session-datatyp
groupid = session-groupid
qid = session-qid
EXCEPTIONS
foreign_lock = 1
system_failure = 99.
Step4: OPEN JOB
DATA: jobname LIKE tbtco-jobname,
jobnumb LIKE rsjobinfo-jobnumb,
Jobname = wa_session-groupid.
CALL FUNCTION ‘JOB_OPEN’
EXPORTING
jobgroup = ‘BATCH-INPUT’
jobname = jobname
sdlstrtdt = sy-datum
sdlstrttm = sy-uzeit
IMPORTING
jobcount = jobnumb
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 99.
Step5: Execute the Queue
Execute the QUEUE using Submit to Report RSBDCBTC.
SUBMIT rsbdcbtc
TO SAP-SPOOL
DESTINATION space
IMMEDIATELY space
KEEP IN SPOOL space
WITHOUT SPOOL DYNPRO
USER session-userid
VIA JOB jobname
NUMBER jobnumb
WITH queue_id EQ wa_session-qid
WITH mappe EQ jobname
WITH modus EQ ‘N’
WITH logall EQ ‘X’ ” Extended Log
AND RETURN.
If Sy-subrc = 0
Step6: Close Job
CALL FUNCTION ‘JOB_CLOSE’
EXPORTING
jobcount = jobnumb
jobname = jobname
strtimmed = ‘X’
targetsystem = ” ” Target Host
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 = 99.
IF sy-subrc = 0
Step 7: Update Session info
UPDATE apqi SET qstate = ‘S’
WHERE destsys = wa_session-destsys
AND destapp = wa_session-destapp
AND datatyp = wa_session-datatyp
AND groupid = wa_session-groupid
AND progid = wa_session-progid
AND formid = wa_session-formid
AND qattrib = wa_session-qattrib
AND qid = wa_session-qid.
COMMIT WORK.
Step 8: Delete Job
If Job Not closed (Sy-subrc <> 0 for step 5 or 6), delete Job.
CALL FUNCTION ‘BP_JOB_DELETE’
EXPORTING
jobname = jobname
jobcount = jobnumb
forcedmode = ‘X’
EXCEPTIONS
OTHERS = 99.
Step 9: Unlock BDC queue
CALL FUNCTION ‘DEQUEUE_BDC_QID’
EXPORTING
datatyp = wa_session-datatyp
groupid = wa_session-groupid
qid = wa_session-qid.
So you are all done. Hope that was simple.
You might also be interested in these posts:


I finally decided to write a comment on your blog. I just wanted to say good job. I really enjoy reading your posts.
I found your site on Google and read a few of your other entires. Nice Stuff. I’m looking forward to reading more from you.
[...] BDC Session – Automatic Execution from Report | ABAP Tutorials [...]
[...] BDC Session – Automatic Execution from Report | ABAP Tutorials [...]
Genial brief and this enter helped me alot in my college assignement. Say thank you you seeking your information.
Pretty nice post. I just stumbled upon your blog and wanted to say that I have really enjoyed browsing your blog posts. In any case I’ll be subscribing to your feed and I hope you write again soon!
it was very interesting to read.
I want to quote your post in my blog. It can?
And you et an account on Twitter?
Very good to read this blog…This is very helpful for me…Pls don’t stop this..We are waiting more articles from you…:-)
Post a Comment