Thursday, May 21, 2026

Running a job at a specific time every day without using a job scheduler

This post explains how to automate the repeated submission of a job using JCL, SORT, and a dataset/member where the job is stored.

Sample Job

/MYUSERRR JOB ,'REPEAT',MSGCLASS=F,COND=(4,LT),
//         CLASS=A,REGION=0M,NOTIFY=&SYSUID
//*
// SCHEDULE HOLDUNTL=('05:00','2026/141')
//*
//NEXTJOB  EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTIN   DD DISP=SHR,DSN=MYUSER.JCL(REPEAT)
//SORTOUT  DD SYSOUT=(,INTRDR)
//SYSIN    DD *
    OPTION COPY
    OUTFIL IFTHEN=(WHEN=(1,21,CH,EQ,C'// SCHEDULE HOLDUNTL='),
           BUILD=(1,23,C'05',26,6,DATE3(/)+1,40,41)),
           IFTHEN=(WHEN=NONE,BUILD=(1,80))
/*
//* PUT REST OF JOB AFTER THIS COMMENT

In the above job you have to change the job card to make it work at your installation. Whatever you want the job to do every hour or day or week or month or ... you will have to append in additional steps. The above job will run every day at 5am except for the first time.   

  • If the scheduled time has already passed at submission, the job starts immediately.
  • If the scheduled time is in the future, the job remains in HELD status until the specified time.

Please remember to save the JCL in MYUSER.JCL(REPEAT) before you submit it the first time.

 

So what is actually going on? SCHEDULE makes the job start at the specified time on the specified day. SORT reads the JCL from SORTIN and copies it to SORTOUT which submits it again. During the copy SORT edits the contents of the SCHEDULE card and adds one to the current date (DATE3(/)+1) which delays the execution of the job until next day at 5am. You can choose to add 7 instead if the job is supposed to run once a week or add some other value. The amazing thing is the ability to control the time of day, too. I have just chosen to let the job start at 5am. You can use some of the functionality in the BUILD function in SORT to make the job run every hour or every second hour or whatever you need.

 

Please be aware that when you make changes to the JCL in MYUSER.JCL(REPEAT) it will not take effect until after the next time the job is executed as the job waiting to be executed next time is sitting in the input queue in JES. If you want your change to have immediate effect you must cancel the job in JES and then submit your changed job with a SCHEDULE card holding the time and date for the next execution. The job will survive an IPL so you do not have to worry about that.

 

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.