BDC Session – Automatic Execution from Report

When 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.

SM35

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:

  1. Pretty Report Vs Pretty Printer in ABAP
  2. Display a Popup and Get Values from User
  3. Convert Spool Request to PDF in SAP
  4. ABAP Program to Display SE78 pictures on Screen
  5. MM02 BDC – Select Specific Material Master View

8 Responses to “BDC Session – Automatic Execution from Report”
Randy Pena Posted on June 20, 2010 at 7:31 PM

I finally decided to write a comment on your blog. I just wanted to say good job. I really enjoy reading your posts.

Darryl Coleman Posted on June 20, 2010 at 7:31 PM

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 [...]

Wordpress Themes Posted on June 30, 2010 at 6:03 PM

Genial brief and this enter helped me alot in my college assignement. Say thank you you seeking your information.

ultrasound technician Posted on July 14, 2010 at 6:10 AM

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!

coollabanana Posted on July 22, 2010 at 2:31 AM

it was very interesting to read.
I want to quote your post in my blog. It can?
And you et an account on Twitter?

Shakthi Posted on September 2, 2011 at 6:29 PM

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