JCL Variables provide a way to create dynamic, reusable JCL by allowing runtime substitution of values. Unlike symbolic parameters that are limited to procedures, JCL variables can be used across the entire job and even passed between jobs. They enable more flexible and maintainable JCL by centralizing values and supporting arithmetic and string operations.
Key Benefit:
JCL Variables allow for dynamic value substitution throughout jobs, enabling parameterization and custom logic that traditional symbolic parameters cannot provide, particularly when working with system information, dates, and calculated values.
Feature | JCL Variables | Symbolic Parameters |
---|---|---|
Scope | Job-wide and can be exported to other jobs | Limited to the procedure in which they're defined |
Definition | SET statement anywhere in JCL | PROC statement or override on EXEC statement |
Operations | Support arithmetic and string operations | Simple substitution only |
System values | Can access system symbols and built-in functions | Cannot access system information |
123// SET var=value // SET DATASET='MY.DATA.SET' // SET COUNT=10
123//STEP1 EXEC PGM=MYPROG //DD1 DD DSN=&DATASET,DISP=SHR //DD2 DD SPACE=(TRK,(&COUNT,5))
1234567// SET A=5 // SET B=10 // SET C=&A+&B /* C = 15 */ // SET D=&C*2 /* D = 30 */ // SET E=(&A+&B)*2 /* E = 30 */ // SET F=&C/&A /* F = 3 */ // SET G=&C-&B /* G = 5 */
1234// SET PREFIX='MY.DATA' // SET SUFFIX='FILE' // SET FULLNAME='&PREFIX..&SUFFIX' /* FULLNAME = 'MY.DATA.FILE' */ // SET JOBTXT='JOB &JOBNAME RUNNING' /* Uses system variable */
Note the double period (..) when concatenating strings - the first period is treated as a concatenation point, the second as a literal period.
1234// SET FULLDATE='20230712' // SET YEAR=SUBSTR(&FULLDATE,1,4) /* YEAR = '2023' */ // SET MONTH=SUBSTR(&FULLDATE,5,2) /* MONTH = '07' */ // SET DAY=SUBSTR(&FULLDATE,7,2) /* DAY = '12' */
Symbol/Function | Description | Example |
---|---|---|
&SYSUID | User ID submitting the job | SET OWNER=&SYSUID |
&SYSDATE | Current date (yyyymmdd format) | SET TODAY=&SYSDATE |
&SYSTIME | Current time (hhmmss format) | SET NOW=&SYSTIME |
&SYSNAME | System name | SET SYSID=&SYSNAME |
&SYSPLEX | Sysplex name | SET PLEX=&SYSPLEX |
&JOBNAME | Name of the current job | SET JOB=&JOBNAME |
SUBSTR() | Extract substring | SET YR=SUBSTR(&SYSDATE,1,4) |
LENGTH() | Get string length | SET LEN=LENGTH(&NAME) |
INDEX() | Find position of substring | SET POS=INDEX(&TEXT,'ABC') |
123456789101112//DATEJOB JOB (ACCT#),'ADMIN',CLASS=A // SET TODAY=&SYSDATE // SET YEAR=SUBSTR(&TODAY,1,4) // SET MONTH=SUBSTR(&TODAY,5,2) // SET DAY=SUBSTR(&TODAY,7,2) // SET YESTERDAY=&TODAY-1 //* //STEP1 EXEC PGM=REPORT //INFILE DD DSN=DATA.FILE.&YEAR&MONTH&DAY,DISP=SHR //PREVFILE DD DSN=DATA.FILE.&YESTERDAY,DISP=SHR //OUTFILE DD DSN=REPORT.&YEAR&MONTH&DAY,DISP=(NEW,CATLG), // SPACE=(CYL,(5,2)),UNIT=SYSDA
This job uses system date information to dynamically build dataset names.
123456789101112131415161718//CONDVAR JOB (ACCT#),'ADMIN',CLASS=A // SET ENV='PROD' // SET MAXRC=4 //* // IF &ENV = 'PROD' THEN // SET SYSID='P' // SET DATASET='PROD.MASTER.FILE' // ELSE // SET SYSID='T' // SET DATASET='TEST.MASTER.FILE' // ENDIF //* //STEP1 EXEC PGM=UPDATE //MASTER DD DSN=&DATASET,DISP=SHR //* // IF STEP1.RC > &MAXRC THEN //NOTIFY EXEC PGM=SENDMAIL // ENDIF
This example shows how to use variables with conditional logic for environment-specific processing.
12345678//SIZEVAR JOB (ACCT#),'ADMIN',CLASS=A // SET FILESIZE=100 // SET PRIMARY=&FILESIZE/10 // SET SECONDARY=&PRIMARY/2 //* //STEP1 EXEC PGM=GENCOPY //OUTPUT DD DSN=MY.OUTPUT.FILE,DISP=(NEW,CATLG), // SPACE=(TRK,(&PRIMARY,&SECONDARY))
This job calculates space allocation dynamically based on a file size variable.
1234567891011//STRVAR JOB (ACCT#),'ADMIN',CLASS=A // SET PREFIX='DATA' // SET ENV='PROD' // SET SYSID='SYS1' // SET SEQ=101 //* // SET DSNAME='&PREFIX..&ENV..&SYSID..D&SYSDATE..S&SEQ' //* //STEP1 EXEC PGM=PROCESS //OUTPUT DD DSN=&DSNAME,DISP=(NEW,CATLG), // SPACE=(CYL,(10,5)),UNIT=SYSDA
This example builds a complex dataset name by concatenating multiple variables and literals.
12345678910//VARSCOPE JOB (ACCT#),'ADMIN',CLASS=A // SET GLOBAL=100 /* Global variable */ //* //STEP1 EXEC PGM=PROGRAM1 //* // SET LOCAL=200 /* Local to this context */ //STEP2 EXEC PGM=PROGRAM2 //* // SET GLOBAL=300 /* Updates global variable */ //STEP3 EXEC PGM=PROGRAM3
Variables defined outside any IF/THEN/ELSE blocks are globally accessible. Variables defined within conditional blocks are only accessible within that block and its nested blocks.
12345678//EXPORT JOB (ACCT#),'ADMIN',CLASS=A // EXPORT SYMLIST=(TODAY,ENV) // SET TODAY=&SYSDATE // SET ENV='PROD' //* //STEP1 EXEC PGM=PROGRAM1 //* //STEP2 EXEC PGM=PROGRAM2
The EXPORT statement makes variables available to subsequent jobs in the same JES execution group.
Issue | Possible Causes | Solutions |
---|---|---|
Variable not substituted |
|
|
Calculation error |
|
|
Concatenation issues |
|
|
System symbols not available |
|
|
SYMLIST
command to display values of defined symbolsMSGLEVEL=(1,1)
on the JOB statement to see expanded JCL with resolved variablesTYPERUN=SCAN
to validate JCL with variables without execution