The question was simple: Can you tell when a subsystem started?
I am going to give two examples. The first will show what I would do if you asked me what time the QPGMR subsystem was started. I only need to give an answer one time, and I do not need to write a program or code to do this.
In the second example I do want some code to show when the QPGMR subsystem was started. This would be used in a scenario where I would need to know frequently what time it started. I would add it to the Job Scheduler, run the job periodically, and it would send me an email with the date and time it started included within.
Example 1: One time
At any command line I would type in:
WRKACTJOB SBS(QPGMR) |
The results show all of the active jobs in the QPGMR subsystem. If there are no results the subsystem is not active.
Work with Active Jobs Current Opt Subsystem/Job User Type CPU % Function Status 5 QPGMR QSYS SBS .0 DEQW _ QPADEV0001 SIMON INT .0 CMD-WRKACTJOB DSPW |
The first job is the one that is started when the subsystem is started. I put a "5" next to it, as shown, and press Enter.
At the "Work with job menu" I take option 10 for "Display job log, if active, on job queue, or pending".
The first line shown has the date and time when the subsystem was started:
Display Job Log System: DEV740 Job . . : QPGMR User . . : QSYS Number . . . : 110064 Job 110064/QSYS/QPGMR started on 02/22/21 at 09:24:53 in subsystem QPGMR |
Example 2: Frequently
I can use the information from two SQL Table functions to give me what I need:
- Subsystem library name
- Subsystem name
- Time started
The first Table function I will use is ACTIVE_JOB_INFO as that can tell me if the subsystem is active or not.
The second is JOB_LOG_INFO, as I need to get the first entry from the job log.
The SQL statement I would use is:
01 SELECT A.SUBSYSTEM_LIBRARY_NAME AS "Library", 02 A.SUBSYSTEM AS "Subsystem", 03 B.MESSAGE_TIMESTAMP AS "Start time" 04 FROM TABLE(QSYS2.ACTIVE_JOB_INFO( 05 SUBSYSTEM_LIST_FILTER => 'QPGMR', 06 JOB_NAME_FILTER => '*SBS')) A, 07 LATERAL 08 (SELECT MESSAGE_TIMESTAMP 09 FROM TABLE(QSYS2.JOBLOG_INFO(A.JOB_NAME)) 10 WHERE ORDINAL_POSITION = 1) B ; |
Lines 1 – 3: These are the columns I desire, and I have given them meaningful headings.
Lines 4 - 6: Here we have the ACTIVE_JOB_INFO Table function, and the two parameters I am passing to it:
- SUBSYSTEM_LIST_FILTER: Name of the subsystem, in this example it is 'QPGMR'
- JOB_NAME_FILTER: The type of job I am interested in, here it is the subsystem itself
Line 7: Using the LATERAL I can include the results from a subselect using a column from the first part.
Lines 8 – 10: This is the subselect. I want the job log message timestamp returned. I using the JOBLOG_INFO Table function passing the job name from the ACTIVE_JOB_INFO. I am only interested in the first entry in the joblog, therefore, to select that I must use the ORDINAL_POSITION column.
The results are the same as those from example 1.
Library Subsystem Start time ------- --------- -------------------------- QSYS QPGMR 2021-02-22 09:24:53.752041 |
If no result is returned the subsystem is not active.
This article was written for IBM i 7.4, and should work for some earlier releases too.
Simon, the name of the parameter SUBSYSTEM_NAME_FILTER should be SUBSYSTEM_LIST_FILTER.
ReplyDeleteOops. Thank you for bring that to my attention. I have made the change.
Deletealso need to change it here:
DeleteLines 4 - 6: Here we have the ACTIVE_JOB_INFO Table function, and the two parameters I am passing to it:
SUBSYSTEM_NAME_FILTER: Name of the subsystem, in this example it is 'QPGMR'
Thank you.
DeleteThank you to everyone who noticed that there was a type in the SQL statement. I was missing a > symbol. The statement has been corrected.
ReplyDelete