Thursday, December 17, 2009

Scheduling Background Job At Runtime - ABAP

data : gv_job_name type btcjob ,
         gv_jobcount type btcjobcnt,
         gv_variant type rsvar-variant.
constants : gc_bg_repid type sy-repid value 'ZZZZ_PROGRAM_NAME'.
data : gv_step like tbtcjob-stepcount.

*** Simply we initiate the operation
gv_job_name = 'NAMEOFJOB'.
call function 'JOB_OPEN'
exporting
jobname = gv_job_name
importing
jobcount = gv_jobcount
exceptions
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
others = 4.


*** Submit the report and needed variant name
gv_variant = 'VARIANT111'.
call function 'JOB_SUBMIT'
exporting
authcknam = sy-uname
jobcount = gv_jobcount
jobname = gv_job_name
report = gc_bg_repid
variant = gv_variant
importing
step_number = gv_step
exceptions
bad_priparams = 1
bad_xpgflags = 2
invalid_jobdata = 3
jobname_missing = 4
job_notex = 5
job_submit_failed = 6
lock_failed = 7
program_missing = 8
prog_abap_and_extpg_set = 9
others = 10.
*** here gv_step equals to 1 as a first step
*** You can multiple steps by using the job_submit function

*** Use Another variant or report for the second step
gv_variant = 'VARIANT222'.

call function 'JOB_SUBMIT'
exporting
authcknam = sy-uname
jobcount = gv_jobcount
jobname = gv_job_name
report = gc_bg_repid
variant = gv_variant
importing
step_number = gv_step
exceptions
bad_priparams = 1
bad_xpgflags = 2
invalid_jobdata = 3
jobname_missing = 4
job_notex = 5
job_submit_failed = 6
lock_failed = 7
program_missing = 8
prog_abap_and_extpg_set = 9
others = 10.

*** here gv_step equals to 2 as a second step
*** Finally release the job.

*** According to your scheduling options lots of input

*** parameters exist inside the function
*** You've got your job number

call function 'JOB_CLOSE'
exporting
jobcount = gv_jobcount
jobname = gv_job_name
strtimmed = 'X'
* IMPORTING
* JOB_WAS_RELEASED =
* CHANGING
* RET =
exceptions
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
invalid_target = 8
others = 9.

No comments:

Post a Comment