FM to create background job


FM to create a background job:

Imports:

 

imports

Result:

result

Source Code:

FUNCTION ZTB_CREATE_JOB.

*”———————————————————————-

*”*”Local Interface:

*”  IMPORTING

*”     REFERENCE(I_JOBNAME) TYPE  STRING

*”     REFERENCE(I_REPORT) TYPE  STRING

*”     REFERENCE(I_VARIANT) TYPE  STRING OPTIONAL

*”     REFERENCE(I_UNAME) TYPE  STRING OPTIONAL

*”  EXPORTING

*”     REFERENCE(E_RETURN) TYPE  BAPIRET2

*”———————————————————————-

data:

lv_jobname  like tbtcjobjobname,

lv_report   like syrepid,

lv_variant  like raldbvariant,

lv_uname    like syuname,

lv_jobcount like tbtcjobjobcount,

lv_released type c.

lv_jobname i_jobname.

lv_report  i_report.

lv_variant i_variant.

lv_uname   i_uname.

if lv_uname is initial.

   lv_uname syuname.

endif.

* Step 1

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 sysubrc <> 0.

   e_returntype ‘E’.

   e_returnmessage ‘Error!’.

   exit.

endif.

* Step 2

call function ‘JOB_SUBMIT’

  exporting

    authcknam              lv_uname

    jobcount               lv_jobcount

    jobname                lv_jobname

    report                 lv_report

    variant                lv_variant

 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          .

if sysubrc <> 0.

   e_returntype ‘E’.

   e_returnmessage ‘Error!’.

   exit.

endif.

* Step 3

call function ‘JOB_CLOSE’

  exporting

    jobcount            lv_jobcount

    jobname             lv_jobname

    strtimmed           ‘X’

 importing

   job_was_released     lv_released

 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.

if sysubrc <> 0.

   e_returntype ‘E’.

   e_returnmessage ‘Error!’.

   exit.

endif.

ENDFUNCTION.

Leave a comment

Your email address will not be published. Required fields are marked *