Procedures (PROCs)
A procedure is a reusable set of JCL statements defined once and called multiple times within a job or across various jobs.
Procedures are used to simplify job processing by allowing frequently used sets of JCL statements to be stored in a library and called whenever required. The EXEC statement is used to call and execute a procedure at the step level.
The main advantage of the procedures are -
- Reusing the same JCL statements to produce different outputs with different inputs.
- Reducing the repetitive coding.
Syntax -
Calling PROC -
//[step-name] EXEC PROC=proc-name[,parameters [comments]]
or
//[step-name] EXEC proc-name[,parameters [comments]]
PROC Definition -
//proc-name PROC
- Procedure Name (proc-name) - proc-name specifies the user-defined 8 character procedure name. proc-name should be the same in PROC definition and PROC calling.
- Operation - Operation is PROC and is optional.
- Parameters - Parameters are used to pass the overriding value to the procedure. All the parameters are optional. If the parameter field is coded, there should be one blank after the PROC operation.
- Comment - Comment used to make a note of the current statement. The comment field should be preceded with a blank after the parameters.
Procedure Types -
Procedures are of two types based on their definition and usage -
- Instream procedure.
- Cataloged procedure.
Instream procedure
An instream procedure is a type of procedure that is defined within the same JCL where it calls. The instream procedure won't validate syntax errors until an EXEC statement calls it. A maximum of 15 instream procedures can be coded in any job.
Syntax -
PROC Defintion -
//proc-name PROC
//jcl-statements
// PEND
Calling PROC -
//step-name EXEC proc-name
or
//step-name EXEC PROC=proc-name
Example - JCL to create two PS files.
//MTHUSERC JOB (MTH1234),'PAWAN Y',
// CLASS=B,NOTIFY=&SYSUID
//*
//STEP10 EXEC PGM=IEFBR14
//DD1 DD DSN=MATEPK.IEFBR14.PSFILE1,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(TRK,(3,2),RLSE),
// UNIT=SYSDA,VOLUME=SER=DEVHD4,
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
//*
//STEP20 EXEC PGM=IEFBR14
//DD1 DD DSN=MATEPK.IEFBR14.PSFILE2,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(TRK,(3,2),RLSE),
// UNIT=SYSDA,VOLUME=SER=DEVHD4,
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
Same JCL with instream proc -
//MTHUSERC JOB (MTH1234),'PAWAN Y',
// CLASS=B,NOTIFY=&SYSUID
//* Instream PROC definition
//CREATEPS PROC
//STEPA EXEC PGM=IEFBR14
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSDUMP DD SYSOUT=*
//DD1 DD DSN=&PSNAME,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(TRK,(3,2),RLSE),
// UNIT=SYSDA,VOLUME=SER=DEVHD4,
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
// PEND
//* Instream PROC calling
//STEP10 EXEC CREATEPS,PSNAME=MATEPK.IEFBR14.PSFILE1
//STEP20 EXEC CREATEPS,PSNAME=MATEPK.IEFBR14.PSFILE2
Cataloged procedure
The procedure defined outside of the JCL is called as cataloged procedure. A maximum of 255 procedures can be coded in a single JCL.
Cataloged procedures are defined outside of the JCL and maintained independently of any particular JCL. The library can be a personal or system library of type PDS/PDSE. The library should be coded in JCL with PROCLIB/JCLLIB statement to call procedure.
Syntax -
PROC Defintion -
//proc-name PROC
//jcl-statements
Calling PROC -
//step-name JCLLIB ORDER=(cataloged-procedure-library) //*mandatory
//*
//step-name EXEC proc-name
or
//step-name EXEC PROC=proc-name
Example - JCL to create two PS files.
//MTHUSERC JOB (MTH1234),'PAWAN Y',
// CLASS=B,NOTIFY=&SYSUID
//*
//STEP01 EXEC PGM=IEFBR14
//DD1 DD DSN=MATEPK.IEFBR14.PSFILE1,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(TRK,(3,2),RLSE),
// UNIT=SYSDA,VOLUME=SER=DEVHD4,
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
//*
//STEP02 EXEC PGM=IEFBR14
//DD1 DD DSN=MATEPK.IEFBR14.PSFILE2,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(TRK,(3,2),RLSE),
// UNIT=SYSDA,VOLUME=SER=DEVHD4,
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
Same JCL with Cataloged Proc -
Cataloged procedure definition -
//CREATEPS PROC
//STEPA EXEC PGM=IEFBR14
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSDUMP DD SYSOUT=*
//DD1 DD DSN=&PSNAME,
// DISP=(NEW,CATLG,DELETE),
// SPACE=(TRK,(3,2),RLSE),
// UNIT=SYSDA,VOLUME=SER=DEVHD4,
// DCB=(DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=800)
JCL calling cataloged procedure (with overriding PS file name) -
//MATEPKPS JOB (MTH1234),'PAWAN Y',
// CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),
// NOTIFY=&SYSUID
//PLIB JCLLIB ORDER=(MATEPK.JCL.LIB)
//*
//STEP10 EXEC CREATEPS,PSNAME=MATEPK.TEST.PSFILE1
//STEP20 EXEC CREATEPS,PSNAME=MATEPK.TEST.PSFILE2
Nested procedures
Nested procedures (PROC) are a technique to create a PROC that contains a call to another PROC. Procedures can be nested up to 15 levels. The nesting can be either in-stream or cataloged. i.e., we cannot code an instream procedure within a cataloged or vice versa—only in-steam in in-stream and cataloged in cataloged.
Syntax -
PROCA - PROCA definition
//PROCA PROC
//STEPname EXEC PGM=PROG1
..
..
PROCB - PROCB definition
//PROCB PROC
//STEPname EXEC PROCA
//STEPname EXEC PGM=PROG2
..
..
JCL - Calling PROCB that executes PROCA also
//JOB1 JOB
//STEPname EXEC PROCB
Examples - Coding a nested procedure that calls PROCA to PROCB.
PROC1 - PROC1 with a PROG1
//PROC1 PROC
//STEP11 EXEC PGM=PROG1
PROC2 - PROC2 with PROG2 and PROC1 execution
//PROC2 PROC
//STEP21 EXEC PGM=PROG2
//STEP22 EXEC PROC1
JCL - Calling PROC2 that executes PROC1
//JOB1 JOB
//STEP01 EXEC PROC2
The above JCL same as -
//JOB1 JOB
//STEP21 EXEC PGM=PROG2
//STEP11 EXEC PGM=PROG1