This week’s API by Example presents a utility that is designed to monitor active batch jobs and report any active jobs that are currently either held or waiting for a reply to a specific message. I named it “The Monitor Batch Jobs (MONBCHJOB)” command.
The heart of the utility is the QGYOLJOB (Open List of Jobs) API, which, as its name reveals, is one of the Open List APIs. These APIs return the same type of information as regular List APIs. The difference is the standard List APIs output their results to a user space, whereas the Open List APIs spawn a separate job to do the work and you retrieve the data from that job using the Get List Entry (QGYGTLE) API.
Although I could’ve written the MONBCHJOB utility with the normal List APIs, I chose the Open List APIs to improve performance. Since the information retrieval is an asynchronous process, your program can start processing the returned list entries even before the list is complete.
For large lists, this can substantially improve the performance of the list processing program. When list processing is complete, running the Close List (QGYCLST) API is essential since it performs clean-up activities and frees up all of the resources used by the Open List API.
Download the save file containing the source code.
APIs by Example: Monitor Batch Job Utility Bug Fix
The MONBCHJOB command presented in the previous installment of this column unfortunately had a problem in the main command-processing program, CBX1322. In line 415.00, I had entered the following:
DoW LstInf.LstSts '2' Or LstInf.RcdNbrTot > RtnRcdNbr;
This needs to be changed to the following:
DoW LstInf.LstSts '2' Or LstInf.RcdNbrTot >= RtnRcdNbr;
The equal sign was missing in the original statement, which lead to the last record in the job list not being read. As a consequence, a monitor event could remain undiscovered.