JCL In-Stream Procedures – Quick Reference

An in-stream procedure is a procedure defined in the same job stream, between a PROC statement and a PEND statement. You give it a name on the PROC line and optionally define symbolic parameters with defaults. The procedure body contains the steps (EXEC, DD, etc.) that run when you invoke the procedure with EXEC procname. In-stream procedures must appear before the EXEC that calls them. PEND is required to end the procedure; without it, the rest of the job is incorrectly treated as part of the procedure.

Explain Like I'm Five: What Is an In-Stream Procedure?

Imagine you write a short recipe (steps 1, 2, 3) on a piece of paper and then say "do that recipe." The recipe is the procedure—the list of steps. In-stream means the recipe is written right there in the same job, not in a separate book (catalog). PROC is the title of the recipe; PEND is the end of the recipe. When the job runs "do that recipe," it runs all the steps between PROC and PEND. You can even have placeholders (parameters) like "use 2 eggs" and change it to "use 3 eggs" when you run it.

PROC Statement

The PROC statement marks the beginning of an in-stream procedure. Syntax: //procname PROC [param=value ...]. Procname is 1–8 characters and must start with a letter (A–Z) or national character (@, #, $). Optional parameters are symbolic: you give a name and a default value. Inside the procedure you reference them with an ampersand (e.g. &DSN). When the procedure is invoked with EXEC, the caller can override these values.

PROC statement parts
PartMeaning
procname1–8 characters, must start with A–Z or @ # $. Names the procedure.
PROCKeyword. Marks the beginning of the procedure.
param=valueOptional. Symbolic parameters with default values (e.g. DSN=MY.DATA).

PEND Statement

The PEND statement marks the end of the in-stream procedure. Syntax: //[name] PEND. The name field is optional and has no functional effect. Every PROC must have a matching PEND. If you omit PEND, the system treats all following statements in the job as part of the procedure until it hits another PROC or end of job, which usually leads to errors or unexpected behavior. Cataloged procedures do not use PEND; they are stored in a library and end when the procedure definition ends.

Structure: Procedure Before Invocation

The in-stream procedure must appear in the job stream before the first EXEC that invokes it. Typical order: JOB statement, then the procedure (PROC ... body ... PEND), then the steps that EXEC the procedure or other steps. You cannot invoke an in-stream procedure before it is defined.

jcl
1
2
3
4
5
6
7
//MYJOB JOB (ACCT),'INSTREAM PROC' //MYPROC PROC DSN=MY.DATA //STEP1 EXEC PGM=PROG1 //DD1 DD DSN=&DSN,DISP=SHR // PEND //RUN EXEC MYPROC //RUN2 EXEC MYPROC,DSN=OTHER.DATA

MYPROC is defined with one symbolic parameter DSN=MY.DATA. STEP1 uses &DSN in the DD. PEND ends the procedure. RUN invokes MYPROC with the default DSN (MY.DATA). RUN2 overrides DSN to OTHER.DATA. So the same procedure runs twice with different data set names.

Symbolic Parameters

Parameters on the PROC statement are symbolic. In the procedure body you reference them with &name (e.g. &DSN, &PARM). When you EXEC the procedure, you can override any parameter by specifying the same name and a new value on the EXEC statement or in a separate override. The maximum length of a symbolic parameter value and substitution rules depend on the system; keep names and values within JCL conventions (e.g. 1–8 characters for simple names).

In-Stream vs Cataloged Procedure

An in-stream procedure is defined in the job stream (PROC ... PEND) and is only visible to that job. A cataloged procedure is stored in a procedure library (e.g. SYS1.PROCLIB) and is invoked by name; it has no PEND in the job. In-stream is useful for one-off or job-specific procedures; cataloged procedures are shared across jobs and maintained in the library.

Step-by-Step: Defining an In-Stream Procedure

  1. Place the procedure after the JOB statement and before any EXEC that invokes it.
  2. Start with //procname PROC. Add optional parameters (param=default) if you want overridable values.
  3. Write the procedure body: EXEC and DD statements (and any other valid JCL) that define the steps. Use &param for symbolic parameters.
  4. End with //[name] PEND. Ensure every PROC has exactly one PEND.
  5. Invoke the procedure with EXEC procname. Override parameters on the EXEC if needed (e.g. EXEC procname,PARM=value).

Best Practices

Test Your Knowledge

Test Your Knowledge

1. An in-stream procedure is bounded by:

  • JOB and EXEC
  • PROC and PEND
  • DD and EXEC
  • // and //

2. If you omit PEND:

  • The procedure is invalid
  • The rest of the job is treated as part of the procedure
  • Only the first step runs
  • Nothing happens

3. To override a procedure parameter when invoking you use:

  • DD statement
  • EXEC procname,PARM=value
  • JOB statement
  • PEND