Scheduling a background job through programming (Using Function Modules )

 

  • Till now, we were scheduling our background job through SM36 transaction code.
  • Now, We want to schedule our background job through coding.
  • SAP has given use various function modules which we can use for scheduling a background job through programming.

Various function modules which can be used for scheduling a job :-

1. JOB_OPEN :-

  • This function module is used to create a background job.

2. JOB_SUBMIT / SUBMIT :-

  • The function module JOB_SUBMIT or ABAP statement SUBMIT adds a step to the background job.

3. JOB_CLOSE :-

  • This function module process the background job.

Implementation :-

  • Step 1 :- Create a executable program in ABAP Editor ( SE38) .

  • Step 2 :- Call the function module JOB_OPEN to create a background job.

    • In this function module we will pass the job name and job class for our job and it will return the job count for our job which we will use later in add step purpose.


  • Step 3 :- the next step for the job scheduling was to add program name and variant, so we will use JOB_SUBMIT function module for the same purpose.



  • Now, If I execute this program my job will went to schedule status.

  • So, we need to give start condition and for that purpose, we will use JOB_CLOSE function module.




Code :-

*&---------------------------------------------------------------------*
*& Report ZAR_JOB_SCHEDULING
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZAR_JOB_SCHEDULING.

DATA : lv_jobcount type BTCJOBCNT.

CALL FUNCTION 'JOB_OPEN'
  EXPORTING
*   DELANFREP              = ' '
*   JOBGROUP               = ' '
    jobname                = 'AR_BACKGROUNDJOB_11'
*   SDLSTRTDT              = NO_DATE
*   SDLSTRTTM              = NO_TIME
   JOBCLASS               = 'A'
*   CHECK_JOBCLASS         =
 IMPORTING
   JOBCOUNT               = lv_jobcount
*   INFO                   =
* CHANGING
*   RET                    =
 EXCEPTIONS
   CANT_CREATE_JOB        = 1
   INVALID_JOB_DATA       = 2
   JOBNAME_MISSING        = 3
   OTHERS                 = 4
          .

CALL FUNCTION 'JOB_SUBMIT'
  EXPORTING
*   ARCPARAMS                         =
    authcknam                         = 'S419AH02'
*   OPERATINGSYSTEM                   = ' '
    jobcount                          = lv_jobcount
    jobname                           = 'AR_BACKGROUNDJOB_11'
*   LANGUAGE                          = SY-LANGU
*   PRIPARAMS                         = ' '
   REPORT                            = 'ZAR_TRAFFIC_LIGHTS'
   VARIANT                           = 'INPUT1TO10'
* IMPORTING
*   STEP_NUMBER                       =
 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
          .

CALL FUNCTION 'JOB_CLOSE'
  EXPORTING
    jobcount                          = lv_jobcount
    jobname                           = 'AR_BACKGROUNDJOB_11'
*   LASTSTRTDT                        = NO_DATE
*   LASTSTRTTM                        = NO_TIME
*   SDLSTRTDT                         = NO_DATE
*   SDLSTRTTM                         = NO_TIME
*   STARTDATE_RESTRICTION             = BTC_PROCESS_ALWAYS
   STRTIMMED                         = 'X'
*   TARGETSYSTEM                      = ' '
*   START_ON_WORKDAY_NOT_BEFORE       = SY-DATUM
*   START_ON_WORKDAY_NR               = 0
*   WORKDAY_COUNT_DIRECTION           = 0
*   RECIPIENT_OBJ                     =
*   TARGETSERVER                      = ' '
*   DONT_RELEASE                      = ' '
*   TARGETGROUP                       = ' '
*   DIRECT_START                      =
*   INHERIT_RECIPIENT                 =
*   INHERIT_TARGET                    =
*   REGISTER_CHILD                    = ABAP_FALSE
*   TIME_ZONE                         =
*   EMAIL_NOTIFICATION                =
* 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
   INVALID_TIME_ZONE                 = 9
   OTHERS                            = 10
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

Check Status in SM37 :-



Comments

Popular posts from this blog

Understanding Different Types of SAP Function Modules: Normal, RFC, and Update

Unlocking SAP ABAP Secrets: Interactive Classical Reports with GET CURSOR, At User Command, and a Comparison of HIDE Statements

Mastering ABAP: A Step-by-Step Guide to Function Modules and Groups for Modularized Programming