First do a WRKACTJOB OUTPUT(*PRINT) SBS(QBATCH) JOB(JOBNAME)in the Cl program.
Then do a CPYSPLF command for file QPDSPAJB. The create an RPG program that parses out the spool file information from the file and check for the required job to see if it’s running. The job ID should be in position 5-14.
Hope this helps.
Don’t try processing a printed file, especially when it’s easier to do it the right way. Technically, you want to use the <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/qwcrjbst.htm”>Retrieve Job Status (QWCRJBST) API</a>. But a quick look at it will show that you aren’t likely to know what the name of the job is without some research.
A job is known by the combination of name, user and number. Most likely you will only know the ‘name’ portion. How can you expect to find the status when you don’t know the fully qualified job name?
Say that you’re trying to find the status of a job named PAYROLL. The job might run every week. When it runs, it might generate a few reports and also generate a joblog when it finishes. Because it leaves reports behind, the job still exists in the system. The joblog might remain in the system for a month or more. After four weeks, there will be four different PAYROLL jobs in the system. Which one are expecting to check the status for?
Further, anybody can give the name PAYROLL to any job at any time. How do you intend to tell the difference between regular PAYROLL jobs and, for example, one that I ran that simply lists all users in the Human Resources payroll group but that I named PAYROLL?
Usually you’ll need to know a number of additional attributes. The user associated with the job should be one that is not a basic user profile. Maybe it’s a profile created to run these jobs — e.g., PAYUSER. With a job name and a known job user, you’d have two of the three elements that should uniquely identify a job.
But the final element — job number — is harder to come by.
What might commonly be done is to call the <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/qusljob.htm”>List Job (QUSLJOB) API</a> to create a list of jobs in the system with that name and user. You’d loop through the list perhaps to find the one with the most recent date.
Except the list doesn’t include attributes such as date. To get the dates, you take the fully-qualified name from each job in the list and call another API — the <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/qusrjobi.htm”>Retrieve Job Information (QUSRJOBI) API</a>.
But wait, the list also has Status along with names… maybe you only want to know if PAYROLL currently has an *ACTIVE status. In that case, you’d loop through the list to see if *ACTIVE was one of the listed statuses. If it is, the job is active, otherwise it isn’t.
As you can see, the simple question “Is job X active?” can have a lot of implications.
Best thing to do is describe what the business problem is. Rather than the way you asked, try to state the problem in a way that can be reviewed by others. Multiple suggested resolutions can be supplied. A good resolution can be worked out in a dialog.