Check for active jobs in CL

15 pts.
Tags:
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.

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.

Tom

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • 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:
    report
  • 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:
    report
  • 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:
    report
  • 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:
    report
  • 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:
    report

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following