In this section, we will delve into the creation and usage of procedures in JCL. Procedures, often referred to as PROCs, are reusable sets of JCL statements that can be invoked by multiple jobs, making your JCL code more modular and easier to maintain.

What is a Procedure?

A procedure in JCL is a pre-defined set of JCL statements that can be included in a job. Procedures help in reducing redundancy and improving the maintainability of JCL scripts. They are stored in partitioned data sets (PDS) and can be invoked using the EXEC statement.

Key Concepts:

  • Procedure (PROC): A reusable set of JCL statements.
  • EXEC Statement: Used to call a procedure.
  • Symbolic Parameters: Variables within procedures that can be overridden at execution time.

Creating a Procedure

To create a procedure, you need to define it in a member of a partitioned data set (PDS). Here is a simple example of a procedure that copies data from one data set to another:

Example Procedure (COPYPROC)

//COPYPROC PROC
//STEP1    EXEC PGM=IEBGENER
//SYSPRINT DD SYSOUT=*
//SYSIN    DD DUMMY
//SYSUT1   DD DSN=&INFILE,DISP=SHR
//SYSUT2   DD DSN=&OUTFILE,DISP=(NEW,CATLG,DELETE),
//            SPACE=(TRK,(1,1)),UNIT=SYSDA

Explanation:

  • COPYPROC PROC: Defines the procedure named COPYPROC.
  • STEP1 EXEC PGM=IEBGENER: Executes the IEBGENER utility program.
  • SYSPRINT DD SYSOUT=*: Directs the output to the system output.
  • SYSIN DD DUMMY: Specifies a dummy data set for SYSIN.
  • SYSUT1 DD DSN=&INFILE,DISP=SHR: Defines the input data set using a symbolic parameter &INFILE.
  • SYSUT2 DD DSN=&OUTFILE,DISP=(NEW,CATLG,DELETE), SPACE=(TRK,(1,1)),UNIT=SYSDA: Defines the output data set using a symbolic parameter &OUTFILE.

Using a Procedure

To use a procedure in a JCL job, you need to call it using the EXEC statement and provide values for any symbolic parameters.

Example JCL Job Using COPYPROC

//MYJOB    JOB (ACCT),'COPY JOB',CLASS=A,MSGCLASS=A
//STEP1    EXEC COPYPROC,INFILE=MY.INPUT.DATASET,OUTFILE=MY.OUTPUT.DATASET

Explanation:

  • MYJOB JOB (ACCT),'COPY JOB',CLASS=A,MSGCLASS=A: Defines the job.
  • STEP1 EXEC COPYPROC,INFILE=MY.INPUT.DATASET,OUTFILE=MY.OUTPUT.DATASET: Executes the COPYPROC procedure, providing values for the INFILE and OUTFILE symbolic parameters.

Practical Exercise

Exercise 1: Create and Use a Procedure

  1. Create a Procedure:

    • Create a procedure named SORTPROC that sorts a data set using the SORT utility.
    • Use symbolic parameters for the input and output data sets.
  2. Use the Procedure:

    • Write a JCL job that uses the SORTPROC procedure to sort a data set named MY.INPUT.DATASET and output the sorted data to MY.SORTED.DATASET.

Solution:

SORTPROC Procedure

//SORTPROC PROC
//STEP1    EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTIN   DD DSN=&INFILE,DISP=SHR
//SORTOUT  DD DSN=&OUTFILE,DISP=(NEW,CATLG,DELETE),
//            SPACE=(TRK,(1,1)),UNIT=SYSDA
//SYSIN    DD *
  SORT FIELDS=(1,10,CH,A)
/*

JCL Job Using SORTPROC

//MYJOB    JOB (ACCT),'SORT JOB',CLASS=A,MSGCLASS=A
//STEP1    EXEC SORTPROC,INFILE=MY.INPUT.DATASET,OUTFILE=MY.SORTED.DATASET

Explanation:

  • SORTPROC PROC: Defines the procedure named SORTPROC.
  • STEP1 EXEC PGM=SORT: Executes the SORT utility program.
  • SYSOUT DD SYSOUT=*: Directs the output to the system output.
  • SORTIN DD DSN=&INFILE,DISP=SHR: Defines the input data set using a symbolic parameter &INFILE.
  • SORTOUT DD DSN=&OUTFILE,DISP=(NEW,CATLG,DELETE), SPACE=(TRK,(1,1)),UNIT=SYSDA: Defines the output data set using a symbolic parameter &OUTFILE.
  • *SYSIN DD : Provides the SORT control statements directly in the JCL.

Common Mistakes and Tips

Common Mistakes:

  • Forgetting to Define Symbolic Parameters: Ensure all symbolic parameters used in the procedure are defined and provided values when the procedure is called.
  • Incorrect DISP Parameters: Ensure the DISP parameters are correctly set to avoid data set conflicts.

Tips:

  • Use Descriptive Names: Use descriptive names for procedures and symbolic parameters to make the JCL more readable.
  • Modularize Your JCL: Break down complex JCL jobs into smaller, reusable procedures to improve maintainability.

Conclusion

In this section, we learned how to create and use procedures in JCL. Procedures help in making your JCL scripts modular and easier to maintain. We covered the basics of defining a procedure, using symbolic parameters, and invoking procedures in a JCL job. By practicing the provided exercise, you should now be comfortable creating and using procedures in your JCL jobs.

© Copyright 2024. All rights reserved