Skip to main content

JCL Procedures – Introduction

In large-scale batch processing systems, Job Control Language (JCL) is used to manage the execution of programs on IBM mainframes. To avoid writing repetitive code and to make JCL more modular, procedures (PROCs) are used.

A procedure is a reusable group of JCL statements (steps) that can be included in one or more jobs. This improves readability, reduces redundancy, and allows centralized maintenance. JCL supports both in-stream and cataloged procedures, and provides mechanisms to pass parameters, override defaults, and conditionally execute steps inside the procedure.

JCL supports two types:

  • In-stream Procedure: Defined within the job itself.
  • Cataloged Procedure: Stored externally in a system library (PDS/PDSE), referenced by name in jobs.

Benefits of Using Procedures

  • Modularity: Isolate common steps and reuse them.
  • Maintainability: Update logic in one place (especially for cataloged PROCs).
  • Reusability: Same logic can be used in multiple jobs.
  • Readability: Main JCL becomes shorter and more focused.
  • Standardization: Ensures consistent execution across environments.

In-stream Procedures

An in-stream procedure is embedded within the same JCL job where it is used. It starts with a PROC statement and ends with a PEND.

IBM Docs - In stream procedure

Syntax

//procName PROC
//STEP1 EXEC PGM=MYPGM
//DD1 DD DSN=MY.DATASET,DISP=SHR
//PEND

//STEPX EXEC PROC=procName
//STEPY EXEC procName

Key Points

  • Defined inside the JCL using PROC and PEND.
  • Can be used only in the same job.
  • The procedure name is mandatory.
  • Must be defined before the step that uses it.
  • Only one level of in-stream PROC is allowed (nesting not permitted).

Cataloged Procedures

A cataloged procedure is saved in a partitioned dataset (like a PDS) and can be referenced by multiple jobs. It allows code reuse across JCL jobs.

IBM Docs - Cataloged Procedure

Example

Cataloged PROC stored in a library (e.g., MY.PROCLIB):

//MYPROC PROC
//STEP1 EXEC PGM=PROG1
//DD1 DD DSN=INPUT.DATA1,DISP=SHR
//STEP2 EXEC PGM=PROG2
//DD2 DD DSN=INPUT.DATA2,DISP=SHR

Calling it in a JCL:

//MYJOB   JOB ...
// JCLLIB ORDER=MY.PROCLIB
//STEPX EXEC MYPROC
//STEPY EXEC PROC=MYPROC

Catalog proc Key Points

  • Stored externally and referenced using EXEC.
  • JCLLIB must be used to specify the library path.
  • A PROC statement is optional.
  • A PEND statement is not required.
  • Procedure name defaults to the member name in the library.

Symbolic Parameters (Procedure Symbols)

Symbolic parameters allow values to be passed to a PROC at execution time, making the procedure dynamic and flexible.

IBM Docs - Symbols in PROC

Defining Defaults in PROC

//MYPROC PROC LIB1=DEFAULT.DATA
//STEP1 EXEC PGM=MYPGM
//IN1 DD DSN=&LIB1,DISP=SHR

If the caller provides LIB1=NEW.DATA, it will override DEFAULT.DATA.

Calling and Overriding

//STEPX EXEC PROC=MYPROC, LIB1=NEW.DATA

Precedence Rules

  1. EXEC Parameter (highest) → Overrides everything else
  2. Default in PROC → Used if no override given
  3. SET Statement (lowest) → Ignored if already defined in PROC

Overriding DD Statements in PROCs

When a PROC contains DD statements, they can be overridden, added, or removed from the calling JCL using the format:

IBM Docs - Overide DD Statements

//callingStepName.ddname DD ...

Common Use Cases

  • Override existing dataset:

    //STEP1.INPUT DD DSN=NEW.DATA,DISP=SHR

This overrides INPUT DD used in STEP1 of the PROC.

  • Add new DD not in PROC:

    //STEP1.LOG DD SYSOUT=*

This adds LOG DD used in STEP1 of the PROC.

  • Remove a DD (null override):

    //STEP1.INPUT DD DUMMY

This effectively disables INPUT in STEP1.


REFERBACK in PROCs

REFERBACK allows one DD to refer back to the attributes (like DCB, SPACE, etc.) of another DD.

When used in a calling JCL for a step inside a PROC, the format becomes:

*.callingStep.procStep.ddname

This ensures JCL knows exactly where to look inside the procedure structure.

For more details on referback please refer to actual referback handsout


Using COND in PROCs

PROCs can contain conditional logic using the COND parameter to control whether a step runs based on return codes (RC).

Inside the PROC

//procName PROC
//.....
//STEP2 EXEC PGM=PGM2, COND=(4,LT)

Skips STEP2 if any previous step has RC < 4.

Outside the PROC

The calling EXEC statement can include a COND parameter to control individual steps or override if present in PROC

COND.[procstep]=((rc,operator,[procstep]))

Considering about example, let say we want to skips STEP2 inside procName if any previous step have RC < 5.

//STEPXX EXEC PROC=procName,COND.STEP2=(5,LT)

For more details on Conditions please refer to actual conditions handsout