IBM Support

Monitoring BATCH Jobs' Messages from Your E-Mail or Your Message Queue

Troubleshooting


Problem

This document explains how to monitor a BATCH job's messages from your e-mail account, your message queue, or both. For every BATCH job whose messages you want to monitor, you can even redirect them to your mobile phone.

Resolving The Problem

To monitor some critical BATCH jobs, you can easily monitor the jobs' messages by redirecting the batch jobs' messages to your e-mail, to your message queue, or both.

To do that, do the following:
 
Caution: The following code example is provided on an unsupported, as is basis.
1. Add source member BATCHJOBS to the QGPL/QCLSRC source file. On the operating system command line type the following:

STRSEU SRCFILE(QGPL/QCLSRC) SRCMBR(BATCHJOBS) TYPE(CLP) OPTION(2) TEXT('BATCH jobs'' messages monitoring program')

Press the Enter key.
2. Enter Edit mode for SEU:

Columns . . . :    1  80                                       Edit
SEU==>
FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
       *************** Beginning of data **********************************************
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
       ****************** End of data *************************************************

F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle
F16=Repeat find       F17=Repeat change          F24=More keys
Member BATCHJOBS added to file QGPL/QCLSRC.                                    +
3. Press F13. You will see the SEU Change Session Defaults screen. Change the Uppercase input only option to 'N':

                             Change Session Defaults

Type choices, press Enter.

 Amount to roll . . . . . . . . . . .   H__          H=Half, F=Full
                                                     C=Cursor, D=Data
                                                     1-999
 Uppercase input only . . . . . . . .   N            Y=Yes, N=No
4. Press the Enter key. You are returned to the SEU Edit mode:

Columns . . . :    1  80                                       Edit
SEU==>
FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
       *************** Beginning of data **********************************************
       ****************** End of data *************************************************
5. Type the line command 'I45' on the sequence number area to add forty five blank lines:

Columns . . . :    1  80                                       Edit
SEU==>
FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
I45     *************** Beginning of data **********************************************
       ****************** End of data *************************************************
6. Press the Enter key. Something similar to the following is shown:

Columns . . . :    1  80                                       Edit
SEU==>
FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
       *************** Beginning of data **********************************************
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''

F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle
F16=Repeat find       F17=Repeat change          F24=More keys
7. Copy and paste the following CLP code into the source member:

 BEGIN:      PGM        PARM(&MSGQL &MSGQN)
/* */
            DCL        VAR(&MSGQL) TYPE(*CHAR) LEN(10)
            DCL        VAR(&MSGQN) TYPE(*CHAR) LEN(10)
            DCL        VAR(&MSG) TYPE(*CHAR) LEN(80)
            DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(2000)
            DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)
            DCL        VAR(&MSGF) TYPE(*CHAR) LEN(10)
            DCL        VAR(&MSGFLIB) TYPE(*CHAR) LEN(10)
            DCL        VAR(&RTNTYPE) TYPE(*CHAR) LEN(2)
            DCL        VAR(&SENDER) TYPE(*CHAR) LEN(80)
            DCL        VAR(&JOB) TYPE(*CHAR) LEN(10)
            DCL        VAR(&USER) TYPE(*CHAR) LEN(10)
            DCL        VAR(&NBR) TYPE(*CHAR) LEN(10)
/* */
            MONMSG     MSGID(CPC0000 CPD0000 CPF0000 CPI0000 +
                         MCH0000) EXEC(GOTO CMDLBL(ERROR))
/* */
                                                                     
LOOP:       RCVMSG     MSGQ(&MSGQL/&MSGQN) MSGTYPE(*ANY) WAIT(*MAX) +
                         RMV(*KEEPEXCP) MSG(&MSG) MSGDTA(&MSGDTA) +
                         MSGID(&MSGID) SENDER(&SENDER) +
                         SENDERFMT(*SHORT) RTNTYPE(&RTNTYPE)
            CHGVAR     VAR(&JOB) VALUE(%SST(&SENDER 1 10))
            CHGVAR     VAR(&USER) VALUE(%SST(&SENDER 11 10))
            CHGVAR     VAR(&NBR) VALUE(%SST(&SENDER 21 6))
            SNDMSG     MSG('Message ID: ' || &MSGID |< '. Message: +
                         ' || &MSG |< ' Job: ' || &JOB |< ' / +
                         User: ' || &USER |< ' / Nbr: ' || &NBR |< +
                         '.') TOUSR(MATIAS)
            SNDDST     TYPE(*LMSG) TOINTNET((centenom@ar.ibm.com)) +
                         DSTD('BATCH jobs'' messages...') +
                         LONGMSG('Message ID: ' || &MSGID |< '. +
                         Message: ' || &MSG |< ' Job: ' || &JOB |< +
                         ' / User: ' || &USER |< ' / Nbr: ' || +
                         &NBR |< '.')
            GOTO       CMDLBL(LOOP)
/* */
                                                               
ERROR:      RCVMSG     RMV(*YES) MSGDTA(&MSGDTA) MSGID(&MSGID) +
                         MSGF(&MSGF) MSGFLIB(&MSGFLIB)
            SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +
                         MSGDTA(&MSGDTA)

END:        ENDPGM

Note: Change the TOUSR and TOINTNET parameters to fit your needs.
8. Press F3 + the Enter key to save the code. You are shown the following message at your workstation status line:

 Selection or command
===> _______________________________________
_____________________________________________
F3=Exit   F4=Prompt   F9=Retrieve   F12=Canc
F23=Set initial menu
Member BATCHJOBS added to file QGPL/QCLSRC.
9. Compile the CL procedure BATCHJOBS into the QGPL library. On the operating system command line, type the following:

CRTCLPGM PGM(QGPL/BATCHJOBS) SRCFILE(QGPL/QCLSRC) REPLACE(*YES)
10. Create the messages queue BATCHJOBS. On the operating system command line, type the following:

CRTMSGQ MSGQ(QGPL/BATCHJOBS) TEXT('BATCH jobs'' messages queue') AUT(*EXCLUDE) MSGQFULL(*WRAP)

Press the Enter key.
11. Change the message queue for BATCHJOBS public authorities:

GRTOBJAUT OBJ(QGPL/BATCHJOBS) OBJTYPE(*MSGQ) USER(*PUBLIC) AUT(*OBJOPR *ADD *READ *EXECUTE)

Press the Enter key.
12. Submit the Monitor Job. On the operating system command line, type the following:

SBMJOB CMD(CALL PGM(QGPL/BATCHJOBS) PARM(QGPL BATCHJOBS)) JOB(BATCHJOBS) JOBQ(QBATCH)

Press the Enter key.
13. Run the WRKACTJOB command as follows:

WRKACTJOB SBS(QBATCH) JOB(BATCHJOBS)

Press the Enter key.
14. A screen similar to the following is shown:

Work with Active Jobs                     C10CE97D
                                                           12/15/06  02:45:31
CPU %:      .3     Elapsed time:   01:38:05     Active jobs:   580
                   Current
Opt  Subsystem/Job  User        Type  CPU %  Function        Status
      BATCHJOBS    MATIAS      BCH      .0  PGM-BATCHJOBS    MSGW
.°.

To test the Monitor Job, on the operating system command line type the following commands (one by one):

CRTPF FILE(QGPL/TEMPFILE1) RCDLEN(132) SIZE(*NOMAX)

CRTPF FILE(QGPL/TEMPFILE2) RCDLEN(132) SIZE(1 1 1)

DSPNETA OUTPUT(*PRINT)

CPYSPLF FILE(QPDSPNET) TOFILE(QGPL/TEMPFILE1)

SBMJOB CMD(CPYF FROMFILE(QGPL/TEMPFILE1) TOFILE(QGPL/TEMPFILE2) MBROPT(*ADD) FMTOPT(*NOCHK))
JOB(COPYTEST) JOBQ(QTXTSRCH) MSGQ(QGPL/BATCHJOBS)

DSPMSG MSGQ(QSYSOPR)

A screen similar to the following is shown:
                              Display Messages
                                                     System:   C10CE97D
Queue . . . . . :   QSYSOPR                 Program . . . . :   *DSPMSG
 Library . . . :     QSYS                    Library . . . :
Severity  . . . :   70                      Delivery  . . . :   *HOLD

Type reply (if required), press Enter.
 Member TEMPFILE2 file TEMPFILE2 at maximum size. (C I)
   Reply . . .   __________________

DSPMSG

A screen similar to the following is shown:
                              Display Messages
                                                     System:   C10CE97D
Queue . . . . . :   MATIAS                  Program . . . . :   *DSPMSG
 Library . . . :     QUSRSYS                 Library . . . :
Severity  . . . :   00                      Delivery  . . . :   *NOTIFY

Type reply (if required), press Enter.
 From  . . . :   MATIAS         12/15/06   02:49:40
 Message ID: CPI2404. Message: Waiting for reply to message on message
   queue QSYSOPR. Job: COPYTEST / User: MATIAS / Nbr: 134642.

.°.

Recommendation: The CL procedure example could be easily modified to fit your needs.

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m3p000000GoLkAAK","label":"Job and Work Management-\u003EManaging jobs"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]

Historical Number

435939498

Document Information

Modified date:
07 October 2024

UID

nas8N1014602