Thursday, April 28, 2011

JCL FAQs : Series 02 : Procedures and Symbolics

Procedures

Syntax for Executing procedure

Catalogued:
IBM supplies a utility program called IEBUPDTE; this program places cataloged procedures into partitioned data sets. These procedures are placed inside a system library called SYS1.PROCLIB.

//PRODPR1 JOB ZAq00000,
// 'CC2 NXD',
// MSGCLASS=O,
// RD=R,
// PRTY=14,
// TIME=1440,
// REGION=0M,
// CLASS=P,
// LINES=(50,WARNING)
//PROCS JCLLIB ORDER=(
// MDRPR.NDR.PROCLIB,
// MDRPR.NDR.VSAMINCL,
// ISDPR.ISD.PROCLIB)
//*
//LOADLIB INCLUDE MEMBER=KLIBNDR
//JS05 EXEC [PROC=]PRODPR1,
// MLM1=PR

When you executing CATALOGED PROCEDURE, If you have not specified where it is with JCLLIB statement , it will serach for this procedure in system procedure library SYS1.PROCLIB - There many IBM-supplied procedures that compile, link, and run programs
The following statements cannot be included within the procedure
JOB
DD * or DD DATA
JES2 or JES3 control statements


Instream:
//myproc PROC
//pg01 exec pgm=vvcmrbx
// ..
// ..
// pend
//pg01 exec pgm=vvcmrby
//instrm01 dd MYPROC

Instead of exec, instream called using DD.


MODIFY STATEMENTS IN A PROCEDURE:Overrides in Procedure:
We can add/modify contents of procedure. There are two types of modification we can do ,
1. on EXEC statement
2. on DD statement on EXEC statement


1. On EXEC statement
We can do following functions on EXEC statement in a procedure -

1.1Modify parameter on EXEC statements
PROCEDURE STATEMENT - //STEP10 EXEC PGM=COBPROG,TIME=30
PARAMETER OVERRIDE - //MYSTEP EXEC PROC=MYPROC,TIME.STEP10=40
Now Resultant TIME value for that step (in proc) is 40

1.2Adding parameter to an EXEC statement / all EXEC statement
PROCEDURE STATEMENT - //STEP10 EXEC PGM=COBPROG,TIME=30
PARAMETER ADDING -//MYSTEP EXEC PROC=MYPROC,REGION.STEP10=56K
(for single step)
REGION will be added to the STEP10 in MYPROC procedure
PARAMETER ADDING - //MYSTEP EXEC PROC=MYPROC,REGION=56K (for single step)
If REGION is not available for any step in that procedure. REGION will be added to all steps in procedure. If REGION is available for any step in procedure, REGION value will be override existing value on that step.

1.3Nullifying the parameter value
PROCEDURE STATEMENT - //STEP10 EXEC PGM=COBPROG,TIME=30
PARAMETER ADDING - //MYSTEP EXEC PROC=MYPROC,TIME.STEP10=
Dont give any value for that parameter, it will nullifying that parameter value in procedure on DD statement.

2. Syntax for add/modify DD statements in a procedure
//name EXEC [PROC=]procedure-name
//[procstepname].ddname DD parameter=value
//

We can do following functions on EXEC statement in a procedure
using above syntax:
- Modify existing parameter on DD statements within a procedure
- Add parameter to existing DD statement within a procedure
- Add DD statement to a job step
- Nullify the effect of parameter on DD statement in a procedure

SYMBOLIC PARAMETERS:
Usaually, the same JCL can be used by different programmers to implement common tasks, such as the opening, reading, and writing of data sets. In those cases , we can use symbolic parameters. Using symbolic parameters we can pass value to a parameter which is used in procedure.

A symbolic parameter on a DD statement is coded the parameter preceded by an ampersand. Syntax for assigning values to symbolic parameters in a procedure
//[name] EXEC [PROC=]procedure-name,symbolic-parameter=value

EXAMPLE JCL -> Procedure which is using symbolic parameter
//MYPROC PROC
//MYSTEP EXEC PGM=COBPROG
//INFILE DD DSN=&DOC..TEST.LIB,DISP=SHR
//OUTFILE DD DSN=&DOC..TEST.OUT,
// DISP=(NEW,KEEP,DELETE),
// UNIT=SYSDA,
// SPACE=(CYL,(&SPACE))

The invoking EXEC statement
//STEPA1 EXEC MYPROC,DOC=MYLIB,SPACE='10,5'

The effective JCL
//MYPROC PROC
//MYSTEP EXEC PGM=COBPROG
//INFILE DD DSN=MYLIB.TEST.LIB,DISP=SHR
//OUTFILE DD DSN=MYLIB.TEST.OUT,
// DISP=(NEW,KEEP,DELETE),
// UNIT=SYSDA,
// SPACE=(CYL,('10,5'))

EXPLANATION -
In above example, &DOC,&SPACE are symbolic parameters in MYPROC procedure
We are passing values from invoking JCL,these value will be override the
&DOC and &SPACE where ever they find in the procedure

Quotes & Blanks in JCL Symbolic Variables
Symbolic substitution in JCL can be a minefield when embedded blanks or quotes are involved. The JCL conversion process
• will not substitute symbolics inside quotes
• will stop subsitution when it hits a blank outside of quotes
• requires two quotes within a quoted string to represent a single quote.

Here is a relatively straight-forward example of how to deal with this situation. Say that you want to run SDSF in batch and limit the jobs selected to only those associated with the user who owns the batch job.

Here is some JCL that you could use:
// SET QT=''''
// SET CMD='OWNER '
// SET PRM=&QT.&CMD.&SYSUID.&QT
//GETMSGS EXEC PGM=SDSF,DYNAMNBR=32,REGION=1024K,TIME=5,
// PARM=&QT.&PRM.&QT
//REPORT DD DISP=(,CATLG),DSN=&SYSUID..ABC.LIST,
// SPACE=(CYL,(1,1)),RECFM=FB,LRECL=80,BLKSIZE=0
//ISFOUT DD SYSOUT=*
//ISFIN DD *
PRINT FILE REPORT
...
more SDSF control statements
...

&SYSUID is a standard JCL symbolic which contains the userid associated with the executing job.
Refer to an earlier stupid trick for more information.
The PARM string 'OWNER userid' tells SDSF to only look at jobs belonging to userid.
We construct the parm by combining constant strings (which may contain blanks) with symbolic variables and frame the resulting string using the symbolic variable &QT (one single quote) to glue it all together.
The symbolic variable PRM contains 'OWNER userid';
however, if you don't put the &QTs around it as in the sample above, you wind up with just PARM=OWNER being passed to SDSF.

Here is a more complex example.
Caution-overexposure to this topic may cause discomfort:
//NESTED PROC LS=132,
// PS=60
// SET QT=''''
//SAUS EXEC SAUS,
// OPTIONS='SYSPARM='''&QT.&LS-&PS.&QT''''
//SYSIN DD DISP=(OLD,DELETE),DSN=&&SASIN
// PEND
//RUNJCL EXEC NESTED

The instream procedure NESTED invokes a catalogued procedure SAUS. The intent is to assign the value 'SYSPARM=''132-60''' to symbolic parameter OPTIONS. OPTIONS is appended to the execution parm in the invoked catalogued procedure, (which is contained within quotes), resulting in the value SYSPARM='132-60' being included in the run-time parms for program SAUS, once all the extra quotes have been stripped away. The values 132 and 60 are being used as default line size and page size values by the application. They can be modified in the JCL which makes use of the instream procedure.

No comments:

Post a Comment