Page tree
Skip to end of metadata
Go to start of metadata

Here is a program to automate the Background job monitoring

This program needs to be scheduled daily, It monitors all the jobs and intimates the cancelled job owners on their job status.

Program:

 
*&---------------------------------------------------------------------*
*& Report ZBACKGROUNDJOB_MONITOR
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBACKGROUNDJOB_MONITOR.
************************************************************************
*This report used to monitor the background job i.e., when ever the job*
*fails it will trigger to the concerned user *
************************************************************************
*data declarations
TYPES: BEGIN OF TY_TBTCO,
JOBNAME TYPE TBTCO-JOBNAME,
JOBCOUNT TYPE TBTCO-JOBCOUNT,
SDLSTRTDT TYPE TBTCO-SDLSTRTDT,
STATUS TYPE TBTCO-STATUS,
PRIORITY TYPE TBTCO-PRIORITY,
RELUNAME TYPE TBTCO-RELUNAME,
END OF TY_TBTCO. "table that holds details of job that failed
DATA: WA_TBTCO TYPE TY_TBTCO,
IT_TBTCO TYPE TABLE OF TY_TBTCO.
*for retriveing user details.
DATA: WA_ADDRESS TYPE BAPIADSMTP,
IT_ADDRESS TYPE TABLE OF BAPIADSMTP,
WA_RETUNR TYPE BAPIRET2,
IT_RETURN TYPE TABLE OF BAPIRET2.
TYPES: BEGIN OF TY_EMAIL,
USERNAME TYPE TBTCO-RELUNAME,
AD_SMTPADR TYPE BAPIADSMTP-E_MAIL,
END OF TY_EMAIL.
DATA: WA_EMAIL TYPE TY_EMAIL,
IT_EMAIL TYPE TABLE OF TY_EMAIL.
*for sending mail details.
DATA:IT_MAIL_CONTENT TYPE STANDARD TABLE OF SOLISTI1,
WA_IT_MAIL_CONTENT TYPE SOLISTI1,
WA_IT_DOC_DATA TYPE SODOCCHGI1,
IT_RECEIVER TYPE STANDARD TABLE OF SOMLRECI1,
WA_IT_RECEIVER TYPE SOMLRECI1.
 
 
*select query
SELECT JOBNAME JOBCOUNT SDLSTRTDT STATUS PRIORITY RELUNAME FROM TBTCO
INTO TABLE IT_TBTCO
WHERE STATUS = 'A'.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
LOOP AT IT_TBTCO INTO WA_TBTCO.
REFRESH: IT_RETURN,IT_ADDRESS.
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
EXPORTING
USERNAME = WA_TBTCO-RELUNAME
* IMPORTING
* LOGONDATA =
* DEFAULTS =
* ADDRESS =
* COMPANY =
* SNC =
* REF_USER =
* ALIAS =
* UCLASS =
* LASTMODIFIED =
* ISLOCKED =
TABLES
* PARAMETER =
* PROFILES =
* ACTIVITYGROUPS =
RETURN = IT_RETURN
* ADDTEL =
* ADDFAX =
* ADDTTX =
* ADDTLX =
ADDSMTP = IT_ADDRESS
* ADDRML =
* ADDX400 =
* ADDRFC =
* ADDPRT =
* ADDSSF =
* ADDURI =
* ADDPAG =
* ADDCOMREM =
* PARAMETER1 =
* GROUPS =
* UCLASSSYS =
* EXTIDHEAD =
* EXTIDPART =
* SYSTEMS =
.
READ TABLE IT_ADDRESS INDEX 1 INTO WA_ADDRESS.
WA_EMAIL-USERNAME = WA_TBTCO-RELUNAME.
WA_EMAIL-AD_SMTPADR = WA_ADDRESS-E_MAIL.
APPEND WA_EMAIL TO IT_EMAIL.
ENDLOOP.
REFRESH IT_MAIL_CONTENT.
*sending e-mail about job failure to concerned schedulers.
LOOP AT IT_EMAIL INTO WA_EMAIL.
READ TABLE IT_TBTCO WITH KEY RELUNAME = WA_EMAIL-USERNAME INTO WA_TBTCO.
CONCATENATE 'Jobname' WA_TBTCO-JOBNAME 'failed' INTO
WA_IT_MAIL_CONTENT-LINE SEPARATED BY SPACE.
APPEND WA_IT_MAIL_CONTENT TO IT_MAIL_CONTENT.
CLEAR IT_RECEIVER.
MOVE: WA_EMAIL-AD_SMTPADR TO WA_IT_RECEIVER-RECEIVER,
'X' TO WA_IT_RECEIVER-EXPRESS,
'U' TO WA_IT_RECEIVER-REC_TYPE,
'INT' TO WA_IT_RECEIVER-COM_TYPE.
APPEND WA_IT_RECEIVER TO IT_RECEIVER.
MOVE 'SAP PRO Failed job list TODAY' TO WA_IT_DOC_DATA-OBJ_DESCR.
 
 
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = WA_IT_DOC_DATA
PUT_IN_OUTBOX = 'X' "X
COMMIT_WORK = 'X'
TABLES
OBJECT_CONTENT = IT_MAIL_CONTENT
RECEIVERS = IT_RECEIVER
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.
ENDLOOP.
ENDIF.


Hope you enjoy this--Nick Loy