How to control order of jobs run in batch

435 pts.
Tags:
AS/400
RPG
In this user's CL program, he has 3 jobs and he wants to submit all jobs in qbatch. The catch is he wants to run the third job after the first and second job have already completed. How can he control this? -- Michelle Davidson, editor, Search400.com

Answer Wiki

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

I suppose the easiest way is to send the jobs to a job queue that only allows one job to run at a time.

===================================================

See the answer to Need to know whether a job is completed for some basic info on submitted jobs and batch job completion.

The CPC1221 *COMP message from SBMJOB can be combined with the CPF1241 *COMP message from a completed job to allow any control anyone wants.

Tom

Discuss This Question: 12  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
  • Dalibor
    I support that. If a job queue that runs only one job doesn't exist, it could be easily created and adapt for running only one job. It can be done with in a minute with a two commands: CRTJOBQ, and then you must add job queue to specific (desired) subsystem. Parameter MAXACT in ADDJOBQ must be set to 1, if you want to run one by one job.
    10 pointsBadges:
    report
  • Wimcamp
    Alternative: From your initial CL (PGM1) you submit another CL(PGM2). PGM2 executes the 3 jobs.
    0 pointsBadges:
    report
  • Graeme
    QBATCH is normally set to MAXACT(1) anyway so there shouldn't give them a problem. Is there more behind the question (he asks with one eyebrow raised) such as the third job can only run if the two have run successfully? If not, then the CL should simply have the three submit commands in the order they should run. For example: /* */ /* GRAEME'S CUNNING CLP */ /* */ PGM SBMJOB CMD(CALL PGM(DO_CLEVER/THINGS)) JOB(FIRST) JOBQ(QBATCH) SBMJOB CMD(CALL PGM(DO_CLEVER/STUFF)) JOB(SECOND) JOBQ(QBATCH) SBMJOB CMD(CALL PGM(DO_CLEVER/TRICKS)) JOB(THIRD) JOBQ(QBATCH) ENDPGM
    0 pointsBadges:
    report
  • VBOTone
    These are pretty standard OS/400 answers, but it seems that he desires to run the first and second job concurently. Since we don't know which of the first two jobs will finish first, it seems best to use an external set of flags. A good place would be in a data area. Each job would update it's own flag. The third job would monitor the status of the flags and procede when both are set. The same thing could be accomplished with a message queue using SNDMSG/RCVMSG. The first two jobs would send a special message when completed. The third job would wait until a message from each job has been received.
    55 pointsBadges:
    report
  • Nevster
    If your jobs are going to be submitted to the same job queue you can assign job priority (JOBPTY) to each one which will organise the sequence on the job queue. (this assummes that the job queue will be held first so that none of the jobs will drop straight into the subsystem). Also, on the submit job (SBMJOB)command you can hold the job for manual release later, and you can schedule jobs to be released at specific times.
    0 pointsBadges:
    report
  • RobertMcCarty
    issue command: sbmjob cmd(call pgm(*libl/maincl)) (to any job queue) "Maincl" CL program: pgm call proga call progb call progc endpgm Simple enough?
    0 pointsBadges:
    report
  • McSick
    I've got to go with McCarty's answer!! If you have separate programs that you want to run in a specific order, don't submit them as separate batch jobs, but create one CL program with all the programs called in the order that you want them to run. Add Monmsg CPF0000 to capture any failing call, if you care to do check for errors. Keep it simple people and think out of the box! There are 1,001 ways to get it done, but only 1 right way, It's finding the right way before we've tried 1,000 of the other ways. hehehe
    50 pointsBadges:
    report
  • Mocha1
    If you have a single threaded jobq, just submit your batch job specifying that jobq. If not, create a new jobq for single threaded jobs(CRTJOBQ). Then add a job queue entry to your batch subsystem with the number of jobs set to 1.( ADDJOBQE SBSD(qbatch) JOBQ(SINGLE)MAXACT(1). Then you would just submit the jobs in the order that you want them to run using the new job queue. That should do the trick.
    0 pointsBadges:
    report
  • McSick
    I understand all of you that said to use a single thread job queue, however, what happens if the 1st or 2nd job fails with a console message and it is cancelled? The remaining jobs in the queue will still be released into the system. Make sure you cover all possibilities. Someone suggested creating an external flag using a data area or file or whatever to determine which jobs were run or had completed normally before the remaining jobs will run. This would require the 2nd or 3rd job having to recheck over and over again until 1st job is done. These jobs if submitted must end and be resubmitted at an time interval so as to allow the next job in the queue to be released. I still think one CL program with the 3 calls works best. Keep it simple.
    50 pointsBadges:
    report
  • ToddN2000

    If jobs 1 and 2 can run side by side it makes things a little tougher. You could set a data area flag at the end of  job1 and job2.  You could then have job3 check the status of the 2 data areas. If done, it's ok to run. If job1 or job2 is still running then you could put a DLYJOB in the job3 cl and retest the values after a given amount of time. Not my choice because it ties up a job slot and if there is an error in job1 or job2, the job3 will continue to loop.  Depending on how long these jobs run, I'd put all 3 in one CL. Better safe than sorry.

    11,325 pointsBadges:
    report
  • aceofdelts
    I'm with VBOT - let Jobs 1 & 2 run concurrently and Job 3 checks a file or data area. Could also add an error test on the submit - problem if Job 3 never ran (assume we'd reset data area upon completion) - thus making a higher quality process.
    1,930 pointsBadges:
    report
  • TomLiotta
    The method that is built into the SBMJOB command gives complete control without creating a data area or a file and without having to code anything into the submitted jobs' programming to update anything. Why create some structure when everything is already built into the system? -- 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