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.
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.
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.
| Part | Meaning |
|---|---|
| procname | 1–8 characters, must start with A–Z or @ # $. Names the procedure. |
| PROC | Keyword. Marks the beginning of the procedure. |
| param=value | Optional. Symbolic parameters with default values (e.g. DSN=MY.DATA). |
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.
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.
1234567//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.
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).
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.
1. An in-stream procedure is bounded by:
2. If you omit PEND:
3. To override a procedure parameter when invoking you use: