The EXEC (Execute) statement marks the beginning of a job step within a JCL job. It identifies either the program to be executed or the procedure to be invoked, and specifies the resources and parameters needed for execution.
123//stepname EXEC PGM=program-name //stepname EXEC PROC=procedure-name //stepname EXEC procedure-name
The EXEC statement can invoke either a program directly or a cataloged/in-stream procedure. When invoking a procedure, the PROC= keyword is optional.
Like all JCL statements, the EXEC statement follows a specific format with several fields.
1. Identifier Field (columns 1-2)
2. Name Field (columns 3-10)
3. Operation Field (column 12+)
4. Operand Field
Step names follow the same rules as job names:
Step names are important because they:
The primary use of the EXEC statement is to execute a specific program.
To execute a program directly, use the PGM parameter to specify the program name:
1234//STEP1 EXEC PGM=IEFBR14 //STEP2 EXEC PGM=SORT //STEP3 EXEC PGM=IKJEFT01 //STEP4 EXEC PGM=MYCOBOL
The program must be a load module in a library that is accessible to the system (either in the system libraries, the JOBLIB/STEPLIB, or a link list library).
Program Name | Function | Common Use |
---|---|---|
IEFBR14 | Do nothing program | Create, delete, or catalog datasets |
SORT/ICEMAN | IBM Sort/Merge | Sort or merge datasets |
IDCAMS | Access Method Services | Manage VSAM files and catalogs |
IEBGENER | Data Set Copy | Copy or upgrade sequential datasets |
IEBCOPY | Partitioned Data Set Copy | Copy or compress partitioned datasets |
IKJEFT01 | TSO Terminal Monitor | Execute TSO commands in batch |
DFSORT | IBM DFSORT | Enhanced sorting capabilities |
IEFBR14 Example (Create a dataset)
123//STEP1 EXEC PGM=IEFBR14 //DD1 DD DSN=MY.NEW.DATASET,DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(10,2)),DCB=(RECFM=FB,LRECL=80,BLKSIZE=800)
IDCAMS Example (List a catalog)
12345//STEP2 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //SYSIN DD * LISTCAT ENTRIES('MY.DATASET.NAME') ALL /*
SORT Example (Sort a file)
12345678//STEP3 EXEC PGM=SORT //SYSOUT DD SYSOUT=* //SORTIN DD DSN=INPUT.FILE,DISP=SHR //SORTOUT DD DSN=OUTPUT.FILE,DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(10,5)),DCB=(RECFM=FB,LRECL=80,BLKSIZE=800) //SYSIN DD * SORT FIELDS=(1,10,CH,A,11,5,CH,D) /*
The EXEC statement can also invoke a cataloged or in-stream procedure.
To execute a procedure, you can use either of these formats:
12//STEP1 EXEC PROC=PAYROLL //STEP2 EXEC PAYROLL
The PROC= keyword is optional when invoking a procedure. The procedure must be either a cataloged procedure in a procedure library or an in-stream procedure defined earlier in the job.
Example of using a cataloged procedure:
123//STEP1 EXEC ASMHCL, // PARM.ASM='NODECK,OBJECT', // PARM.LKED='LIST,MAP'
Example of defining and using an in-stream procedure:
123456//MYPROC PROC //STEP1 EXEC PGM=IEFBR14 //DD1 DD SYSOUT=* // PEND //* //RUNSTEP EXEC MYPROC
This example shows a procedure definition and invocation:
12345678910111213//* DEFINE A PROCEDURE //COPYPROC PROC FROM=,TO=,SPACE=(TRK,(5,1)) //COPY EXEC PGM=IEBGENER //SYSPRINT DD SYSOUT=* //SYSIN DD DUMMY //SYSUT1 DD DSN=&FROM,DISP=SHR //SYSUT2 DD DSN=&TO,DISP=(NEW,CATLG,DELETE), // SPACE=&SPACE,DCB=(RECFM=FB,LRECL=80,BLKSIZE=800) // PEND //* //* INVOKE THE PROCEDURE //STEP1 EXEC COPYPROC,FROM='MY.INPUT.FILE',TO='MY.OUTPUT.FILE', // SPACE=(CYL,(1,1))
This procedure (COPYPROC) defines a general-purpose file copy operation using IEBGENER. When invoked by STEP1, it copies MY.INPUT.FILE to MY.OUTPUT.FILE, overriding the default space allocation.
The EXEC statement can include various parameters to control step execution and resource allocation.
Passes information to the program being executed:
Format:
1PARM='parameter-string'
Examples:
12//STEP1 EXEC PGM=MYPROG,PARM='DEBUG,TRACE' //STEP2 EXEC PGM=SORT,PARM='MSGDDN=MSGLST,EQUALS'
Specifies the maximum CPU time for the step:
Format:
1TIME=(minutes,seconds) | TIME=minutes | TIME=1440 | TIME=NOLIMIT
Examples:
12//STEP1 EXEC PGM=MYPROG,TIME=(5,30) //STEP2 EXEC PGM=LONGRUN,TIME=NOLIMIT
Specifies the amount of virtual storage for the step:
Format:
1REGION=valueK | valueM | 0K | 0M
Examples:
12//STEP1 EXEC PGM=SMALLPGM,REGION=2M //STEP2 EXEC PGM=BIGPGM,REGION=0M
Controls conditional execution based on previous steps' return codes:
Format:
1234COND=(code,operator) COND=((code1,operator1),(code2,operator2),...) COND=EVEN COND=ONLY
Examples:
1234//STEP1 EXEC PGM=MYPROG //STEP2 EXEC PGM=NEXTPGM,COND=(4,LT) //STEP3 EXEC PGM=CLEANUP,COND=EVEN //STEP4 EXEC PGM=ERRPGM,COND=((0,NE,STEP1),(0,NE,STEP2))
Operator | Meaning |
---|---|
GT | Greater than |
GE | Greater than or equal to |
EQ | Equal to |
NE | Not equal to |
LT | Less than |
LE | Less than or equal to |
The COND parameter is evaluated as "bypass this step IF the condition is met." For example, COND=(4,LT) means "bypass this step if any previous step's return code is less than 4."
Here are some complete examples of EXEC statements for different scenarios.
1//STEP010 EXEC PGM=IEFBR14
Simple execution of the IBM utility program IEFBR14, which does nothing but return a completion code.
1234//SORT010 EXEC PGM=SORT, // REGION=4M, // TIME=5, // PARM='MSGDDN=SORTMSG,EQUALS,DYNALLOC'
This executes the SORT utility with specific parameters, allocating 4MB of memory and setting a time limit of 5 minutes.
123//CREATE EXEC PGM=MYPROG //REPORT EXEC PGM=REPORTER,COND=(0,EQ,CREATE) //CLEANUP EXEC PGM=CLEANUP,COND=EVEN
The REPORT step only executes if the CREATE step completes with a return code of 0. The CLEANUP step executes regardless of whether any previous steps abended.
1234567//COMPILE EXEC COBUCLG, // REGION.COB=4M, // REGION.LKED=6M, // REGION.GO=8M, // PARM.COB='NOOPT,SOURCE,XREF', // PARM.LKED='LIST,MAP,LET', // TIME.GO=10
This executes the COBUCLG procedure (Compile, Link-edit, and Go for COBOL programs), overriding various parameters for each step within the procedure. Each step gets a different region size, and different parameters are passed to each step.
123456//STEP1 EXEC PGM=PROGRAM1 //STEP2 EXEC PGM=PROGRAM2 //CLEANUP EXEC PGM=PROGRAM3, // COND=((0,EQ,STEP1),(0,EQ,STEP2)) //ERROR EXEC PGM=PROGRAM4, // COND=((12,LT,STEP1),(12,LT,STEP2))
The CLEANUP step only executes if both STEP1 and STEP2 complete with return codes equal to 0. The ERROR step only executes if either STEP1 or STEP2 has a return code less than 12 (meaning one of them encountered a significant error).