In brief
JCL (Job Control Language) is the language you use to tell z/OS which program to run, which data sets it should work with and what to do with the results. A job consists of a JOB statement, EXEC steps and DD data set definitions. A job scheduler, such as IBM Z Workload Scheduler, decides when and in what order jobs start and enforces the dependencies between them. A new team member first learns to read return codes and ABENDs, the DISP parameter, GDG data sets and restart rules.
Three statements: JOB, EXEC and DD
Every batch job on z/OS starts with a JOB statement, which gives it a name and parameters such as the job class and the message output class. An EXEC statement starts a step and names a program or procedure. DD (data definition) statements connect the file names used inside the program to data sets on the system. A COBOL program reads a file called INPUT, and only the DD statement in the JCL says which data set that is.
//CALC JOB (SETTLE),'NIGHTLY CALCULATION',CLASS=A,MSGCLASS=X,
// NOTIFY=&SYSUID
//STEP010 EXEC PGM=IEFBR14
//DELOLD DD DSN=SETTLE.RESULTS.DAILY,DISP=(MOD,DELETE,DELETE),
// SPACE=(TRK,(1,1))
//STEP020 EXEC PGM=CALC
//STEPLIB DD DSN=SETTLE.LOADLIB,DISP=SHR
//INPUT DD DSN=SETTLE.TRANSACT(0),DISP=SHR
//OUTPUT DD DSN=SETTLE.RESULTS.DAILY,DISP=(NEW,CATLG,DELETE),
// SPACE=(CYL,(50,10),RLSE),
// DCB=(RECFM=FB,LRECL=200)
//SYSOUT DD SYSOUT=*
// IF (STEP020.RC <= 4) THEN
//STEP030 EXEC PGM=REPORT
//STEPLIB DD DSN=SETTLE.LOADLIB,DISP=SHR
//RESULTS DD DSN=SETTLE.RESULTS.DAILY,DISP=SHR
//SYSOUT DD SYSOUT=*
// ENDIFStep STEP010 runs IEFBR14, a program that does nothing. All the work happens in the DD statement: the results data set from the previous run is deleted if it exists. This is a popular way to make a job rerunnable without manual cleanup. STEP020 reads the latest generation of transactions and creates a new results data set, and STEP030 prints a report only if the calculation ended with a return code no higher than 4.
Return codes and ABENDs
Every step ends with a return code. Many teams follow a convention: 0 is success, 4 a warning, 8 an error, 12 and 16 a severe error. This is a convention of the programs, not a system rule, so the documentation of each job has to state what a given code means.
A return code is different from an ABEND, which is an abnormal end of a step. ABEND codes are described in the z/OS MVS System Codes manual. A few show up in every team:
| Code | What it means | Typical cause |
|---|---|---|
| S0C7 | Data exception in a decimal operation | A numeric field with invalid content, for example spaces |
| S806 | Program module not found | Wrong program name or a library missing from STEPLIB |
| SB37, SD37, SE37 | Out of space for an output data set | SPACE parameter too small or no secondary allocation |
| S322 | CPU time limit exceeded | A loop in the program or a TIME limit set too low |
| S222 | Job canceled by the operator | Manual cancellation, often of a hung job |
Older JCL controls the flow with the COND parameter, whose logic is the reverse of IF: COND=(4,LT,STEP020) means “skip this step if 4 is less than the return code of step STEP020.” The IF, THEN, ELSE and ENDIF statements are more readable and better suited to new code.
Data sets: DISP and GDG
The DISP parameter has three positions: the status of the data set before the step (NEW, OLD, SHR, MOD), what to do after a normal end (for example CATLG, which records it in the catalog) and what to do after an ABEND (for example DELETE). Mistakes in DISP are the most common reason a job cannot be rerun, because the data set from the failed run already exists.
A GDG (generation data group) is a group of successive versions of the same data set, for example daily transaction files. SETTLE.TRANSACT(0) means the latest generation, (+1) the new one created in this job, and (-1) the previous one. GDGs make restart and keeping history easier, but they need care: rerunning a step that creates (+1) will create yet another generation if the previous run managed to write one.
Job scheduling
JES (Job Entry Subsystem) runs a job once it has been submitted. The scheduler decides when to submit it. A scheduling tool, such as IBM Z Workload Scheduler or products from other vendors, maintains the plan of batch runs and takes care of several things at once:
- dependencies: the settlement job starts only after end of day and the payment import;
- calendars: different runs on business days, at month end and at year end;
- resources: two jobs using the same data set do not start together;
- events: a job starts when a file arrives from a partner;
- reaction to errors: stopping the chain, alerting the on-call engineer, retrying.
For a new team member, the plan of the nightly batch is the best map of the system: it shows what depends on what and which jobs are on the critical path. When moving batch runs off the mainframe, the schedule has to be rebuilt together with these dependencies, as we explain in the article Mainframe batch processing in the cloud.
Restart after failure and the first weeks in the team
The RESTART parameter on the JOB statement lets you run a job from a chosen step. This only works well when the steps are designed for restart: each cleans up after itself at the start, does not depend on temporary data sets from earlier steps and has a documented procedure. For every job on the critical path, record from which step it may be resumed and when the data has to be restored.
The first weeks of a new person on a mainframe team go well in this order:
- reading the JCL and job output of one batch run, step by step, together with an experienced engineer;
- analyzing a few real ABENDs from history, with cause and fix;
- a first JCL change in the test environment, with review;
- paired on-call duty before going solo.
How to plan knowledge transfer before experienced engineers leave is described in the article COBOL and the mainframe: how to transfer knowledge before the experts leave. The IBM i counterpart of JCL, CL programs, is covered in the article CL on IBM i. The project on a maintenance team shows an example of a team taking over maintenance of a line-of-business system.
Questions and answers
How is JCL different from a shell script?
JCL is not a programming language in the usual sense. It has no loops and variables to the extent a shell does, and mainly describes the steps, programs and data sets the system must allocate before running the program. The logic lives in the programs, and the order and conditions of large job chains live in the scheduler. Because of this, the system knows in advance what resources a job needs.
What does ABEND S0C7 mean?
S0C7 is a data exception: the program performed a decimal operation on a field whose content is not a valid packed or zoned decimal number. The most common causes are spaces or other characters in a numeric field of the input file, a new file format from a partner or a shifted record layout. Analysis starts with the dump and the record on which the program stopped.
What is a GDG on the mainframe?
A GDG (generation data group) is a group of data sets with a common base name, in which each generation is the next version, for example the transaction file from the next day. In JCL you refer to them relatively: (0) is the latest, (+1) the new one, (-1) the previous one. The group has a set generation limit, and the oldest generations drop out of it as new ones are created.
Can JCL be kept in git?
Yes. JCL is text, so it can live in a repository alongside COBOL programs, with changes going through review. Tools such as Zowe and VS Code extensions let you submit a job and read its output from the editor. In many installations the production version of the JCL is still controlled by the scheduler or a change management tool, so you need to agree on where the source of truth is.