MainframeMaster

JCL Tutorial

EXEC Statement

Progress0 of 0 lessons

EXEC Statement Purpose

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.

Primary Functions of the EXEC Statement

  • Define a job step by specifying a program or procedure to execute
  • Allocate resources for the step (region size, time limit)
  • Control step execution (conditional execution, restart capabilities)
  • Pass parameters to programs or override values in procedures
  • Specify execution options (DYNAMNBR, PERFORM)

Basic EXEC Statement Format

jcl
1
2
3
//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.

EXEC Statement Format

Like all JCL statements, the EXEC statement follows a specific format with several fields.

EXEC Statement Fields

1. Identifier Field (columns 1-2)

  • Must contain // for all JCL statements

2. Name Field (columns 3-10)

  • Contains the step name (1-8 characters)
  • First character must be alphabetic (A-Z) or national (@, #, $)
  • Remaining characters can be alphanumeric (A-Z, 0-9) or national
  • Must be unique within the job
  • Can be omitted, but not recommended (makes referencing difficult)

3. Operation Field (column 12+)

  • Contains EXEC to identify this as an EXEC statement

4. Operand Field

  • PGM= or procedure name (required)
  • Various step-level parameters separated by commas
  • Parameters for a procedure step (if applicable)

Naming Job Steps

Step names follow the same rules as job names:

  • Must be 1-8 characters long
  • First character must be A-Z, @, #, or $
  • Remaining characters can be A-Z, 0-9, @, #, or $
  • Must be unique within the job

Step names are important because they:

  • Allow referencing the step in subsequent JCL (COND parameter)
  • Enable job restart at a specific step (RESTART parameter)
  • Make it easier to identify steps in output messages
  • Allow for dataset name qualification (using step name)

Executing Programs

The primary use of the EXEC statement is to execute a specific program.

Using PGM Parameter

To execute a program directly, use the PGM parameter to specify the program name:

jcl
1
2
3
4
//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).

Common System Programs

Program NameFunctionCommon Use
IEFBR14Do nothing programCreate, delete, or catalog datasets
SORT/ICEMANIBM Sort/MergeSort or merge datasets
IDCAMSAccess Method ServicesManage VSAM files and catalogs
IEBGENERData Set CopyCopy or upgrade sequential datasets
IEBCOPYPartitioned Data Set CopyCopy or compress partitioned datasets
IKJEFT01TSO Terminal MonitorExecute TSO commands in batch
DFSORTIBM DFSORTEnhanced sorting capabilities

Program Examples

IEFBR14 Example (Create a dataset)

jcl
1
2
3
//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)

jcl
1
2
3
4
5
//STEP2 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //SYSIN DD * LISTCAT ENTRIES('MY.DATASET.NAME') ALL /*

SORT Example (Sort a file)

jcl
1
2
3
4
5
6
7
8
//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) /*

Executing Procedures

The EXEC statement can also invoke a cataloged or in-stream procedure.

Using Procedures

To execute a procedure, you can use either of these formats:

jcl
1
2
//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.

Cataloged Procedures

  • Stored in a procedure library (PROCLIB)
  • Available to all jobs
  • Maintained by system administrators
  • More commonly used in production environments
  • Examples: IBM-supplied procedures like ASMHCL, COBUCL

Example of using a cataloged procedure:

jcl
1
2
3
//STEP1 EXEC ASMHCL, // PARM.ASM='NODECK,OBJECT', // PARM.LKED='LIST,MAP'

In-stream Procedures

  • Defined within the JCL stream
  • Available only to the job containing them
  • Useful for testing or job-specific procedures
  • Defined between PROC and PEND statements
  • Can be invoked multiple times in the same job

Example of defining and using an in-stream procedure:

jcl
1
2
3
4
5
6
//MYPROC PROC //STEP1 EXEC PGM=IEFBR14 //DD1 DD SYSOUT=* // PEND //* //RUNSTEP EXEC MYPROC

Procedure Example

This example shows a procedure definition and invocation:

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
//* 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.

EXEC Statement Parameters

The EXEC statement can include various parameters to control step execution and resource allocation.

PARM Parameter

Passes information to the program being executed:

Format:

jcl
1
PARM='parameter-string'

Examples:

jcl
1
2
//STEP1 EXEC PGM=MYPROG,PARM='DEBUG,TRACE' //STEP2 EXEC PGM=SORT,PARM='MSGDDN=MSGLST,EQUALS'
  • The PARM string can be up to 100 characters
  • If it contains special characters or spaces, it must be enclosed in quotes
  • The format of the PARM string depends on the program receiving it
  • For procedure steps, use PARM.stepname='value'

TIME Parameter

Specifies the maximum CPU time for the step:

Format:

jcl
1
TIME=(minutes,seconds) | TIME=minutes | TIME=1440 | TIME=NOLIMIT

Examples:

jcl
1
2
//STEP1 EXEC PGM=MYPROG,TIME=(5,30) //STEP2 EXEC PGM=LONGRUN,TIME=NOLIMIT
  • TIME=(5,30) specifies 5 minutes and 30 seconds
  • TIME=1440 (24 hours) or TIME=NOLIMIT disables time limit checking
  • The TIME parameter on the EXEC statement overrides the TIME parameter on the JOB statement for this step

REGION Parameter

Specifies the amount of virtual storage for the step:

Format:

jcl
1
REGION=valueK | valueM | 0K | 0M

Examples:

jcl
1
2
//STEP1 EXEC PGM=SMALLPGM,REGION=2M //STEP2 EXEC PGM=BIGPGM,REGION=0M
  • The REGION parameter on the EXEC statement overrides the REGION parameter on the JOB statement
  • REGION=0M or REGION=0K requests the maximum available region size
  • Actual available memory may be less due to system overhead

COND Parameter

Controls conditional execution based on previous steps' return codes:

Format:

jcl
1
2
3
4
COND=(code,operator) COND=((code1,operator1),(code2,operator2),...) COND=EVEN COND=ONLY

Examples:

jcl
1
2
3
4
//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))
OperatorMeaning
GTGreater than
GEGreater than or equal to
EQEqual to
NENot equal to
LTLess than
LELess 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."

  • COND=EVEN: Execute this step even if a previous step abended
  • COND=ONLY: Execute this step only if a previous step abended
  • Multiple conditions use OR logic (if any condition is true, bypass the step)
  • You can specify a specific step name: COND=(8,GT,STEP1)

Full EXEC Statement Examples

Here are some complete examples of EXEC statements for different scenarios.

Basic Program Execution

jcl
1
//STEP010 EXEC PGM=IEFBR14

Simple execution of the IBM utility program IEFBR14, which does nothing but return a completion code.

Program with Parameters and Resources

jcl
1
2
3
4
//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.

Conditional Execution

jcl
1
2
3
//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.

Procedure with Overrides

jcl
1
2
3
4
5
6
7
//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.

Complex Conditional Execution

jcl
1
2
3
4
5
6
//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).