Conditional execution statements (IF/THEN/ELSE/ENDIF) allow for dynamic control of JCL execution flow based on various conditions. This powerful feature enables jobs to make runtime decisions, execute different steps based on return codes, parameter values, or dataset existence, and adapt processing logic without requiring multiple job submissions or external intervention.
Key Benefit:
Conditional execution brings programming-like logic to JCL, allowing for more intelligent and adaptable batch processing that can respond to execution conditions without operator intervention.
1234// IF condition THEN //step1 EXEC PGM=program1 //step2 EXEC PGM=program2 // ENDIF
12345// IF condition THEN //step1 EXEC PGM=program1 // ELSE //step2 EXEC PGM=program2 // ENDIF
123456789// IF condition1 THEN // IF condition2 THEN //step1 EXEC PGM=program1 // ELSE //step2 EXEC PGM=program2 // ENDIF // ELSE //step3 EXEC PGM=program3 // ENDIF
Condition | Description | Example |
---|---|---|
RC = n | Return code equals n | IF RC = 0 THEN |
RC > n | Return code greater than n | IF RC > 4 THEN |
RC < n | Return code less than n | IF RC < 8 THEN |
RC > n | Return code greater than n | IF RC > 4 THEN |
RC >= n | Return code greater than or equal to n | IF RC >= 4 THEN |
RC <= n | Return code less than or equal to n | IF RC <= 4 THEN |
RC ¬= n | Return code not equal to n | IF RC ¬= 0 THEN |
stepname.RC | Return code from a specific step | IF STEP1.RC = 0 THEN |
stepname.procstep.RC | Return code from a step within a procedure | IF STEP1.PROC1.RC = 0 THEN |
Condition | Description | Example |
---|---|---|
ABEND | Previous step abended | IF ABEND THEN |
¬ABEND | Previous step did not abend | IF ¬ABEND THEN |
ABENDCC | System completion code | IF ABENDCC = S0C7 THEN |
stepname.ABEND | Specific step abended | IF STEP1.ABEND THEN |
Condition | Description | Example |
---|---|---|
RUN | Previous step executed | IF RUN THEN |
¬RUN | Previous step bypassed | IF ¬RUN THEN |
stepname.RUN | Specific step executed | IF STEP1.RUN THEN |
Condition | Description | Example |
---|---|---|
¶m = value | Parameter equals value | IF &ENV = PROD THEN |
¶m != value | Parameter not equal to value | IF &ENV != TEST THEN |
¶m > value | Parameter greater than value | IF &COUNT > 100 THEN |
Condition | Description | Example |
---|---|---|
DSN=dataset.name | Dataset exists | IF DSN=MY.DATASET THEN |
¬DSN=dataset.name | Dataset does not exist | IF ¬DSN=MY.DATASET THEN |
123// IF (STEP1.RC = 0 & STEP2.RC < 8) | STEP3.RC > 0 THEN //NEXT EXEC PGM=PROGRAM4 // ENDIF
Uses both AND (&) and OR (|) operators in a compound condition. The parentheses control precedence.
12345678//RCCHECK JOB (ACCT#),'ADMIN',CLASS=A //STEP1 EXEC PGM=MYPROG //* // IF STEP1.RC = 0 THEN //STEP2 EXEC PGM=NEXTPROG // ELSE //STEPALT EXEC PGM=RECOVERY // ENDIF
This job executes NEXTPROG if MYPROG completes successfully, otherwise it runs the RECOVERY program.
1234567//ERRJOB JOB (ACCT#),'ADMIN',CLASS=A //STEP1 EXEC PGM=PROCESS //* // IF STEP1.ABEND THEN //CLEANUP EXEC PGM=CLEANUP //REPORT EXEC PGM=ERRRPT // ENDIF
This job runs cleanup and error reporting programs if the PROCESS program abends.
12345678//PARAMJOB JOB (ACCT#),'ADMIN',CLASS=A // SET ENV=TEST //* // IF &ENV = PROD THEN //PRODSTEP EXEC PGM=PRODPGM // ELSE //TESTSTEP EXEC PGM=TESTPGM // ENDIF
This job uses a symbolic parameter to determine which program to run based on the environment.
1234567//DSNJOB JOB (ACCT#),'ADMIN',CLASS=A //* // IF DSN=MY.INPUT.DATASET THEN //PROCESS EXEC PGM=PROCESS // ELSE //CREATE EXEC PGM=CREATE // ENDIF
This job checks if a dataset exists before processing it, and creates it if necessary.
123456789//MULTRC JOB (ACCT#),'ADMIN',CLASS=A //STEP1 EXEC PGM=PROGRAM1 //STEP2 EXEC PGM=PROGRAM2 //* // IF (STEP1.RC <= 4 & STEP2.RC <= 4) THEN //STEP3 EXEC PGM=FINALPROC // ELSE //RECOVERY EXEC PGM=RECOVERPROC // ENDIF
This job executes the final processing only if both previous steps completed with acceptable return codes.
1234567891011121314151617//COMPLEX JOB (ACCT#),'ADMIN',CLASS=A // SET MODE=NORMAL //STEP1 EXEC PGM=PROGRAM1 //* // IF STEP1.RC < 8 THEN // IF &MODE = NORMAL THEN //NORM EXEC PGM=NORMAL // ELSE //SPEC EXEC PGM=SPECIAL // ENDIF // ELSE // IF STEP1.ABENDCC = S0C7 THEN //FIXMEM EXEC PGM=MEMFIX // ELSE //GENERAL EXEC PGM=ERRHANDLER // ENDIF // ENDIF
This example shows nested conditions that handle different return codes and abend conditions along with parameter-based logic.
You can use conditional statements within procedures:
123456789//MYPROC PROC ENV=TEST //STEP1 EXEC PGM=PROG1 //* // IF &ENV = PROD THEN //STEP2 EXEC PGM=PRODPROG // ELSE //STEP2 EXEC PGM=TESTPROG // ENDIF // PEND
This procedure uses different programs based on the environment parameter value.
Differences between IF/THEN/ELSE and COND parameter:
IF/THEN/ELSE/ENDIF | COND Parameter |
---|---|
More flexible with explicit flow control | Limited to step bypass based on return codes |
Can control multiple steps with one condition | Applies to individual steps only |
Supports multiple condition types (ABEND, DSN, etc.) | Limited to return code checking |
Supports compound conditions with AND/OR | Limited to OR logic via multiple conditions |
Issue | Possible Causes & Solutions |
---|---|
Mismatched IF/ENDIF |
|
Unexpected execution path |
|
JCL error in conditional statements |
|
MSGLEVEL=(1,1)
to see expanded JCL with resolved conditionsTYPRUN=SCAN
to validate conditional JCL syntax without execution//JCLLIB LIST
to verify procedure library resolutionConditional JCL is supported in both JES2 and JES3 environments with minimal differences: