In this module, we will explore the concept of procedures in JCL (Job Control Language). Procedures, often referred to as PROCs, are a powerful feature in JCL that allow for the reuse of JCL code, making job management more efficient and less error-prone. By the end of this module, you will understand what procedures are, how to create them, and how to use them in your JCL jobs.
What are Procedures?
Procedures in JCL are predefined sets of JCL statements that can be included in a job. They are similar to functions or subroutines in other programming languages. Procedures help in:
- Reducing redundancy by reusing common JCL code.
- Simplifying job maintenance and updates.
- Enhancing readability and organization of JCL jobs.
Key Concepts
- Procedure Definition
A procedure is defined in a separate member of a partitioned data set (PDS) or in-stream within a JCL job. The procedure contains a series of JCL statements that can be invoked by a single EXEC statement in the main JCL job.
- Invoking Procedures
To use a procedure in a JCL job, you use the EXEC statement with the PROC
keyword followed by the procedure name.
- Parameters
Procedures can accept parameters, allowing for customization and flexibility. These parameters are known as symbolic parameters and can be overridden when the procedure is invoked.
Basic Structure of a Procedure
A procedure typically includes the following components:
- PROC Statement: Marks the beginning of the procedure.
- JCL Statements: The body of the procedure containing the JCL code.
- PEND Statement: Marks the end of the procedure (optional if the procedure is in-stream).
Example of a Simple Procedure
Let's look at a simple example of a procedure that copies data from one data set to another.
Procedure Definition (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
Main JCL Job Using the Procedure:
//MYJOB JOB (ACCT),'COPY JOB',CLASS=A,MSGCLASS=X //STEP1 EXEC COPYPROC,INFILE=INPUT.DATA,OUTFILE=OUTPUT.DATA
Explanation:
- COPYPROC: The name of the procedure.
- STEP1: The step within the procedure that executes the IEBGENER program.
- INFILE and OUTFILE: Symbolic parameters that will be replaced by actual data set names when the procedure is invoked.
Practical Exercise
Exercise 1: Creating and Using a Procedure
Task: Create a procedure that sorts a data set and use it in a JCL job.
Procedure Definition (SORTPROC):
//SORTPROC PROC //SORTSTEP 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,4,CH,A) /*
Main JCL Job Using the Procedure:
//SORTJOB JOB (ACCT),'SORT JOB',CLASS=A,MSGCLASS=X //STEP1 EXEC SORTPROC,INFILE=INPUT.DATA,OUTFILE=OUTPUT.DATA
Solution Explanation:
- SORTPROC: Defines a procedure named SORTPROC.
- SORTSTEP: Executes the SORT program.
- INFILE and OUTFILE: Symbolic parameters for input and output data sets.
- SORTJOB: A JCL job that uses the SORTPROC procedure to sort data from INPUT.DATA to OUTPUT.DATA.
Common Mistakes and Tips
- Incorrect Parameter Names: Ensure that the symbolic parameter names in the procedure match those used in the EXEC statement.
- Missing PEND Statement: If the procedure is defined in-stream, do not forget the PEND statement to mark the end of the procedure.
- Parameter Overrides: When overriding parameters, ensure the correct syntax and values are used.
Conclusion
In this module, we introduced the concept of procedures in JCL, their structure, and how to use them effectively. Procedures help in reusing JCL code, making job management more efficient. In the next module, we will delve deeper into creating and using procedures, including more advanced features like symbolic parameters and parameter overrides.
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