Mainframes 360
The one stop destination for System Z professionals

Saturday, July 4, 2009

JCL Tutorial – 09 : DD Statement Part III


Q. What is a JCL PROC(Procedure)?
In JCL, we have an important concept of re-usability in the form of Instream and Cataloged Procedures. Once a Batch Job(a group of job-steps in JCL) have been written, you can give this JCL a name and save it onto Secondary Storage. Whenever you need to run the same procedure again, you can simply call it/refer to it by its name, instead of having to rewrite the entire JCL source code again. Thus, if you give your JCL a name, and make it available for others, a third person, who requires the same functionality, can simply call you JCL, and use it like a ready-made object. He doesn’t need to reinvent the wheel all over again.

Note that : This is analogous to writing Function(Procedure or Method) in most conventional/traditional programming languages.
Q. What is a Cataloged Procedure?
Lets say, we’ve written the following JCL PROC.

//MYPROC PROC  
//STEP01 EXEC PGM=COBPROG1
//STEP02 EXEC PGM=COBPROG2
// PEND  

The above PROC can be saved either in a user-defined library(PDS), or in the Default SYSTEM LIBRARY. The Default System-defined Library is SYS1.PROCLIB. So, if we would like anybody to use our JCL PROC globally, we must make sure it is universally visible, by placing it under the Default System Library. We can now call this PROC as follows:

//TRGD56 JOB A123,QUASAR
//STEP01 EXEC PROC=MYPROC

Note, here the while executing MYPROC, it will first search any user-defined private libraries. Since, this Batch Job does not specify any user-defined private library, it will now search for MYPROC in DEFAULT System Library  - SYS1.PROCLIB.

If we had saved the above PROC MYPROC as a member in our own user-defined private library like TRGD56.DEMO.PROCLIB(MYPROC), then the above JCL would look as follows -

//TRGD56 JOB A123,QUASAR
// JCLLIB ORDER=(TRGD56.DEMO.PROCLIB)
//STEP01 EXEC PROC=MYPROC

Thus, to specify a user-defined private library, we must use JCLLIB statement.  

Analogy with respect to conventional Programming Languages like Java and C# : This is the same as when referring to a class/object(containing variables and methods) in a package in Java, or in a namespace in C-Sharp. We need to specify the name of the package using import statement in Java or the using keyword in C#. The JCLLIB of JCL is equivalent to using in C#, or import in Java, or #include in C,C++.
Q. What is an Instream Procedure?
An Instream Procedure is a PROC written as a part of the same JCL/Batch JOB, and referred to elsewhere in the Batch Job. Let me cite to you, a simple example of how an Instream PROC is used wherever needed at other placed in the Batch Job.

//TRGD56 JOB A123,QUASAR
//* START OF PROC  
//MYINPROC PROC  
//ISTEP01 EXEC PGM=PROGRAM1
//ISTEP02 EXEC PGM=PROGRAM2
// PEND  
//* END OF PROC  
//STEP01 EXEC PGM=SOMEPROG
//STEP02 DD MYINPROC
//STEP03 EXEC PGM=OTHRPROG
//STEP04 DD MYINPROC

In the above JCL, I’ve called the instream procedure MYINPROC twice, once in STEP02 and second in STEP04.

The maximum number of Instream PROCs you can write in a Batch JOB is 15.

More on Cataloged Procedures – Overriding Parameters >>
Note : You cannot code Instream Datasets in Cataloged Procedures. So, in cataloged Procedure DD * statement is not allowed.

Example of calling a PROC

Main JCL/Batch JOB – Calling Program




Called Procedure – Member MYPROC stored in the default system Library SYS1.PROCLIB

 
Output – Contents of the Dataset HERC03.DEMO.MYLIB(INPUT) are printed to default printer :

THIS IS DD STATEMENT IN CALLED PROGRAM.

To many people who are thrown to work at a mainframe computer on their first job, they feel lost. Mainframe people seem to speak a completely different language and that doesn't make life easy. What's more, the books and manuals are incredibly hard to comprehend.

"What on earth is a Mainframe?" is an absolute beginner's guide to mainframe computers. We'll introduce you to the hardware and peripherals. We'll talk about the operating system, the software installed on a mainframe. We'll also talk about the different people who work on a mainframe. In a nutshell, we'll de-mystify the mainframe.

Readers based in India, can buy the e-book for Rs. 50 only or the print book. International readers based in the US and other countries can click here to purchase the e-book.