BDC Session – Automatic Execution from Report

17
1469

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.

17 COMMENTS

  1. 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!

  2. Very good to read this blog…This is very helpful for me…Pls don’t stop this..We are waiting more articles from you…:-)

  3. Hi there would you mind sharing which blog platform you’re using? I’m looking to start my own blog in the near
    future but I’m having a difficult time choosing between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something unique.

    P.S My apologies for being off-topic but I had
    to ask!

  4. I’m no longer sure the place you’re getting your information, however good topic.
    I must spend a while studying much more or figuring out more.
    Thanks for great info I used to be in search of this info for my mission.

LEAVE A REPLY

Please enter your comment!
Please enter your name here