Skip to Content

Follow these easy steps to get status of (long running) background job(s) on your iPhone (inbox).

Mon 03.pngMon 02.png

Steps

  1. Create ABAP Program to Send out Job Status via email
  2. Create & schedule a periodic process chain
  3. Change process chain variant to point to a background job

Step 1.

Copy paste the code to create an ABAP program in SE38.

Code

*&———————————————————————*

*& Report  Z_BW_JOB_MONITOR_V2

*&

*&———————————————————————*

*&

*&

*&——————————————————————–&*

*& ABAP Name   : Z_BW_PROCESS_CHECK                                   &*

*& Changed By  : Rahul R Nair                                         &*

*& Created On  : 08/10/2011                                           &*

*& Version     : 1.0                                                  &*

*& Description : This program can be used to monitor jobs displayed   &*

*&               in sm 37. Program variants can be set up to send     &*

*&               email notification when a job fails/completes.       &*

*&               It can also be used to send notication independt of  &*

*&               current status of job.                               &*

*&                                                                    &*

*&               Steps :                                              &*

*&               1.Enter job name(s) ; job id(s) along with the email&*

*&                 addresses and save it as a program variant.        &*

*&               2.Create a process chain containing program and      &*

*&                 the variant.                                       &*

*&               3.Make PC to run every 15 mins with start type as    &*

*&                 ‘Direct scheduling’ with a priodic value (15 min)  &*

*&               4.Excute the PC. PC will execute every 15 min and    &*

*&                 send mail when job completes/errors                &*

*&                                                                    &*

*&               NOTE :                                               &*

*&               To stop scheduling, change start variant to          &*

*&               immediate and uncheck periodic checkbox. Save and    &*

*&               reactivte PC. Execute once to stop cyclic trigger.   &*

*&———————————————————————*

REPORT  Z_BW_JOB_MONITOR_V2.

*$***********************************************************************

*$*$  TABLES

*$*$*********************************************************************

TABLES :

   TBTCO.

*$***********************************************************************

*$*$  DATA DECLARATION

*$*$*********************************************************************

DATA :

   JOB_CNT(50) TYPE    C,

   EMAIL(100TYPE    C.

DATA :

   IT_TBTCO    TYPE STANDARD TABLE OF  TBTCO,

   WA_TBTCO    TYPE                    TBTCO,

   IT_JOBSTAT  TYPE STANDARD TABLE OF  TBTCO,

   WA_JOBSTAT  TYPE                    TBTCO.

TYPES :

   BEGIN OF TY_JOB_CNT,

     JOBNAME   TYPE TBTCOJOBNAME,

     JOBCOUNT  TYPE TBTCOJOBCOUNT,

   END   OF TY_JOB_CNT.

DATA :

   IT_JOB_CNT  TYPE STANDARD TABLE OF  TY_JOB_CNT,

   WA_JOB_CNT  TYPE                    TY_JOB_CNT.

DATA :

   LV_JOBNAME  TYPE C LENGTH 50,

   LV_JOBCOUNT TYPE C LENGTH 50,

   LV_ERR_MSG  TYPE STRING,

   LV_JOBSTAT  TYPE STRING.

DATA :

   WA_DATA     type                    sodocchgi1,

   IT_TXT      type table of           solisti1    with header line,

   IT_REC      type table of           somlrec90   with header line.

*$***********************************************************************

*$*$  SELECTION SCREENS

*$*$*********************************************************************

SELECTION-SCREEN BEGIN OF BLOCK SB1 WITH FRAME TITLE TEXTT01.

SELECT-OPTIONS :

   SO_JOB1     FOR     (JOB_CNT) NO INTERVALS.

SELECTION-SCREEN END   OF BLOCK SB1.

SELECTION-SCREEN BEGIN OF BLOCK SB2 WITH FRAME TITLE TEXTT02.

   SELECTION-SCREEN COMMENT /1(50) TEXTT03.

   SELECTION-SCREEN COMMENT /1(50) TEXTT04.

   SELECTION-SCREEN COMMENT /1(70) TEXTT05.

SELECTION-SCREEN END   OF BLOCK SB2.

SELECTION-SCREEN BEGIN OF BLOCK SB3 WITH FRAME TITLE TEXTT31.

SELECT-OPTIONS :

   SO_MAIL     FOR     (EMAIL) NO INTERVALS.

PARAMETERS  :

   CH_STAT     TYPE    C DEFAULT ‘X’ AS CHECKBOX.

SELECTION-SCREEN END   OF BLOCK SB3.

*$***********************************************************************

*$*$  SELECTION SCREEN HOW TO

*$*$*********************************************************************

SELECTION-SCREEN : BEGIN OF BLOCK SB4 WITH FRAME TITLE TEXTT40.

   SELECTION-SCREEN COMMENT /1(79) TEXTT41.

   SELECTION-SCREEN COMMENT /1(79) TEXTT42.

   SELECTION-SCREEN COMMENT /1(79) TEXTT43.

   SELECTION-SCREEN COMMENT /1(79) TEXTT44.

   SELECTION-SCREEN COMMENT /1(79) TEXTT45.

   SELECTION-SCREEN COMMENT /1(79) TEXTT46.

   SELECTION-SCREEN COMMENT /1(79) TEXTT47.

   SELECTION-SCREEN COMMENT /1(79) TEXTT48.

   SELECTION-SCREEN COMMENT /1(79) TEXTT49.

   SELECTION-SCREEN COMMENT /1(79) TEXTT50.

   SELECTION-SCREEN COMMENT /1(79) TEXTT51.

   SELECTION-SCREEN COMMENT /1(79) TEXTT52.

   SELECTION-SCREEN COMMENT /1(79) TEXTT53.

   SELECTION-SCREEN COMMENT /1(79) TEXTT54.

   SELECTION-SCREEN COMMENT /1(79) TEXTT55.

   SELECTION-SCREEN COMMENT /1(79) TEXTT56.

   SELECTION-SCREEN COMMENT /1(79) TEXTT57.

   SELECTION-SCREEN COMMENT /1(79) TEXTT58.

   SELECTION-SCREEN COMMENT /1(79) TEXTT59.

   SELECTION-SCREEN COMMENT /1(79) TEXTT60.

SELECTION-SCREEN END OF BLOCK SB4 .

*$***********************************************************************

*$*$  DATA PROCESSING

*$*$*********************************************************************

LOOP AT SO_JOB1.

   CONDENSE SO_JOB1LOW.

   CLEAR :

     WA_JOB_CNT,

     LV_JOBNAME,

     LV_JOBCOUNT.

   SPLIT SO_JOB1LOW

     AT ‘;’

     INTO  LV_JOBNAME

           LV_JOBCOUNT.

   CONDENSE :

     LV_JOBNAME,

     LV_JOBCOUNT.

   WA_JOB_CNTJOBNAME  = LV_JOBNAME.

   WA_JOB_CNTJOBCOUNT = LV_JOBCOUNT.

   APPEND WA_JOB_CNT

     TO   IT_JOB_CNT.

ENDLOOP.

IF IT_JOB_CNT[] IS NOT INITIAL.

   SELECT *

     FROM TBTCO

     INTO TABLE IT_TBTCO

     FOR ALL ENTRIES IN IT_JOB_CNT

     WHERE JOBNAME   EQ IT_JOB_CNTJOBNAME

      AND  JOBCOUNT  EQ IT_JOB_CNTJOBCOUNT.

   SORT IT_TBTCO

     BY  JOBNAME   ASCENDING

         JOBCOUNT  ASCENDING.

   DELETE ADJACENT DUPLICATES

     FROM IT_TBTCO

     COMPARING JOBNAME

               JOBCOUNT.

ENDIF.

LOOP AT IT_TBTCO INTO WA_TBTCO.

   IF CH_STAT EQ ‘X’.

     “Send Mails only When

     “1. Job is cancelled

     “2. Job is finished

     IF WA_TBTCOSTATUS EQ ‘A’ “Cancelled

       OR WA_TBTCOSTATUS EQ ‘F’. “Finished

       “‘R’ – Active

       APPEND WA_TBTCO TO IT_JOBSTAT.

     ENDIF.

   ELSE.

     “Send Status email independent of Job Status

     APPEND WA_TBTCO TO IT_JOBSTAT.

   ENDIF.

ENDLOOP.

IF IT_JOBSTAT[] IS NOT INITIAL

   AND SO_MAIL IS NOT INITIAL.

   “Send email

   WA_DATAobj_name  = ‘Job Monitor Log’.

   WA_DATAobj_descr = ‘Job Monitor Log’.

   WA_DATAobj_langu = sylangu.

   “Body of email based on job Status

   LOOP AT IT_JOBSTAT INTO WA_JOBSTAT.

     CLEAR LV_JOBSTAT.

     IF WA_JOBSTATSTATUS EQ ‘A’.

       LV_JOBSTAT = ‘JOB CANCELLED : ‘.

     ELSEIF WA_JOBSTATSTATUS EQ ‘F’.

       LV_JOBSTAT = ‘JOB FINISHED : ‘.

     ELSEIF WA_JOBSTATSTATUS EQ ‘R’.

       LV_JOBSTAT = ‘JOB ACTIVE : ‘.

     ELSE.

       LV_JOBSTAT = ‘JOB STATUS UNKNOWN : ‘.

     ENDIF.

     CLEAR LV_ERR_MSG.

     CONCATENATE LV_JOBSTAT

                 ‘Job name :  ‘

                 WA_JOBSTATJOBNAME

                 ‘- Job id : ‘

                 WA_JOBSTATJOBCOUNT

                 ‘- Status : ‘

                 WA_JOBSTATSTATUS

            INTO LV_ERR_MSG.

     WRITE : / LV_ERR_MSG.

     MESSAGE LV_ERR_MSG TYPE ‘S’. “S Status Message, E Error Message

     IT_TXTline = LV_ERR_MSG.

     append IT_TXT.

   ENDLOOP.

   “Email recepients

   LOOP AT SO_MAIL.

     IT_RECreceiver = SO_MAILLOW.

     IT_RECrec_type = ‘U’.

     append IT_REC.

     CLEAR LV_ERR_MSG.

     CONCATENATE ‘Sending mail to : ‘

                 IT_RECreceiver

            INTO LV_ERR_MSG.

     WRITE : / LV_ERR_MSG.

     MESSAGE LV_ERR_MSG TYPE ‘S’. “S Status Message, E Error Message

   ENDLOOP.

   call function ‘SO_NEW_DOCUMENT_SEND_API1’

     exporting

       document_data   = WA_DATA

       document_type   = ‘RAW’

       put_in_outbox   = ‘X’

     tables

       object_header   = IT_TXT

       object_content  = IT_TXT

       receivers       = IT_REC

     exceptions

       too_many_receivers          = 1

       document_not_sent           = 2

       document_type_not_exist     = 3

       operation_no_authorization  = 4

       parameter_error             = 5

       x_error                     = 6

       enqueue_error               = 7

       others                      = 8

       .

   if sysubrc = 0.

     COMMIT WORK.

*   Push mail out from SAP outbox

     SUBMIT RSCONN01 WITH MODE = ‘INT’ AND RETURN.

     CLEAR LV_ERR_MSG.

     CONCATENATE ‘Emails Sent ‘

                 ‘ ‘

            INTO LV_ERR_MSG.

     WRITE : / LV_ERR_MSG.

     MESSAGE LV_ERR_MSG TYPE ‘S’. “S Status Message, E Error Message

   else.

     CLEAR LV_ERR_MSG.

     CONCATENATE ‘Error Sending mails.’

                 ‘ ‘

            INTO LV_ERR_MSG.

     WRITE : / LV_ERR_MSG.

     MESSAGE LV_ERR_MSG TYPE ‘S’. “S Status Message, E Error Message

   endif.

ENDIF.

Text Elements

Selection Text:

Name Text
CH_STAT Mail only when Job Finish/Err
SO_JOB1 Job name & id :
SO_MAIL Email IDs

Text Symbols:

T01 Job
T02 Help
T03 Enter Job name and Job id seperated by ‘;’.
T04 e.g. BIDTPR_3010457_1 ; 15472500
T05 Job name & id can be found at the top of Job Log in SM37.
T31 Email Options
T40 How to
T41 This program can be used to monitor jobs displayed
T42 in sm 37. Program variants can be set up to send
T43 email notification when a job fails/completes.
T44 It can also be used to send notication independt of
T45 current status of job.
T46
T47 Steps :
T48 1.Enter job name(s) ; job id(s) along with the email
T49   addresses and save it as a program variant.
T50 2.Create a process chain containing program and
T51   the variant.
T52 3.Make PC to run every 15 mins with start type as
T53   ‘Direct scheduling’ with a priodic value (15 min)
T54 4.Excute the PC. PC will execute every 15 min and
T55   send mail when job completes/errors
T56
T57 NOTE :
T58 To stop scheduling, change start variant to
T59 immediate and uncheck periodic checkbox. Save and
T60 reactivte PC. Execute once to stop cyclic trigger.

User Interface:

Program.jpg

Step 2

a. Create a process chain

Job Mon - PROG VAR.jpg

Job Mon - PROG VAR.jpg

b. Schedule the process chain

Sch PC 01.jpg

Step 3

Get details of background job(s) to be monitored.

Option A

Start sending job status when job is complete/cancelled.

Select Job

Job Finish - sm37.jpg

Get details

Job Finish - sm37 detail.jpg

Update details in PC

Job Finish - pc.jpg

Job Finish - pc variant.jpg

Job Finish - pc variant.jpg

Job Finish - process chain completion.jpg

Email notification on your iPhone

Fin 01.png

Job details

Fin 02.png

Option B

Send current job status.

Select Job & get details

Job Mon - sm37 detail.jpg

Update details in PC

Job Mon - pc.jpg

Job Mon - pc variant.jpg

Job Mon - PROG VAR.jpg

Job Mon - process chain completion.jpg

Email notification on your iPhone

Status emails every 15 mins.

Mon 01.png

Job details

Mon 02.png

Change in job status
Mon 03.png

Assumptions:

  1. The developer has intermediate level knowledge of BW process chains & ABAP programming.
  2. The SAP server is connected to the company’s SMTP (email) server.
  3. The iphone is configured to the company’s email server.

Help

Reach out to a BW developer for any process chain related queries, ABAP developer for program queries, Basis for SMTP queries, Company’s infrastructure team for connectivity with iphone.

Note:

The idea behind making the title “catchy” was to get a developer’s attention and prove how effective this simple tool can be.

Acknowledgement

This program is dedicated to Ramji, Ravi, Anuj, Tilak, Karthik, Ram, Prakash, Priya, Twinkle, Greg, Justin, Donna and all my wonderful team mates.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply