MainframeMaster

JCL Tutorial

JCL Procedures

Progress0 of 0 lessons

Procedure Basics

A JCL procedure (or proc) is a pre-defined set of JCL statements that can be reused across multiple jobs. Procedures enhance productivity, reduce errors, and simplify maintenance by allowing common job steps to be written once and used repeatedly.

Benefits of Using Procedures

  • Reduces repetitive coding of common job sequences
  • Ensures consistency across jobs that perform similar functions
  • Simplifies maintenance (changes need to be made in only one place)
  • Hides complex JCL details from end users
  • Standardizes processing across an organization
  • Prevents JCL errors through code reuse
  • Allows for flexibility through parameter substitution

Types of Procedures

Cataloged Procedures

  • Stored in a procedure library
  • Available to all users
  • Created and maintained by system administrators
  • Can be called by any job with access to the library
  • Examples: IBM-supplied procedures like IEBGENER, ASMHCL, COBUCLG

In-stream Procedures

  • Defined within the JCL job stream
  • Available only to the job containing them
  • Defined between PROC and PEND statements
  • Must be defined before they are referenced
  • Useful for testing before cataloging
  • Suitable for job-specific procedures

Procedure Structure

A JCL procedure can contain most JCL statements including EXEC, DD, OUTPUT, and comment statements. It cannot contain a JOB statement, another PROC statement, or a null statement.

Basic Procedure Format

jcl
1
2
3
4
5
6
//procname PROC [parameter1=default1,parameter2=default2,...] //step1 EXEC PGM=program1 //DD1 DD ... //step2 EXEC PGM=program2 //DD2 DD ... // PEND

An in-stream procedure begins with a PROC statement and ends with a PEND statement. A cataloged procedure typically doesn't include the PROC and PEND statements in the library, although they may be shown in documentation.

PROC Statement

The PROC statement marks the beginning of a procedure and can define symbolic parameters with default values:

Format:

jcl
1
//procname PROC param1=value1,param2=value2,...

Examples:

jcl
1
2
3
//MYPROC PROC //SORTPROC PROC SORTIN=INPUT,SORTOUT=OUTPUT,PGM=SORT //COPYPROC PROC FROM=,TO=,SPACE=(TRK,(10,5))

The PROC statement can define parameters with or without default values. Parameters without default values must be provided when the procedure is executed.

PEND Statement

The PEND statement marks the end of a procedure definition:

Format:

jcl
1
// PEND

The PEND statement is only required for in-stream procedures and is not included in cataloged procedures stored in procedure libraries.

Procedure Content

A procedure typically contains one or more EXEC statements and associated DD statements. It may also contain:

  • Comment statements (starting with //*) - Provide documentation without affecting execution
  • OUTPUT statements - Define output processing options for SYSOUT datasets
  • SET statements - Define or modify symbolic parameters during procedure execution
  • IF/THEN/ELSE/ENDIF statements - Create conditional logic based on return codes or other conditions
  • INCLUDE statements - Incorporate other JCL segments from a library into the procedure

A procedure cannot contain:

  • JOB statements - These define job attributes and must be outside procedures
  • Another PROC statement - Nested procedures are not supported
  • Delimiter statements (//) - Null statements cannot be included in procedures
  • Nested procedures - A procedure cannot directly call another procedure (but a step can)

Creating and Using Procedures

Procedures can be defined in-stream or cataloged in a procedure library for broader use.

Creating an In-stream Procedure

An in-stream procedure is defined directly within the JCL job:

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
//MYJOB JOB (ACCT),'USER',CLASS=A //* //* DEFINE THE PROCEDURE //MYPROC PROC TYPE='MASTER',CLASS=A //STEP1 EXEC PGM=MYPROG //INPUT DD DSN=&TYPE..DATA,DISP=SHR //OUTPUT DD SYSOUT=&CLASS //REPORT DD SYSOUT=&CLASS // PEND //* //* EXECUTE THE PROCEDURE //STEP01 EXEC MYPROC //STEP02 EXEC MYPROC,TYPE='DETAIL',CLASS=B

In this example, the procedure MYPROC is defined with two parameters (TYPE and CLASS) and then executed twice with different parameter values.

Cataloging a Procedure

To catalog a procedure in a procedure library, you need to use a utility such as IEBUPDTE or submit the procedure to a specific procedure library:

jcl
1
2
3
4
5
6
7
8
9
10
11
12
//CATALOG JOB (ACCT),'USER',CLASS=A //STEP1 EXEC PGM=IEBUPDTE,PARM=NEW //SYSPRINT DD SYSOUT=* //SYSUT2 DD DSN=SYS1.PROCLIB,DISP=SHR //SYSIN DD * ./ ADD NAME=MYPROC,LIST=ALL //MYPROC PROC TYPE='MASTER',CLASS=A //STEP1 EXEC PGM=MYPROG //INPUT DD DSN=&TYPE..DATA,DISP=SHR //OUTPUT DD SYSOUT=&CLASS //REPORT DD SYSOUT=&CLASS /*

This job adds the procedure MYPROC to the system procedure library SYS1.PROCLIB. Note that the PEND statement is typically not included when cataloging a procedure.

Executing a Procedure

To execute a procedure, use the EXEC statement with the procedure name:

Format:

jcl
1
2
//stepname EXEC procname[,param1=value1,param2=value2,...] //stepname EXEC PROC=procname[,param1=value1,param2=value2,...]

Examples:

jcl
1
2
3
//STEP1 EXEC MYPROC //STEP2 EXEC MYPROC,TYPE='DETAIL' //STEP3 EXEC PROC=SORTPROC,SORTIN=MY.FILE,SORTOUT=MY.OUTPUT

The PROC= keyword is optional. Parameter values specified on the EXEC statement override the defaults defined in the procedure.

Symbolic Parameters

Symbolic parameters allow for flexibility in procedures by letting you substitute values when the procedure is executed.

Defining Symbolic Parameters

Symbolic parameters are defined on the PROC statement or with SET statements:

jcl
1
2
3
//MYPROC PROC A=1,B='ABC',C= // SET D=100 //STEP1 EXEC PGM=MYPROG,PARM='&A,&B'
  • Parameter A has a default value of 1
  • Parameter B has a default value of 'ABC' (quoted because it contains letters)
  • Parameter C is defined but has no default value (must be provided when executing)
  • Parameter D is defined using a SET statement with a value of 100

Using Symbolic Parameters

Symbolic parameters are referenced by prefixing their names with an ampersand (&):

jcl
1
2
3
4
//MYPROC PROC DSN='MY.DATASET',SPACE=(TRK,(10,5)) //STEP1 EXEC PGM=IEFBR14 //DD1 DD DSN=&DSN,DISP=(NEW,CATLG,DELETE), // SPACE=&SPACE,UNIT=SYSDA

In this example, the DSN and SPACE parameters are used within the DD statement. When executing the procedure, these values can be overridden.

Parameter Syntax Rules

  • Parameter names can be 1-7 characters (A-Z, 0-9, @, #, $) - Names must fit this format to be recognized
  • First character must be alphabetic or national (@, #, $) - Ensures valid identifier format
  • Case is significant - Parameters are typically uppercase in JCL for consistency
  • Values can be quoted or unquoted - Numeric values typically unquoted, text often quoted
  • Quoted values are required - For values containing special characters or spaces to ensure proper parsing
  • Double periods (..) - Used when a symbolic parameter is followed by a period in a dataset name
  • Example: DSN=&PREFIX..DATA - When PREFIX='MY', this resolves to MY.DATA

Special Handling of Periods

When a symbolic parameter is followed by a period in a dataset name, use double periods:

jcl
1
2
3
//MYPROC PROC PREFIX='MY' //STEP1 EXEC PGM=IEFBR14 //DD1 DD DSN=&PREFIX..DATA,DISP=SHR

In this example, if PREFIX is 'MY', the dataset name will be MY.DATA. The double period is needed because the first period is considered part of the parameter substitution.

Overriding Procedure Statements

You can override or add to statements in a procedure when you execute it.

Overriding EXEC Parameters

To override parameters on an EXEC statement within a procedure:

jcl
1
//STEP1 EXEC MYPROC,PARM.STEP1='NEW VALUE',TIME.STEP2=5

This overrides the PARM parameter for STEP1 and the TIME parameter for STEP2 within the MYPROC procedure.

Overriding DD Statements

To override a DD statement in a procedure, specify the procedure step name and the ddname:

jcl
1
//STEP1.DD1 DD DSN=NEW.DATASET,DISP=SHR

This overrides the DD1 statement in STEP1 of the procedure. The entire DD statement is replaced, not just individual parameters.

Adding DD Statements

To add a DD statement to a procedure step:

jcl
1
//STEP1.NEWDD DD DSN=EXTRA.DATASET,DISP=SHR

This adds a new DD statement named NEWDD to STEP1 of the procedure.

Nullifying DD Statements

To nullify (ignore) a DD statement in a procedure:

jcl
1
//STEP1.DD1 DD DUMMY

This replaces the DD1 statement in STEP1 with a DUMMY, effectively nullifying it.

Override Rules

  • Overrides must appear after the EXEC statement - This ensures the procedure is properly invoked first
  • Overrides must be in the same order as steps - System processes steps sequentially and needs matching order
  • Cannot override non-existent steps/DDs - Attempting to do so will result in JCL errors
  • Cannot add new steps to a procedure - Only existing steps can be modified; new steps must be added to the job
  • Symbolic parameters resolved first - Parameter substitution occurs before overrides are applied

Common Procedure Examples

Here are some examples of commonly used procedures.

Simple Copy Procedure

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//COPYPROC PROC FROM=,TO=,SPACE=(TRK,(10,5)) //* //* PROCEDURE TO COPY ONE DATASET TO ANOTHER //* //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,UNIT=SYSDA, // DCB=(RECFM=FB,LRECL=80,BLKSIZE=27920) // PEND //* EXECUTION EXAMPLE: //STEP1 EXEC COPYPROC,FROM='MY.INPUT.FILE',TO='MY.OUTPUT.FILE', // SPACE=(CYL,(2,1))

This procedure copies one dataset to another using IEBGENER, with parameters for input/output files and space allocation.

Sort Procedure

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//SORTPROC PROC SORTIN='SORTIN',SORTOUT='SORTOUT', // SORTWK01='SORTWK01',SORTWK02='SORTWK02', // SORTWK03='SORTWK03',SORTCNTL='SORTCNTL' //* //* PROCEDURE TO SORT DATA //* //SORT EXEC PGM=SORT //SYSOUT DD SYSOUT=* //SORTIN DD DSN=&SORTIN,DISP=SHR //SORTOUT DD DSN=&SORTOUT,DISP=(NEW,CATLG,DELETE), // SPACE=(CYL,(5,2)),UNIT=SYSDA, // DCB=(RECFM=FB,LRECL=80,BLKSIZE=27920) //SORTWK01 DD DSN=&&SORTWK01,DISP=(NEW,DELETE), // SPACE=(CYL,(10,5)),UNIT=SYSDA //SORTWK02 DD DSN=&&SORTWK02,DISP=(NEW,DELETE), // SPACE=(CYL,(10,5)),UNIT=SYSDA //SORTWK03 DD DSN=&&SORTWK03,DISP=(NEW,DELETE), // SPACE=(CYL,(10,5)),UNIT=SYSDA //SYSIN DD DSN=&SORTCNTL,DISP=SHR // PEND //* EXECUTION EXAMPLE: //STEP1 EXEC SORTPROC,SORTIN='MY.DATA',SORTOUT='MY.SORTED.DATA' //SORT.SYSIN DD * SORT FIELDS=(1,10,CH,A) /*

This procedure performs a sort operation using the SORT utility. It includes parameters for input/output files and work files, and allows for overriding the SYSIN DD statement to provide sort control statements.

Compile, Link, and Execute Procedure

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//COBCLG PROC SYSLIB='SYS1.COBLIB', // SOURCE='SOURCE.COBOL',LOADLIB='USER.LOADLIB', // PARM.COB='NOOPT,OBJECT,NODYNAM', // PARM.LKED='LIST,MAP,LET', // REGION.COB=2M,REGION.LKED=2M,REGION.GO=4M //* //* PROCEDURE TO COMPILE, LINK, AND EXECUTE A COBOL PROGRAM //* //COB EXEC PGM=IKFCBL00,REGION=®ION.COB, // PARM='&PARM.COB' //SYSPRINT DD SYSOUT=* //SYSUT1 DD UNIT=SYSDA,SPACE=(CYL,(1,1)) //SYSUT2 DD UNIT=SYSDA,SPACE=(CYL,(1,1)) //SYSUT3 DD UNIT=SYSDA,SPACE=(CYL,(1,1)) //SYSUT4 DD UNIT=SYSDA,SPACE=(CYL,(1,1)) //SYSLIN DD DSN=&&LOADSET,DISP=(MOD,PASS), // UNIT=SYSDA,SPACE=(TRK,(3,3)) //SYSIN DD DSN=&SOURCE,DISP=SHR //* //LKED EXEC PGM=IEWL,REGION=®ION.LKED, // PARM='&PARM.LKED',COND=(4,LT,COB) //SYSPRINT DD SYSOUT=* //SYSUT1 DD UNIT=SYSDA,SPACE=(CYL,(1,1)) //SYSLIB DD DSN=&SYSLIB,DISP=SHR //SYSLMOD DD DSN=&LOADLIB(PROGRAM),DISP=SHR //SYSLIN DD DSN=&&LOADSET,DISP=(OLD,DELETE) // DD DDNAME=SYSIN //* //GO EXEC PGM=*.LKED.SYSLMOD,REGION=®ION.GO, // COND=((4,LT,COB),(4,LT,LKED)) //STEPLIB DD DSN=&LOADLIB,DISP=SHR //SYSOUT DD SYSOUT=* //SYSUDUMP DD SYSOUT=* // PEND //* EXECUTION EXAMPLE: //STEP1 EXEC COBCLG,SOURCE='MY.COBOL.PROGRAM' //GO.INPUT DD DSN=MY.INPUT.FILE,DISP=SHR //GO.OUTPUT DD SYSOUT=*

This procedure compiles, links, and executes a COBOL program. It includes parameters for source code location, load library, and options for each step. It also uses conditional execution to skip steps if previous steps fail.

Best Practices for Procedures

Follow these guidelines when creating and using JCL procedures.

Procedure Design

  • Keep procedures simple and focused - Each procedure should handle one specific task or function
  • Use meaningful parameter names - Names like INFILE or REPORT are clearer than A or X
  • Provide default values - Include sensible defaults for optional parameters to minimize errors
  • Include thorough documentation - Comments should explain purpose, parameters, and usage
  • Use consistent naming conventions - Standard naming makes procedures easier to understand and manage
  • Test thoroughly before cataloging - Verify all parameter combinations and overrides work properly
  • Consider backward compatibility - Changes should not break existing jobs that use the procedure

Procedure Usage

  • Understand the procedure - Review the procedure code and documentation before using it
  • Review default parameter values - Know what defaults will be used if not explicitly overridden
  • Only override what needs changing - Rely on defaults for parameters that don't need modification
  • Be aware of conditional execution - Understand how COND parameters affect step execution
  • Provide all required parameters - Parameters without defaults must be supplied when executing
  • Use appropriate DD overrides - Follow the stepname.ddname format for overriding DD statements
  • Document procedure usage - Add comments explaining parameter choices and overrides

Common Procedure Pitfalls

ProblemRecommendation
Missing required parametersDocument required parameters clearly and check for them
Hardcoded valuesUse symbolic parameters for values that might need to change
Too many parametersLimit parameters to what's truly needed for flexibility
Unclear namingUse descriptive names for procedures and parameters
Inflexible proceduresDesign procedures with reasonable customization options
Inadequate documentationInclude clear comments explaining purpose and usage
Symbolic parameter conflictsUse unique parameter names to avoid conflicts