Problem solve Get help with specific problems with your technologies, process and projects.

Monitor your job

Site expert John Kohan provides a way to determine when a batch job is in a "MSGW" (Message Wait) status in QBATCH.

Want to know when a batch job is in a "MSGW" (Message Wait) status in QBATCH? You could place message monitors in CL programs to trap those messages and take the appropriate action. But unfortunately, that can't always be accomplished. Several different developer processes may run on any given iSeries. Those include in-house processes, outside vendors, and even IBM processes.

You may, however, monitor your system for MSGW jobs with just a few simple lines of code. The process is simple, and I have used it in the past with good success.

The WRKACTJOB command allows you to display any subsystem you wish. By using the SBS keyword, you can specify one or more subsystems to list. In addition, you may list those subsystems to screen or to a spool file.


John Kohan

By listing the subsystems to a spool file, you can copy the spool file to a physical file and read them with a RPG program. The RPG program can look at the status of each job and take the necessary action.

I have included a very simple CL and RPG program. They are intended to give you a starting point from which to build a process. You will want to add additional code to do such things as properly remove the spool files when it is complete and capture more information then just the status of the job.

Once the programs are ready for production, all you need to do is call the CL program. There are several ways to execute the CL program to periodically check the status of a subsystem(s). One way is to add it to your job scheduler to run at set times.

Below is a breakdown of this process.

  1. Create a physical file that is called SPOOLI with a single field 133 bytes called SPOOL.
  2. Create a CL program to get the status of all active jobs in a subsystem and create a spool file.
  3. Copy the spool file to file SPOOLI
  4. Call and RPG program to read the status of the job(s)
  5. Execute logic within the RPG program when a job is in MSGW

Here is the CL & RPG source to support the above process.

CL Program GETSTAT

PGM
WRKACTJOB  OUTPUT(*PRINT) SBS(QBATCH)            
CPYSPLF    FILE(QPDSPAJB) TOFILE(*LIBL/SPOOLI) + 
             SPLNBR(*LAST)                       
CALL       PGM(CHKSTAT)
ENDPGM                             

RPG Program CHKSTAT

FSPOOLI    IF   E             DISK                                      
F                                     RENAME(SPOOL:SPOOLR)              
D*----------------------------------------------------------------      
D                 DS                                                    
D  SPOOL                  1    133                                      
D  @STAT                111    114                                      
C*----------------------------------------------------------------      
C     *INLR         DOUEQ     *ON                                       
C                   READ      SPOOLR                                 LR 
C     *INLR         IFEQ      *OFF                                      
C     @STAT         ANDEQ     'MSGW'                                    
C* Take action                                                          
C                   ENDIF                                               
C                   ENDDO                                               

-----------------------------------------
About the author: John Kohan is a senior programmer analyst at CT Codeworks.

==================================
MORE INFORMATION
==================================

  • Receive "MSGW" note by e-mail/phone
    With one main CL as control batch, the system can send e-mail when a MSGW in WRKACTJOB occurs. This also works with a message on cell phones that have message access.
  • Resequencing columns on the WRKACTJOB screen
    If you've ever had a hard time finding the job referred to by error messages popping up in your QSYSOPR message queue, Search400.com member Dave Jeffries has a tip that will reduce your search time.
  • Three fun things you can do with WRKACTJOB
    Sometimes it's the simple tools -- like OS/400's green-screen Work with Active Jobs (WRKACTJOB) -- that you take for granted. WRKACTJOB's a lot older than many readers on this list and -- because of that longevity -- it contains some useful features that can be handy in different situations.
  • Proper way to end WRKACTJOB
    Most iSeries (AS/400) users do not use the correct procedure to end the WRKACTJOB command. The common method used involves the user pressing the "F3" or the "F12" command keys. This is incorrect.


Dig Deeper on iSeries CL programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close