Check for active jobs in CL

25 pts.
IBM iSeries
How can I check for a active job in my CL?

Answer Wiki

Thanks. We'll let you know when a new response is added.

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 Retrieve Job Status (QWCRJBST) API. 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 List Job (QUSLJOB) API 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 Retrieve Job Information (QUSRJOBI) API.

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.


Discuss This Question: 5  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Fanbot
    As previous user stated. However by using a flat file length 132 bytes, you can actually perform all of the processing in the cl by either sequential processing, SQL or QRY selection.
    0 pointsBadges:
  • BurtNoir
    I like to use WRKUSRJOB for this type of thing because it can show you jobs on the queue as well - which can be useful if you are trying to get the program to decide whether or not to submit another one. But it all depends on what you are trying to do and what information you have available when the program runs. If it's something very specific like one program needs to know the status of another before it can run then you could also use a data area to communicate between them.
    0 pointsBadges:
  • Satsho
    Have you looked at the following API's 1. QUSLJOB 2. QGYOLJOB There are a lot of examples out there using these API's.
    1,245 pointsBadges:
  • ISeriesGuyWI
    I have an rpgle pgm that does that for me using the QUSLJOB API. If you want i can send it to you. Just pass it the job name and it returns if it is active. Works well for me.
    80 pointsBadges:
  • TomLiotta
    For an example of how the various APIs would be used, see the discussion under End Active Job within a cl pgm. Tom
    125,585 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: