Nested Procedures


Nested procedures (PROC) are a technique to create a PROC that contains a call to another PROC. This process is useful when a particular set of JCL statements is needed in multiple procedures. It is easier to define them in a separate procedure than to repeat them in each one.

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  PROC
//STEPname EXEC PGM=PROG1
..
..

PROCB -

//PROCB  PROC
//STEPname EXEC PROCA
//STEPname EXEC PGM=PROG2
..
..

JCL -

//JOB1  JOB
//STEPname EXEC PROCB

Examples -


Scenario - Coding a nested procedure that calls PROCA to PROCB.

PROC1 -

//PROC1  PROC
//STEP11 EXEC PGM=PROG1

PROC2 -

//PROC2  PROC
//STEP21 EXEC PGM=PROG2
//STEP22 EXEC PROC1

JCL -

//JOB1  JOB
//STEP01 EXEC PROC2

The above JCL after expansion -

//JOB1  JOB
//STEP21 EXEC PGM=PROG2
//STEP11 EXEC PGM=PROG1