Previously I have been touching the subject of avoiding job scheduling tools like OPC/TWS which has become increasingly easy. Many of the functions supplied by OPC/TWS are now available directly within JCL. And in this week I will give you a tip about how to automate the repeated submission of the same job. All you need is JCL, SORT and a dataset/member where the job is kept. Just take a look:
//MYUSERRR JOB ,'REPEAT',MSGCLASS=F,COND=(4,LT), // CLASS=A,REGION=0M,NOTIFY=&SYSUID //* // SCHEDULE HOLDUNTL=('05:00','2019/210') //* //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 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 where it will start immediately when you have submitted it. 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.
I have used the above trick during the last two years and it works surprisingly stable. The job will survive an IPL so you do not have to worry about that. I am an extremely happy user of this tip and I hope you will be as well.