Showing posts with label EXEC PROC. Show all posts
Showing posts with label EXEC PROC. Show all posts

Tuesday, 9 April 2019

JCL Cataloged Procedure: PROC, JCLLIB, and Override Examples

//RUNRPT EXEC PROC=MYRPT,HLQ=TEST01 can expand into several job steps without copying those steps into every job. The reusable statements live in a procedure-library member, while the calling job supplies values and overrides for one execution.

JCL cataloged procedure flow from PROCLIB through EXEC PROC to expanded JCL
Store once, invoke where needed.

What is a JCL cataloged procedure?

A JCL cataloged procedure is a named set of reusable JCL statements stored as a member of a partitioned data set or PDSE that participates in the procedure-library search. The member usually contains one or more EXEC statements and their DD statements. A job calls the member by name rather than repeating the stored statements.

IBM describes SYS1.PROCLIB as a standard system procedure library, but production installations commonly concatenate product and application procedure libraries with it. Do not place an application procedure in SYS1.PROCLIB simply because an example uses that name. Follow the library, change-control, and security rules at your site.

Cataloged procedure versus in-stream procedure

PointCataloged procedureIn-stream procedure
LocationA member in a procedure libraryInside the submitted job
ReuseAvailable to jobs allowed to search the libraryAvailable only within that job
End markerNo PEND is required in the library memberThe definition ends with PEND
Best fitControlled compile, link-edit, backup, utility, and application-run standardsTesting a procedure or keeping a one-job definition close to its caller

For the broader procedure concepts, see the JCL procedure tutorial. The in-stream procedure guide covers the inline form.

Create a cataloged procedure member

Create a member such as USER01.PROCLIB(MYRPT). The member name becomes the procedure name used by the calling EXEC statement. The following procedure runs a reporting program and provides defaults through symbolic parameters.

//MYRPT   PROC HLQ=PROD01,OUTCLS=A
//REPORT  EXEC PGM=RPT100
//STEPLIB DD  DSN=&HLQ..LOAD,DISP=SHR
//INFILE  DD  DSN=&HLQ..INPUT.CUSTOMER,DISP=SHR
//RPTFILE DD  SYSOUT=&OUTCLS
//SYSPRINT DD SYSOUT=*

&HLQ. uses a period to terminate the symbolic name before the next period in the data set name. With the default HLQ=PROD01, &HLQ..LOAD resolves to PROD01.LOAD.

Cataloged-member rule: a stored procedure may begin with a named PROC statement, but it does not need the PEND statement used by an in-stream procedure.

Make a private PROCLIB searchable with JCLLIB

If the member is not in an installation-defined procedure-library concatenation, code JCLLIB ORDER after the JOB statement and before the first EXEC statement. IBM states that the named libraries are searched in the coded order before unspecified default procedure libraries.

//RPTJOB  JOB (ACCT),'DAILY REPORT',CLASS=A,MSGCLASS=X
//PROCS   JCLLIB ORDER=(USER01.PROCLIB,TEAM01.PROCLIB)
//RUNRPT  EXEC PROC=MYRPT

This job searches USER01.PROCLIB first, then TEAM01.PROCLIB, followed by any applicable default libraries. JCLLIB identifies procedure and INCLUDE libraries; it does not replace JOBLIB or STEPLIB for executable load modules.

Invoke the procedure with EXEC PROC

Both forms below call a procedure named MYRPT. Coding PROC= is explicit and easier for a beginner to recognize.

//RUNRPT  EXEC PROC=MYRPT
//RUNRPT  EXEC MYRPT

The name before EXEC, RUNRPT, identifies this invocation in the job. The step names inside the procedure keep their own identities after expansion. The JCL EXEC statement guide explains the difference between PGM= and PROC=.

Override symbolic parameters

Values coded on the calling EXEC statement replace the defaults on the PROC statement for that invocation. The stored member is not changed.

//RUNRPT  EXEC PROC=MYRPT,HLQ=TEST01,OUTCLS=H

The expanded data set names use TEST01, and the report is routed to SYSOUT class H. Choose descriptive symbols and provide safe defaults only when a default is appropriate. See JCL positional and keyword parameters for the statement-field rules.

Override a DD statement in a cataloged procedure

Qualify the override with the procedure step name and DD name. Here, REPORT is the EXEC step inside MYRPT, and INFILE is its DD name.

//RUNRPT         EXEC PROC=MYRPT,HLQ=TEST01
//REPORT.INFILE  DD   DSN=TEST01.INPUT.SPECIAL,DISP=SHR

IBM notes that an override replaces only the parameters you code. Parameters not replaced can remain from the stored DD statement. If a complete replacement is intended, inspect the expanded JCL so that an inherited UNIT, VOL=SER, SPACE, or DCB subparameter does not survive unexpectedly.

Procedure DD overrides must follow the procedure invocation. When several DD statements are overridden, keep them in the same relative order as their statements in the procedure. The JCL DD statement guide provides allocation examples.

Add a DD statement for one invocation

A calling job can add a DD statement to a procedure step when the stored procedure does not contain that DD name.

//RUNRPT          EXEC PROC=MYRPT
//REPORT.SYSUDUMP DD   SYSOUT=*

This adds SYSUDUMP to step REPORT for the current call. It does not add the statement to the procedure member. Use the feature for job-specific diagnostic or input/output requirements, not as a substitute for fixing a procedure that is wrong for every caller.

Complete cataloged procedure example

Procedure member USER01.PROCLIB(MYRPT)

//MYRPT   PROC HLQ=PROD01,OUTCLS=A
//REPORT  EXEC PGM=RPT100
//STEPLIB DD  DSN=&HLQ..LOAD,DISP=SHR
//INFILE  DD  DSN=&HLQ..INPUT.CUSTOMER,DISP=SHR
//RPTFILE DD  SYSOUT=&OUTCLS
//SYSPRINT DD SYSOUT=*

Calling job

//RPTJOB  JOB (ACCT),'DAILY REPORT',CLASS=A,MSGCLASS=X
//PROCS   JCLLIB ORDER=USER01.PROCLIB
//RUNRPT  EXEC PROC=MYRPT,HLQ=TEST01,OUTCLS=H
//REPORT.INFILE  DD DSN=TEST01.INPUT.SPECIAL,DISP=SHR
//REPORT.SYSUDUMP DD SYSOUT=*

The job locates MYRPT, substitutes the symbolic values, overrides REPORT.INFILE, adds REPORT.SYSUDUMP, and submits the expanded steps to normal JCL conversion and execution.

Watch the JCL cataloged procedure video

Video walkthrough: creating and using a JCL cataloged procedure.

Common cataloged procedure errors

  • Procedure not found: the member name is wrong or its library is missing from the applicable search order.
  • Wrong procedure step name: an override uses the calling step name instead of the EXEC step name inside the procedure.
  • Unresolved symbol: the procedure references a symbol that has no default and the caller supplies no value.
  • Bad symbol delimiter: a data set name omits the terminating period after a symbolic parameter.
  • Override order error: multiple DD overrides do not follow the order of the original DD statements.
  • Invalid stored JCL: IBM states that an invalid parameter in the original procedure cannot be repaired by an override because the base procedure is checked first.
  • Program not found: JCLLIB found the procedure, but JOBLIB or STEPLIB does not make the requested load module available.
Before production: review the expanded JCL in JES, confirm the resolved data set names, and check that every override landed on the intended procedure step.

Cataloged procedure test checklist

  1. Validate the member name and the PROC statement name.
  2. Confirm which PROCLIB concatenation or JCLLIB ORDER supplies the member.
  3. List each symbolic parameter, its default, and the value supplied by the caller.
  4. Match every override to the internal procstep.ddname.
  5. Check the expanded JCL before diagnosing the application program.
  6. Keep environment-specific data set names in symbols or approved overrides.

For a beginner sequence covering JOB, EXEC, and DD statements, use the JCL tutorial with examples.

Official IBM references

JCL cataloged procedure FAQ

What is a JCL cataloged procedure?

A cataloged procedure is a reusable set of JCL statements stored as a member of a procedure library. A job invokes the member from an EXEC statement.

How do I call a cataloged procedure?

Code EXEC PROC=procedure-name, or omit PROC= and code the procedure name as the EXEC positional parameter. Add any symbolic values on the same EXEC statement.

How does JCLLIB ORDER affect a cataloged procedure?

JCLLIB ORDER lists private or system procedure libraries in search order. z/OS searches those libraries before unspecified default procedure libraries.

Does a DD override change the stored procedure?

No. An override applies only to the current invocation. The procedure member in the library is not changed.

The safest procedure call is the one whose expanded JCL you have reviewed; the member name alone does not show the data sets, defaults, and overrides that the job will use.

Sunday, 28 July 2013

JCL EXEC Statement: PGM, PROC, PARM, and COND Examples

//STEP10 EXEC PGM=IDCAMS starts a job step named STEP10 and tells z/OS to run IDCAMS. Every executable step begins with a JCL EXEC statement. The statement can name a program directly, invoke a reusable procedure, pass program options, and control step-level processing.

JCL EXEC statement flow from JOB to an EXEC step, program or procedure, and DD statements
An EXEC statement starts a step, selects a program or procedure, and is followed by the DD statements needed by that work.

JCL EXEC statement syntax

//stepname EXEC PGM=program-name,keyword=value
//stepname EXEC PROC=procedure-name,keyword=value
//stepname EXEC procedure-name,keyword=value

An EXEC statement must identify a program or a procedure. PGM= names an executable program. PROC= names a cataloged or in-stream procedure. If both PGM and PROC are omitted, z/OS treats the first positional value after EXEC as a procedure name.

The step name is one through eight characters and identifies the job step in messages, condition tests, backward references, and overrides. Choose a meaningful name such as SORTIN, COMPILE, or REPORT. Step names must be unique within the job.

Statement boundary: an EXEC statement begins a step. The next EXEC statement, another JOB statement, or the end of the job ends that step. The associated DD statements normally follow the EXEC statement.

Run a program with EXEC PGM

//COPYSTEP EXEC PGM=IEBGENER
//SYSPRINT DD  SYSOUT=*
//SYSUT1   DD  DSN=APP.INPUT.FILE,DISP=SHR
//SYSUT2   DD  DSN=APP.OUTPUT.FILE,
//             DISP=(NEW,CATLG,DELETE),
//             SPACE=(TRK,(5,2)),UNIT=SYSDA
//SYSIN    DD  DUMMY

Here the system runs the load module named IEBGENER. DD statements connect the names expected by IEBGENER to input, output, messages, and control data. The PGM value names the program; it is not a source member or a compile command.

Use PGM= when the step should run one known program and the full DD setup belongs in the submitted job. The mainframe utilities guide lists common IBM utility program names.

Call a procedure with EXEC PROC

//RUNRPT  EXEC PROC=RPTPROC,ENV=PROD

//* Equivalent positional form:
//RUNRPT2 EXEC RPTPROC,ENV=TEST

Both statements invoke a procedure named RPTPROC. PROC= is explicit; the positional form is shorter and is widely used. A procedure can hold several EXEC and DD statements, so one job-level EXEC can expand into multiple procedure steps.

The ENV value in this example is a symbolic parameter only if RPTPROC defines or uses that symbol. Symbolic parameters are substituted while JCL is converted; they are different from PARM=, which passes data to a running program. See the JCL cataloged procedure guide for PROC, JCLLIB, symbols, and DD overrides.

Pass options with the PARM parameter

//COMPILE EXEC PGM=IGYCRCTL,PARM='LIB,LIST,MAP'

//RUNPGM  EXEC PGM=MYPROG,PARM='MODE=BATCH'

PARM= passes a character string to the program for that step. The program must be written to receive and interpret it, so valid values depend on that program's documentation. Quotes are needed when a value contains commas, blanks, or other JCL-significant characters.

The normal JCL PARM limit is 100 characters, excluding the enclosing delimiters. Some products provide a DD-based option mechanism for longer input. Do not assume that an arbitrary program accepts PARMDD or another alternate DD name.

PROC override: qualify PARM with the internal procedure step name when necessary. For example, //C1 EXEC COBPROC,PARM.COMP='LIST,MAP' changes PARM for the procedure step named COMP.

Skip a step with the COND parameter

//STEP1   EXEC PGM=PROGA
//STEP2   EXEC PGM=PROGB,COND=(4,LT,STEP1)

The comparison asks whether 4 is less than STEP1's return code. If STEP1 returns 8, the comparison is true and STEP2 is bypassed. If STEP1 returns 0 or 4, the comparison is false and STEP2 can run. This reverse-looking behavior is the main source of COND mistakes: a true EXEC COND test means skip the step.

An EXEC statement can contain up to eight COND comparisons. For new multi-branch logic, IF, THEN, and ELSE often state the intended run condition more directly. The JCL COND parameter tutorial covers operators, EVEN, ONLY, and return-code examples.

Do not read COND as “run when true.” First evaluate the coded comparison; if it is true, bypass the step. Also check whether a preceding abend affects later step processing.

Set storage with REGION

//REPORT EXEC PGM=RPTPGM,REGION=0M

//SMALL   EXEC PGM=OLDPROG,REGION=8M

REGION= controls the storage made available to a job step, subject to system and installation controls. Many sites use REGION=0M to request the available limit rather than an artificially small value, but local standards decide what is acceptable.

REGION can be coded on JOB or EXEC. IBM states that a REGION value on the JOB statement overrides one on an EXEC statement. When a storage failure occurs, check both statements and the site's exits or limits before increasing the step value.

Override an EXEC parameter inside a procedure

To change one internal procedure step, append a dot and that procedure step name to the keyword:

//RUNPROC EXEC PROC=PROCA,
//             TIME.STEP1=2,
//             PARM.STEP2='ABCD'

This sets TIME for procedure step STEP1 and PARM for procedure step STEP2. Other keywords on those internal EXEC statements remain in effect unless the override replaces them or they conflict with the overriding value.

Do not qualify the keyword with the calling job step name. Use the name of the EXEC statement inside the procedure. Likewise, a DD override uses procstep.ddname after the procedure call.

How z/OS finds the program

For EXEC PGM=MYPROG, the system must locate an executable module in an accessible program library. A step-level STEPLIB DD or job-level JOBLIB DD can identify private libraries; z/OS also searches its configured system libraries. Follow local standards because authorized program libraries and search order are site controlled.

//RUNAPP  EXEC PGM=MYPROG
//STEPLIB DD  DSN=APP.PROD.LOAD,DISP=SHR
//SYSOUT   DD  SYSOUT=*

If MYPROG cannot be found, an S806 abend is a common result. Check the PGM spelling, confirm that the member is a load module or program object, inspect STEPLIB or JOBLIB names and concatenation order, and verify access to the library. S806 is an execution-time module-location failure, not a compilation message.

Common EXEC statement errors

SymptomLikely check
JCL error before executionCheck commas, continuation alignment, duplicate step names, keyword spelling, and whether PGM or a procedure name is present.
S806 abendCheck PGM spelling and whether the module is available through STEPLIB, JOBLIB, or system libraries.
Procedure not foundCheck the procedure name and the JES procedure libraries or JCLLIB ORDER statement.
Program ignores PARMConfirm that the program accepts the exact string and delimiters supplied.
Step unexpectedly skippedEvaluate every COND comparison against earlier return codes; true means bypass.
Override has no effectUse the internal procedure step name after the keyword, such as PARM.COMP.

EXEC coding checklist

  • Give each step a short, meaningful, unique name.
  • Use exactly one program or procedure form on the statement.
  • Verify the program or procedure name against the target environment.
  • Keep PARM syntax within the called program's documented rules.
  • Read COND as a bypass test and trace the earlier return codes.
  • Qualify procedure overrides with the internal procedure step name.
  • Confirm the DD statements expected by the selected program or procedure.
  • Review JES messages and the job log when conversion or execution fails.

For the complete JOB, EXEC, and DD relationship, use the JCL tutorial with examples. For JES control statements outside normal JOB/EXEC/DD syntax, see the JCL JECL quick reference.

Official IBM references

JCL EXEC statement FAQ

What does the EXEC statement do in JCL?

It begins a job step and identifies either the program or the in-stream or cataloged procedure that z/OS is to run for that step.

What is the difference between EXEC PGM and EXEC PROC?

EXEC PGM names one executable program. EXEC PROC names a reusable JCL procedure, which can contain one or more internal steps and their DD statements.

When does JCL COND skip an EXEC step?

For an EXEC COND return-code test, z/OS bypasses the step when any coded comparison evaluates true. IF, THEN, and ELSE are often clearer for new conditional logic.

What usually causes an S806 abend on an EXEC step?

S806 normally means the requested load module could not be found in an accessible program library. Check the PGM spelling and the applicable STEPLIB, JOBLIB, and system library setup.

Start with the simplest valid form—//stepname EXEC PGM=program—then add only the PARM, COND, REGION, or procedure overrides that the step actually needs.

New In-feed ads