Batch job event triggering

Batch job event triggers can be used in a smart way to trigger a batch job when needed.

Defining the event in SM64

In transaction SM64 you can see the current events and also create a new custom event:

Triggering the event

The event can be triggered from SM64 by selecting the event and pressing the Execute button:

Or you can trigger from an ABAP program with the function module BP_RAISE_EVENT.

FORM RAISE_EVENT. 
  CALL FUNCTION 'BP_EVENT_RAISE' 
    EXPORTING 
      EVENTID = 'ZMYEVENT'  
      EVENTPARM = 'EVENTPARM 'Test'  
      TARGET_INSTANCE = ' ' 
    EXCEPTIONS BAD_EVENTID = 1. 
ENDFORM. " RAISE_EVENT

Or you can trigger from OS level with the sapevt program.

Schedule job with event trigger

Now we will schedule the job in SM36 using a test program ZHELLOEVENT. In the job definition we will run the program ZHELLOEVENT. In the scheduling we will use the start condition After Event:

When you trigger the event now in SM36 you see the job will execute nicely. Go to transaction SM37 and key in the Or after event search option:

You will now find the jobs after the event triggering.

Jobs waiting for a trigger

To find batch jobs that are still waiting for a trigger, use SE11 to see the content of table BTCEVTJOB.

Reorganization of batch jobs events

Settings are done in SM64:

Run background program RSEVTHISTREORG for the clean up.

OSS notes

Relevant OSS notes:

Reading content data from batch job variants

In quite some cases the basis team is asked: in which batch job variant is this company code XXXX used? Or we need to add another sales organization to all the batch jobs, can you provide us a list with jobs using sales organization YYYY?

Some hints are given in this blog.

But no real solution.

Continue reading for a custom code solution!

Custom program to scan batch job variant content

If you load the program in the next section, create texts so that the start screen looks like this:

First test program on small batch of programs with know variants.

Example search all programs starting with ZA for the variant text US:

Result is list of program and variants with the key word:

Custom program coding

*&---------------------------------------------------------------------*
*& Report ZVARSEARCH
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZVARSEARCH.

* _____________________________________________________________________
*|                              T A B L E S                            |
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
TABLES: trdir, tadir.

* _____________________________________________________________________
*|                              T Y P E S                              |
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
TYPES: BEGIN OF ty_source,
         line(255) TYPE c,
       END OF ty_source.

TYPES: BEGIN OF ty_objname,
         obj_name TYPE sobj_name,
       END OF ty_objname.

TYPES: BEGIN OF ty_variant,
         variant TYPE variant,
       END OF ty_variant.

* _____________________________________________________________________
*|              I T A B S  & W O R K A R E A S                         |
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
DATA: gt_selop       TYPE STANDARD TABLE OF    vanz,
      gt_params      TYPE STANDARD TABLE OF    vanz,
      gt_params_nonv TYPE STANDARD TABLE OF    vanz,
      gt_selop_nonv  TYPE STANDARD TABLE OF    vanz,
      gs_vanz        TYPE                      vanz,
      lv_text        TYPE                      string,
      gv_report      TYPE                      vari_reprt,
      mv_report      TYPE                      vari_reprt,
      gt_variant     TYPE STANDARD TABLE OF    ty_variant,
      gs_variant     TYPE                      ty_variant,
      gv_program     TYPE                      syrepid,
      gv_subrc       TYPE                      sysubrc,
      gt_reports     TYPE STANDARD TABLE OF    trdir,
      gs_reports     TYPE                      trdir,
      gt_valuetab    TYPE STANDARD TABLE OF    rsparams,
      gt_objname     TYPE STANDARD TABLE OF    ty_objname.

FIELD-SYMBOLS:
      <fs_vanz>      TYPE vanz.
* _____________________________________________________________________
*|                 S E L E C T I O N - S C R E E N                     |
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
SELECTION-SCREEN BEGIN OF BLOCK aa WITH FRAME.
SELECTION-SCREEN BEGIN OF BLOCK bb WITH FRAME TITLE text-t01.
PARAMETERS:     ra_srch   RADIOBUTTON GROUP a1
                             USER-COMMAND tab1 DEFAULT 'X',
                ra_srch2  RADIOBUTTON GROUP a1,
                ra_wday   RADIOBUTTON GROUP a1,
                ra_synt   RADIOBUTTON GROUP a1,
                ch_all   AS CHECKBOX  MODIF ID a2.
SELECTION-SCREEN END OF BLOCK bb.
SELECT-OPTIONS: so_prog   FOR trdir-name.
PARAMETERS:     p_string  TYPE s_text       MODIF ID a1.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK cc WITH FRAME.
PARAMETERS:     pa_prog   TYPE program,
                pa_local  AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK cc.
SELECTION-SCREEN END OF BLOCK aa.

* _____________________________________________________________________
*|           A T  S E L E C T I O N - S C R E E N  O U T P U T         |
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
AT SELECTION-SCREEN OUTPUT.

  LOOP AT SCREEN.
    CASE screen-group1.
      WHEN 'A1'.

        IF ra_srch  IS INITIAL
        AND ra_srch2 IS INITIAL.
          CLEAR p_string.
          screen-input = '0'.
        ELSE.
          screen-input = '1'.
        ENDIF.
      WHEN 'A2'.
        IF ra_synt = 'X'.
          screen-input = '1'.

        ELSE.
          CLEAR ch_all.
          screen-input = '0'.
        ENDIF.
    ENDCASE.
    MODIFY SCREEN.
  ENDLOOP.

* _____________________________________________________________________
*|                 S T A R T - O F - S E L E C T I O N                 |
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
START-OF-SELECTION.
  IF ( NOT ra_srch  IS INITIAL OR NOT ra_srch2 IS INITIAL )
  AND p_string IS INITIAL.
    MESSAGE e001(00) WITH 'No string entered'.
  ENDIF.

  PERFORM select_programs.
  PERFORM select_variants.

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Form  SELECT_PROGRAMS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM select_programs.

  DATA: lv_tabix   TYPE   sytabix,
        lv_lines   TYPE   i.

*-Only executable programs are taken into account
  IF ch_all IS INITIAL.
    SELECT * FROM trdir
       INTO TABLE gt_reports
         WHERE name IN so_prog
                     AND subc = '1'.

*-For syntax checking you can also include other program types
  ELSE.
    SELECT * FROM trdir
      INTO TABLE gt_reports
        WHERE name IN so_prog.
  ENDIF.

  SORT gt_reports BY name.
  DESCRIBE TABLE gt_reports LINES lv_lines.

*-check if the user wants to start from a certain program
*-(so skip all preceding programs)
  IF NOT pa_prog IS INITIAL.

    READ TABLE gt_reports WITH KEY name = pa_prog
     TRANSPORTING NO FIELDS.
    IF sy-subrc = 0.
      lv_tabix = sy-tabix + 1.
      IF lv_tabix < lv_lines.
*-      Delete all preceding reports including the start from report
        DELETE gt_reports FROM 1 TO lv_tabix.
      ENDIF.
    ENDIF.

  ENDIF.

  IF gt_reports[] IS INITIAL.
    MESSAGE s001(00) WITH 'No reports selected'.
    WRITE:/ 'No reports selected'.
  ENDIF.

ENDFORM.                    " SELECT_PROGRAMS
*&---------------------------------------------------------------------*
*&      Form  SELECT_VARIANTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM select_variants .

  DATA: lt_results     TYPE STANDARD TABLE OF rsvobs,
        lv_found       TYPE                   flag.

  REFRESH gt_objname.

  CHECK NOT gt_reports[] IS INITIAL.

*-retrieve already all details for quicker reading
  IF pa_local = 'X'.                         "Exclude local programs
    SELECT obj_name INTO TABLE gt_objname
      FROM tadir
      FOR ALL ENTRIES IN gt_reports
      WHERE pgmid = 'R3TR'
        AND object = 'PROG'
        AND obj_name = gt_reports-name.
  ELSE.                                      "Include local programs
    SELECT obj_name INTO TABLE gt_objname
      FROM tadir
      FOR ALL ENTRIES IN gt_reports
      WHERE pgmid = 'R3TR'
        AND object = 'PROG'
        AND obj_name = gt_reports-name
        AND devclass <> '$TMP'.
  ENDIF.

  LOOP AT gt_reports INTO gs_reports.

    READ TABLE gt_objname
      WITH KEY obj_name = gs_reports-name
        TRANSPORTING NO FIELDS.
    CHECK sy-subrc = 0.

    gv_program = gv_report = gs_reports-name.

*=====================================================================*
*-  PERFORM A SYNTAX CHECK FOR PROGRAM
*=====================================================================*
*-  Get the source code of the report for syntax checking
    PERFORM program_syntax_check USING    gv_program
                                 CHANGING gv_subrc.

*-  Skip programs with syntax errors for further variant checking
    IF gv_subrc <> 0.
      IF ra_synt = 'X'.
        MESSAGE s000(3w) WITH 'SYNTAX ERROR==>' gv_report.
        WRITE:/      gv_report,
                  50 'CONTAINS SYNTAX ERROR'.
      ELSE.
        CONTINUE.
      ENDIF.
    ENDIF.

*---------------------------------------------------------------------*
*-  Only process variants for select-options search and working days
*---------------------------------------------------------------------*
    CHECK ra_srch = 'X' OR ra_srch2 = 'X' OR ra_wday = 'X'.

*-  Select variants for a program
*-  (exclude the very old ones and also the standard SAP ones)
    SELECT variant INTO TABLE gt_variant
      FROM varid
          WHERE report = gv_report
            AND ( edat > 20100101  OR  aedat > 20100101 )
            AND ( ename <> 'SAP'   AND aename <> 'SAP'  ).

    CHECK NOT gt_variant[] IS INITIAL.
    REFRESH lt_results.

*-  Process all variants
    LOOP AT gt_variant INTO gs_variant.
      CLEAR lv_found.

*-    Give a message to indicate which program/variant is being checked
*-    (comes in handy in case the program cancels during the check as
*-    you can then restart this program starting from the object that
*-    dumped)
      MESSAGE s000(3w) WITH 'Checking' gv_report '-' gs_variant-variant.

      CALL FUNCTION 'RS_VARIANT_CONTENTS'
        EXPORTING
          report                      = gv_report
          variant                     = gs_variant-variant
          no_import                   = ' '
          execute_direct              = ''
        TABLES
          l_params                    = gt_params
          l_params_nonv               = gt_params_nonv
          l_selop                     = gt_selop
          l_selop_nonv                = gt_selop_nonv
          valutab                     = gt_valuetab
       EXCEPTIONS
         variant_non_existent        = 1
         variant_obsolete            = 2
         OTHERS                      = 3.

      CHECK sy-subrc = 0.

*=====================================================================*
*-    SEARCH VARIANTS FOR A CERTAIN FIELD VALUE
      IF ra_srch = 'X'.
*=====================================================================*
        FIND FIRST OCCURRENCE OF p_string
        IN TABLE gt_valuetab
        IN CHARACTER MODE.
        IF sy-subrc = 0.
          CONCATENATE 'String' p_string 'found'
             INTO lv_text SEPARATED BY space.
          MESSAGE s000(3w) WITH 'FOUND:' gv_report
                                gs_variant-variant lv_text.

          WRITE:/   'FOUND:',
                  7 gv_report,
                 50 gs_variant-variant,
                 80 lv_text.
        ENDIF.

*=====================================================================*
*-    SEARCH VARIANTS FOR A CERTAIN FIELD NAME OR FIELD DESCRIPTION
      ELSEIF ra_srch2 = 'X'.
*=====================================================================*
*-      Check select-options field names and descriptions for a
*-      certain string
        LOOP AT gt_selop ASSIGNING <fs_vanz>.
          FIND FIRST OCCURRENCE OF  p_string
          IN <fs_vanz>-name IN CHARACTER MODE.
          IF sy-subrc = 0.
            lv_found ='X'.
            EXIT.
          ENDIF.
        ENDLOOP.

        IF lv_found IS INITIAL.
          LOOP AT gt_selop_nonv ASSIGNING <fs_vanz>.
            FIND FIRST OCCURRENCE OF  p_string
            IN <fs_vanz>-name IN CHARACTER MODE.
            IF sy-subrc = 0.
              lv_found ='X'.
              EXIT.
            ENDIF.
          ENDLOOP.
        ENDIF.

        IF lv_found IS INITIAL.
          LOOP AT gt_params  ASSIGNING <fs_vanz>.
            FIND FIRST OCCURRENCE OF p_string
            IN <fs_vanz>-name IN CHARACTER MODE.

            IF sy-subrc = 0.
              lv_found ='X'.
              EXIT.
            ENDIF.
          ENDLOOP.
        ENDIF.

        IF lv_found IS INITIAL.
          LOOP AT gt_params_nonv  ASSIGNING <fs_vanz>.
            FIND FIRST OCCURRENCE OF p_string
            IN <fs_vanz>-name IN CHARACTER MODE.

            IF sy-subrc = 0.
              lv_found ='X'.
              EXIT.
            ENDIF.
          ENDLOOP.
        ENDIF.

        IF lv_found = 'X'.
          CONCATENATE 'String' p_string 'found'
                      INTO lv_text SEPARATED BY space.
          MESSAGE s000(3w) WITH 'FOUND:' gv_report
                                gs_variant-variant lv_text.
          WRITE:/   'FOUND:',
                  7 gv_report,
                 50 gs_variant-variant,
                 80 lv_text.
        ENDIF.

*=====================================================================*
*-    SEARCH VARIANTS FOR VARIABLES THAT REQUIRE CALENDAR ENTRY
      ELSEIF ra_wday = 'X'.
*=====================================================================*
        LOOP AT gt_selop INTO gs_vanz
             WHERE vname <> ''.
          IF gs_vanz-vname CS 'XWD' OR gs_vanz-vname CS 'WDAY'.
            lv_found ='X'.
            EXIT.
          ENDIF.
        ENDLOOP.
        IF lv_found IS INITIAL.
          LOOP AT gt_selop_nonv INTO gs_vanz
               WHERE vname <> ''.
            IF gs_vanz-vname CS 'XWD' OR gs_vanz-vname CS 'WDAY'.
              lv_found ='X'.
              EXIT.
            ENDIF.
          ENDLOOP.
        ENDIF.
        IF lv_found IS INITIAL.
          LOOP AT gt_params INTO gs_vanz
               WHERE vname <> ''.
            IF gs_vanz-vname CS 'XWD' OR gs_vanz-vname CS 'WDAY'.
              lv_found ='X'.
              EXIT.
            ENDIF.
          ENDLOOP.
        ENDIF.
        IF lv_found IS INITIAL.
          LOOP AT gt_params_nonv INTO gs_vanz
               WHERE vname <> ''.
            IF gs_vanz-vname CS 'XWD' OR gs_vanz-vname CS 'WDAY'.
              lv_found ='X'.
              EXIT.
            ENDIF.
          ENDLOOP.
        ENDIF.

        IF lv_found = 'X'.
          MESSAGE s000(3w) WITH 'FOUND:' gv_report gs_variant-variant
                                'Calendar logic present'.
          WRITE:/   'FOUND:',
                  8 gv_report,
                 50 gs_variant-variant,
                 80 'Calendar logic present'.

        ENDIF.

      ENDIF.

    ENDLOOP.

  ENDLOOP.

ENDFORM.                    " SELECT_VARIANTS
*&---------------------------------------------------------------------*
*&      Form  PROGRAM_SYNTAX_CHECK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LV_SUBRC  text
*----------------------------------------------------------------------*
FORM program_syntax_check   USING    p_program
                            CHANGING p_subrc.

  DATA: lt_source    TYPE STANDARD TABLE OF    ty_source.

  CLEAR p_subrc.
  REFRESH lt_source.

  READ REPORT gv_program INTO lt_source.

  CALL FUNCTION 'RS_SYNTAX_CHECK'
    EXPORTING
      i_program        = p_program
    IMPORTING
      o_error_subrc    = p_subrc
    TABLES
      i_source         = lt_source.

ENDFORM.                    " PROGRAM_SYNTAX_CHECK

Find batch jobs with deleted or locked step users

If a batch job step user is locked or deleted, that step will fail. To find batch jobs with deleted or locked step users, start program BTCAUX09:

This will give a full list of jobs that you might want to start analyzing for deletion:

Why clean up? You will most likely find a lot of jobs in Scheduled status that never ran and are planned very long time ago. All batch job related transactions will have to plough through this irrelevant data.

OSS notes

Notes:

FIORI app for monitoring data archiving jobs

SAP has delivered diverse apps for basis administrators.

This blog will explain about the data archiving batch job monitoring FIORI app.

For generic data archiving technical setup: read this blog.

Activating the app for monitoring data archiving jobs

The full activation manual is published on the FIORI reference library.

Short manual:

  • Activate SICF service bas_ilm_jobmon
  • Activate ODATA service ILM_JOB_MONITOR_SERVICE
  • Manually add the tile in your catalog (use edit home page and than add the app)

Using the app display data archiving jobs

The main FIORI app tile will already show the amount of failed jobs:

When you open the app the overview screen comes:

On the left hand side you can choose the archiving object. On the right hand side you can see the last archiving jobs for the selected object.

When you click on a job, you can see the details per job:

There are tabs for the job results, job log details and application log.

Bug fix notes

Bug fix OSS notes:

Batch job result distribution

When a batch job finishes, there are use cases where you want to be informed on the results.

Questions that will be answered in this blog are:

  • How can I mail the spool result of a batch job?
  • How can I mail if the job went ok or not?

Mailing job status

As of version S4HANA 1709 (basis version 7.52), you can mail the batch job result for cancelled jobs, or in all cases when it finishes. In SM37 after job is planned goto change mode of the job and push the E-mail Notification button:

In case of issues check OSS note 2951767 – E-mail notifications are not sent.

Mailing spool result

For mailing spool results use the Spool List Recipient button:

On older systems there might be a cutoff after 1000 lines in the mail. See OSS note 329537 – Spool cut off at 1000 lines when sent to recipient. In case of issues, you can check OSS note 760838 – Spool lists are not sent and 930570 – Problems with sent OTF documents.

Mailing spool result to multiple mail addresses

In transaction SO15 create a distribution list:

Hit the create button to create a distribution list:

Goto the tab Dist. list content to enter the e-mail addresses:

Save the list.

Now you can go to SM37 and change the job:

In the recipient field hit F4 or the selection button and switch to the distribution list. Search the correct one and press ok:

In case somebody by accident deleted a shared distribution list, check OSS note 2477819 – Distribution Lists have been deleted for recovery options.

Bug fixes

Bug fix OSS notes:

S4HANA standard batch jobs

In S4HANA standard jobs are scheduled in a different way.

This blog will answer the following questions:

  • How to see then new standard jobs via transaction SJOBREPO?
  • Where to find more information on more advanced functions?
  • Which background OSS notes can I read on the S4HANA stand batch job repository?
  • I have done a change to SJOBREPO and it is not visible? (it takes up to 1 hour!)

Viewing the job repository

Start transaction SJOBREPO to view the job repository:

The jobs running are different per release. Check the corresponding note. Example for S4HANA 2020: 2992214 – Jobs in the Technical Job Repository (SJOBREPO) in SAP S/4HANA 2020.

Use transaction SWF_JOBREPO_SLG1 to see logs of potential job issues.

To assign a standard user to job steps use transaction SJOBREPO_STEPUSER to set standard job step user:

See OSS notes

Checking the activation status of SJOBREPO

With program R_JR_UTIL_1 you can check the current status of SJOBREPO or activate it:

See OSS note 2790150 – Automatic Job Scheduling is switched off.

Activation and monitoring

In SJOBREPO, more background information can be found by clicking the button Monitor help:

A very important remark is made here that it can take up to 1 hour before changes to SJOBREPO are visible in the monitoring overview. This is a very annoying feature.

Advanced functions in SJOBREPO

All the advanced configuration functions of the S4HANA job repository can be found as PDF attachment to OSS note 2190119 – Background information about S/4HANA technical job repository.

Activation of server group for technical job repository

Apply OSS note 3057980 – Targetservergroups in SJOBREPO in Release 7.55 to get the function for server groups for the technical job repository.

Scope dependent jobs

In customizing you can activate scope dependent jobs:

See also OSS note 3085988 – Technical job is not getting schedule in S/4HANA SJOBREPO because the job is showing as ‘Not in Scope’.

Background OSS notes

Useful background OSS notes:

Bug fix notes:

Debug batch programs

This blog will explain how to debug a background batch program with real background mode (SY-BATCH is X).

Questions that will be answered are:

  • How to debug a running job?
  • How to debug a completed job?

Starting the debug mode for batch job

First we plan a single run of the batch job. In our example we run program RSWAITSEC which does nothing more than wait.

In SM37 show the job run:

Select the job and in the command line enter the background debug command JDBG:

Now the debugger starts first in the batch job part. Hit F7 a few time (F7 = jump back out of routine) until you reach the real program:

As you can see here the SY-BATCH variable is X, which means you are debugging with real background mode on.

SM50 background debugging

If you want to debug a running job, you have to goto SM50 and select the background process. Then choose the menu option Administration / Program / Debugging. Confirm the prompt:

Wait until the running SQL statement has completed and debug mode will start.

Please be very careful with this kind of debugging in a productive system. If you cancel the debug session there might be a rollback work statement triggered, which can cause database inconsistencies.

Reference notes

573128 – Debugging programs in the background

Batch jobs tips & tricks

This blog will give tips and tricks on batch jobs.

Questions that will be answered are:

  • How to check a job is not running already before starting new one?
  • How to build in a wait step into a batch job?
  • How to set the RV variables automatically in table TVARVC?
  • How to validate that the basic batch job system is working ok?
  • How to analyze the jobs running in my system?
  • How to mass stop and start batch jobs?
  • How to set up batch job interception?
  • How to ignore large spool output of batch jobs?
  • How to see the batch job delay timing?
  • How to plan standard jobs in S4HANA?
  • How do I set up batch job server groups?
  • How can I mail the spool of a batch job?
  • How can I mail if job was successful or not?
  • How to check the consistency of the batch job tables and how to repair?
  • How can I archive a print list?
  • How can I archive a job log?
  • How can I get job statistics?
  • How to read content from batch job variants?
  • How to find batch jobs with deleted or locked step users?
  • How to debug a batch job?
  • How to find who deleted a batch job?
  • How to check in case of batch job delay?
  • How to quickly check health of batch job scheduler?
  • How to trigger batch job event?

SAP FAQ note on background jobs

SAP has FAQ note on background jobs: 3008195 – FAQ: Background Processing BC-CCM-BTC-*.

Prevention of same job still running

If you want to prevent same job from starting, while a previous instance is still running, you need to add program RSBTONEJOB or RSBTONEJOB2 as first step in the batch job. This step will detect if the previous instance is still running and abort to avoid the next steps from being executed. More background in OSS note 557610. The scope of both programs is in principle limited to be used for idocs and CUA. To extend the scope or in case of issues, read the instructions in note 3225033 – Behavior of program RSBTONEJOB, RSBTONEJOB2 not as expected.

Forcing a batch program to wait

If for some reason you need a batch program to wait between steps, you can use program RSWAITSEC as a step. This program will only do a wait for x amount of seconds.

Setting current date in the TVARVC table for the RV variables

The RV variables for current date, month and year are often used in month end closing batch jobs. Running program RVSETDAT will set the current dates for RV TVARC variables.

Checking basis background job system settings and working

If you want to validate if the background job system function itself is working properly, start transaction SM65 background processing analysis tool.

SM65 start screen

Result is shown correct working, number of batches and wait time:

SM65 result screen

Bug fixes for SM65:

Background job analysis tool

Start transaction ST13 and start tool BACKGROUND_JOB_ANALYSIS. Or directly start program /SSA/BTC.

Batch job analysis tool

Pending on your selection you get a graphical overview or a full list for you to speed up your analysis.

Mass stop and start of batch jobs

Also check this note for clean up of BTCDELAY table: 3222291 – Superfluos Entries in BTCDELAY Table.

In some cases you might want to find out who manually deleted a batch job.

Unfortunately you first need to activate the logging via program BTCAUX06:

To view job deletions you need to go to transaction SM51, menu option Goto, Trace, Instance Trace, Search Trace. Then look for pattern BP_JOB_DELETE.

More information in OSS note 850885 – Logging the deletion of jobs and 3325374 – How to log job deleted in Background Processing.

A batch job is not started immediately, but with a delay. This delay is set via RZ11 parameter rdisp/btctime and default setting is 60 seconds. More information can be found in OSS note 923228 – Background job scheduler: Use of processes that have become free.

See new note 3236046 – Test report for immediate start for program BTCAUX25 that will test immediate start.

Standard batch jobs in S4HANA

Standard batch jobs in S4HANA are planned via transaction SJOBREPO. For more details read the dedicated blog.

Batch job server groups

If you have a large production system with many application servers you can setup batch job server groups to have batch jobs run on a set of dedicated application servers. To set up batch job server groups start transaction SM61 and click the button Job server groups:

Job server groups

Here you can define the job server group and assign application servers to them. Background is in OSS note 612838 – Administration of job server groups.

job statistics

This gives statistical output:

Job statistics output

Batch jobs with deleted or locked step users

If a batch job step user is locked or deleted, that step will fail. To find such batch jobs, follow the steps as described in this blog.

Batch job delay

Batch job delay can be set with parameter rdisp/btctime. Default is 60 seconds.

See also OSS notes 3080021 – Jobs are started with delay and 3148846 – Background Jobs with status “No free batch work processes available”.

And these notes:

3275278 – Background jobs are started with delay / 3355049 – Correction for Note 3275278.

How to read content from batch job variants

In quite some cases the basis team is asked: in which batch job variant is this company code XXXX used? Or we need to add another sales organization to all the batch jobs, can you provide us a list with jobs using sales organization YYYY? How to get this data is answered in this dedicated blog.

How to check health of batch job scheduler

Start transaction SM61. Now select the Time-Driven scheduler. Select the server and choose the health check tab. Now press the check button:

Batch job event triggers

Batch jobs can also be triggered using events. Read more in this blog on batch job event triggers.

Batch job monitoring

Batch job monitoring can be done with SAP Focused Run. Read more in this blog.

Background OSS notes

3008195 – FAQ: Background Processing BC-CCM-BTC-*

SAP batch job interception

This blog will explain how to setup SAP batch job interception.

Questions that will be answered in this blog are:

  • How to activate SAP batch job interception?
  • How does an intercepted job look like?

Activating SAP batch job interception

Before you can begin the setup of the batch job interception you must run program INITXBP2 in SE38:

Program INITXBP2

Next you have to start transaction CRIT and create the profiles.

Transaction CRIT to manage job interception criteria

First create the default SAP profile by clicking on the SAP logo. Activate it. Next step is to create the profile in which you want to do the interception. In the screen above click on the create profile button. Now enter a criteria. For simplicity we have called it interception. In our case we intercept all except a list of authorized users. In the user list we include the basis users and the background users (in this example WF-BATCH). Save the data.

Next step is to activate this profile:

Activate interception proflie

Working of interception

When a batch job is planned the interception checks if the job should be intercepted or not. As a test logon as end user and launch a job. In our case the user ENDUSER tries to launch a job from SLG2 transaction to delete application logs. This jobs is intercepted and shows like this in SM37:

Intercepted job

The job does not start immediately, but shows in intercepted state. If user with release rights now goes to SM37 for this job, he can release the intercepted job.

Stop and start batch jobs for maintenance

This blog explains how to mass stop and mass start batch jobs as admin. This especially useful putting the SAP system in maintenance mode. Maintenance mode can be needed for upgrade, support package patching or data conversion.

Questions that will be answered are:

  • How to mass stop batch jobs?
  • Can I plan new jobs I need during the suspend mode?
  • How to mass start batch jobs again?

More batch jobs tips and tricks in this blog.

Stopping all batch jobs for maintenance mode

Stop all batch jobs: start transaction SE38 and start program BTCTRNS1.

BTCTRNS1 output

All currently planned jobs will be put into a Released/Suspended mode:

Batch jobs suspended mode

This means the already planned jobs (periodically or not) will not be started.

During this suspend mode new jobs can be planned by admin. These new jobs will be executed.

Starting all batch jobs after end of maintenance

Start all batch jobs again: start transaction SE38 and start program BTCTRNS2.

BTCTRNS2 output

Background

For more background information read OSS note 79424 – How do BTCTRNS1 / BTCTRNS2 work?.