MainframeMaster

JCL Tutorial

Cataloged Procedures in JCL

Creating reusable JCL components for standardized batch processing

Progress0 of 0 lessons

What are Cataloged Procedures?

Cataloged procedures are pre-written, reusable collections of JCL statements stored in a system library. They serve as templates for common processing tasks, allowing multiple jobs to use the same standardized JCL without having to duplicate the code in each job.

Key benefits of cataloged procedures include:

  • Standardization of common processing tasks across an organization
  • Reduced maintenance by centralizing JCL for common operations
  • Simplified job streams by abstracting complex JCL into simple procedure calls
  • Improved reliability through use of tested, optimized JCL
  • Enforcement of organizational standards and best practices

Types of Procedures

Cataloged Procedures

Stored permanently in a procedure library and available to all jobs

In-stream Procedures

Defined within a job stream and only available to that job

While both types of procedures serve the same purpose and follow the same syntax rules, this tutorial focuses primarily on cataloged procedures that are stored in procedure libraries.

Procedure Libraries

Cataloged procedures are stored in specialized libraries that the system searches when a procedure is referenced in a job. Common procedure libraries include:

  • SYS1.PROCLIB - System-provided procedures
  • SYS1.PROC - Additional system procedures
  • [HLQ].PROCLIB - Organization-specific procedure libraries

The system searches these libraries in a predefined order when looking for a procedure. You can specify additional procedure libraries for a specific job using the JCLLIB statement:

jcl
1
2
//MYJOB JOB (ACCT),'MY JOB',CLASS=A // JCLLIB ORDER=(USER.PROCLIB,DEPT.PROCLIB)

The JCLLIB statement must appear after the JOB statement but before any EXEC statements that reference procedures. The system searches the libraries in the order specified.

Creating a Cataloged Procedure

A cataloged procedure consists of JCL statements that define one or more job steps. These statements are stored as a member in a procedure library.

Procedure Structure

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//MYPROC PROC P1='DEFAULT1',P2='DEFAULT2' //*-------------------------------------------------- //* This procedure does something important //*-------------------------------------------------- //STEP1 EXEC PGM=PROG1,PARM='&P1' //STEPLIB DD DSN=MY.LOADLIB,DISP=SHR //INPUT DD DSN=MY.INPUT.FILE,DISP=SHR //OUTPUT DD DSN=MY.&P2..FILE, // DISP=(NEW,CATLG,DELETE), // SPACE=(CYL,(10,5)), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=27920) //SYSOUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSIN DD DUMMY //*-------------------------------------------------- //STEP2 EXEC PGM=PROG2,COND=(0,NE,STEP1) //INPUT DD DSN=MY.&P2..FILE,DISP=SHR //OUTPUT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //*-------------------------------------------------- // PEND

Key Components of a Procedure

  • PROC Statement - Marks the beginning of the procedure and optionally defines symbolic parameters
  • Comments - Document the purpose and usage of the procedure
  • EXEC Statements - Define each step in the procedure
  • DD Statements - Define the data resources needed by each step
  • PEND Statement - Marks the end of the procedure

Procedure Naming Rules

  • Must follow standard JCL naming conventions (1-8 characters, starting with A-Z, @, #, or $)
  • Name must be unique within the procedure library
  • Should follow organizational naming standards for clarity and consistency

Using a Cataloged Procedure

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

jcl
1
2
3
4
5
6
//MYJOB JOB (ACCT),'MY JOB',CLASS=A //*-------------------------------------------------- //* Execute the cataloged procedure MYPROC //*-------------------------------------------------- //STEP01 EXEC MYPROC //

Passing Parameters to a Procedure

You can override the default values of symbolic parameters when executing a procedure:

jcl
1
2
3
//MYJOB JOB (ACCT),'MY JOB',CLASS=A //STEP01 EXEC MYPROC,P1='CUSTOM1',P2='CUSTOM2' //

This will replace the default parameter values in the procedure with the specified custom values.

Overriding Procedure Statements

When executing a procedure, you can override or add to the statements within it. This allows for customization while still leveraging the standardized procedure.

Overriding DD Statements

To override a DD statement in a procedure, include a DD statement with the qualified name stepname.ddname:

jcl
1
2
3
4
5
//MYJOB JOB (ACCT),'MY JOB',CLASS=A //STEP01 EXEC MYPROC //STEP1.INPUT DD DSN=MY.CUSTOM.INPUT,DISP=SHR //STEP2.OUTPUT DD SYSOUT=A,DEST=REMOTE1 //

Important: You must use the step name as defined in the procedure, not the name of the EXEC statement in your job that calls the procedure.

Adding DD Statements

You can add new DD statements to a procedure step using the same stepname.ddname syntax:

jcl
1
2
3
4
//MYJOB JOB (ACCT),'MY JOB',CLASS=A //STEP01 EXEC MYPROC //STEP1.EXTRA DD DSN=MY.EXTRA.FILE,DISP=SHR //

Overriding EXEC Parameters

You can override parameters on the EXEC statement in a procedure:

jcl
1
2
3
//MYJOB JOB (ACCT),'MY JOB',CLASS=A //STEP01 EXEC MYPROC,REGION.STEP1=8M,TIME.STEP2=10 //

In this example, we override the REGION parameter for STEP1 and the TIME parameter for STEP2.

Complex Procedure Example with Overrides

Let's look at a more comprehensive example:

Procedure Definition

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
//DBLOAD PROC ENV='TEST',LOADLIB='SYS1.DB2.LOADLIB' //*-------------------------------------------------- //* Database Load Procedure //* Parameters: //* ENV - Environment (TEST/PROD) //* LOADLIB - Load library for DB2 programs //*-------------------------------------------------- //UNLOAD EXEC PGM=DSNUTILB,REGION=4M //STEPLIB DD DSN=&LOADLIB,DISP=SHR //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //DATASET DD DSN=&ENV..DATA.EXTRACT,DISP=SHR //SYSIN DD * UNLOAD TABLESPACE DSN8D81A.DSN8S81E /* //*-------------------------------------------------- //SORT EXEC PGM=SORT,COND=(4,LT,UNLOAD) //SORTIN DD DSN=&ENV..DATA.EXTRACT,DISP=SHR //SORTOUT DD DSN=&ENV..DATA.SORTED, // DISP=(NEW,CATLG,DELETE), // SPACE=(CYL,(50,25),RLSE) //SYSIN DD * SORT FIELDS=(1,10,CH,A) /* //SYSOUT DD SYSOUT=* //*-------------------------------------------------- //LOAD EXEC PGM=DSNUTILB,COND=(4,LT,SORT) //STEPLIB DD DSN=&LOADLIB,DISP=SHR //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //DATASET DD DSN=&ENV..DATA.SORTED,DISP=SHR //SYSIN DD * LOAD TABLESPACE DSN8D81A.DSN8S81F /* // PEND

Using the Procedure with Overrides

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//PRODLOAD JOB (ACCT),'DB LOAD',CLASS=A //*-------------------------------------------------- //* Production database load with overrides //*-------------------------------------------------- //LOADJOB EXEC DBLOAD,ENV='PROD', // REGION.LOAD=8M //* Override the standard extract dataset //UNLOAD.DATASET DD DSN=PROD.SPECIAL.EXTRACT,DISP=SHR //* Add a report DD to the LOAD step //LOAD.REPORT DD SYSOUT=A //* Override the SYSIN for the LOAD step //LOAD.SYSIN DD * LOAD TABLESPACE PRODDB.CUSTDATA REPLACE LOG NO /*

In this example, we're:

  • Setting the ENV parameter to 'PROD'
  • Increasing the REGION for the LOAD step to 8M
  • Using a different input dataset for the UNLOAD step
  • Adding a new REPORT DD to the LOAD step
  • Completely replacing the SYSIN for the LOAD step

Nested Procedures

A procedure can execute another procedure, creating a hierarchy of nested procedures. This allows for modular construction of complex job streams.

jcl
1
2
3
4
5
6
7
8
9
10
//MASTERP PROC ENV='TEST' //*-------------------------------------------------- //* Master procedure that calls other procedures //*-------------------------------------------------- //EXTRACT EXEC EXTRACT,ENV=&ENV //VALIDATE EXEC VALIDATE,ENV=&ENV, // COND=(0,NE,EXTRACT.EXTR) //REPORT EXEC REPORT,ENV=&ENV, // COND=(0,NE,VALIDATE.CHECK) // PEND

Most systems limit procedure nesting to 15 levels. Careful design is needed for deeply nested procedures to ensure maintainability.

When using nested procedures, parameter passing flows down through the levels. You can set parameters at the top level that affect all nested procedure calls.

Best Practices for Cataloged Procedures

Thorough Documentation

Include clear comments explaining the procedure's purpose, parameters, requirements, and usage examples.

Sensible Parameter Defaults

Provide meaningful default values that work in common scenarios, making the procedure easier to use.

Error Handling

Include appropriate COND parameters to handle errors and provide useful return codes.

Consistent Naming Conventions

Use consistent, descriptive names for procedures, steps, and parameters that follow organizational standards.

Version Control

Maintain version control for procedures and document changes to ensure traceability.

Modular Design

Design procedures to be modular and focused on specific tasks to maximize reusability.

Common Challenges with Cataloged Procedures

Practical Exercise

Building a File Processing Procedure

Create a cataloged procedure that provides a standardized way to process data files. The procedure should:

  1. Accept parameters for environment (DEV/TEST/PROD), file type, and processing options
  2. Include steps for validation, processing, and reporting
  3. Handle different types of input files (fixed or variable length)
  4. Implement appropriate error handling between steps
  5. Generate both detailed and summary reports

Then, create a job that calls this procedure with various overrides to demonstrate its flexibility.

Consider how you would:

  • Document the procedure for users who may not be familiar with its internals
  • Handle potential errors in each step
  • Enable customization while enforcing standards
  • Test the procedure thoroughly

Try writing the JCL yourself, then compare with a sample solution in a future lesson.

Test Your Knowledge

1. What is the primary purpose of cataloged procedures in JCL?

  • To reduce disk space usage
  • To improve system performance
  • To provide reusable, standardized JCL for common tasks
  • To secure sensitive JCL code

2. Where are cataloged procedures typically stored?

  • In JES spool datasets
  • In system procedure libraries like SYS1.PROCLIB
  • In user home directories
  • In temporary datasets

3. Which statement marks the end of a procedure definition?

  • END
  • PEND
  • PROC END
  • //*END PROC

4. How do you override a DD statement in a procedure?

  • By adding an OVERRIDE statement
  • By coding a DD statement with the same name in the calling job
  • Using procstepname.ddname syntax in the calling job as an override
  • By modifying the procedure library directly

5. What happens if symbolic parameters in a procedure are not given values when the procedure is called?

  • The job fails with a JCL error
  • The parameters receive their default values if specified, otherwise null
  • The system prompts the user for values
  • The procedure is skipped entirely

Frequently Asked Questions