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 theINFILE
andOUTFILE
symbolic parameters.
Practical Exercise
Exercise 1: Create and Use a Procedure
-
Create a Procedure:
- Create a procedure named
SORTPROC
that sorts a data set using theSORT
utility. - Use symbolic parameters for the input and output data sets.
- Create a procedure named
-
Use the Procedure:
- Write a JCL job that uses the
SORTPROC
procedure to sort a data set namedMY.INPUT.DATASET
and output the sorted data toMY.SORTED.DATASET
.
- Write a JCL job that uses the
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.
JCL (Job Control Language) Course
Module 1: Introduction to JCL
Module 2: JCL Statements and Syntax
Module 3: Data Definition (DD) Statements
Module 4: Procedures and Symbolic Parameters
Module 5: Advanced JCL Concepts
- Conditional Processing
- JCLLIB and INCLUDE Statements
- Generation Data Groups (GDGs)
- Restart and Checkpoint
Module 6: Error Handling and Debugging
- Common JCL Errors
- Interpreting JCL Error Messages
- Debugging Techniques
- Using JES2/JES3 for Troubleshooting