The COND parameter is used to conditionally execute or skip job steps based on the return codes of previous steps. This allows for creating processing logic within your JCL, such as skipping error recovery steps if no errors occurred, or bypassing unnecessary processing when certain conditions are met.
1//stepname EXEC PGM=program,COND=(code,operator)
1//stepname EXEC PGM=program,COND=((code1,operator1),(code2,operator2),...)
1//stepname EXEC PGM=program,COND=((code,operator,stepname))
1//stepname EXEC PGM=program,COND=((code,operator,stepname.procstepname))
12//stepname EXEC PGM=program,COND=EVEN //stepname EXEC PGM=program,COND=ONLY
A decimal number from 0 to 4095 that is compared with the return code from a previous step. Common return code values:
Operator | Meaning | Step is bypassed if... |
---|---|---|
GT | Greater than | Return code > specified code |
GE | Greater than or equal to | Return code ≥ specified code |
EQ | Equal to | Return code = specified code |
LT | Less than | Return code < specified code |
LE | Less than or equal to | Return code ≤ specified code |
NE | Not equal to | Return code ≠ specified code |
Value | Description |
---|---|
EVEN | Execute this step even if a previous step abnormally terminated |
ONLY | Execute this step only if a previous step abnormally terminated |
123//STEP1 EXEC PGM=PROG1 //STEP2 EXEC PGM=PROG2,COND=(4,LT) //STEP3 EXEC PGM=PROG3,COND=(8,EQ)
STEP2 executes only if the return code from STEP1 is less than 4.
STEP3 executes only if the return code from either STEP1 or STEP2 is not equal to 8.
123//STEP1 EXEC PGM=PROG1 //STEP2 EXEC PGM=PROG2 //STEP3 EXEC PGM=PROG3,COND=((4,GT,STEP1),(0,NE,STEP2))
STEP3 executes only if both conditions are false:
- Return code from STEP1 is not greater than 4
- Return code from STEP2 is equal to 0
12//STEP1 EXEC PGM=PROG1 //RECOVERY EXEC PGM=CLEANUP,COND=(0,NE,STEP1)
The RECOVERY step executes only if STEP1 does not complete with a return code of 0 (i.e., an error occurred).
123//STEP1 EXEC PGM=PROG1 //STEP2 EXEC PGM=PROG2 //CLEANUP EXEC PGM=HOUSEKEEP,COND=EVEN
The CLEANUP step executes regardless of whether STEP1 or STEP2 abnormally terminates.
123//STEP1 EXEC PGM=PROG1 //STEP2 EXEC PGM=PROG2 //FAILURE EXEC PGM=NOTIFY,COND=ONLY
The FAILURE step executes only if STEP1 or STEP2, or both, abnormally terminate.
123//STEP1 EXEC PGM=SORT //STEP2 EXEC PGM=UPDATE //STEP3 EXEC PGM=REPORT,COND=((0,EQ,STEP1),(0,EQ,STEP2))
STEP3 will be bypassed if either STEP1 or STEP2 ended with a return code of 0. This is the equivalent of "If STEP1=0 OR STEP2=0, then bypass STEP3."
12//STEP1 EXEC PGM=NORMAL //STEP2 EXEC PGM=ERRPROC,COND=(EVEN,(4,GE,STEP1))
STEP2 executes even if STEP1 abnormally terminates, and will be bypassed only if STEP1 completes with a return code greater than or equal to 4.
1//STEP EXEC PGM=PROGRAM,COND=(0,NE)
The step will be skipped if any previous step did not end with a return code of 0.
1//STEP EXEC PGM=PROGRAM,COND=(8,GE)
The step will be skipped if any previous step ended with a return code of 8 or higher.
1//CLEANUP EXEC PGM=HOUSEKEEP,COND=EVEN
The cleanup step will execute even if previous steps ended abnormally.
1//REPORT EXEC PGM=REPORTER,COND=((0,NE,PREPDATA))
The REPORT step will be skipped if the PREPDATA step did not end with a return code of 0.
Understanding the logical interpretation of COND tests can be helpful. Remember:
Desired Logic | COND Parameter |
---|---|
IF return code = 0 THEN run step | COND=(0,NE) (Skip if return code ≠ 0) |
IF return code `>` 4 THEN skip step | COND=(4,GT) (Skip if return code `>` 4) |
IF STEP1 = 0 AND STEP2 = 0 THEN run step | COND=((0,NE,STEP1),(0,NE,STEP2)) (Skip if STEP1 ≠ 0 OR STEP2 ≠ 0) |
1//STEP2 EXEC PGM=PROG2,COND=(0,EQ) // Skips if previous RC = 0, not what is often intended
1//STEP2 EXEC PGM=PROG2,COND=(8,LT) // Skips if RC < 8, not if RC >= 8 as might be intended
1//STEP3 EXEC PGM=PROG3,COND=((0,EQ,STEP1),(0,EQ,STEP2)) // Skips if STEP1=0 OR STEP2=0
1//STEP3 EXEC PGM=PROG3,COND=(0,NE,STEP9) // Error if STEP9 doesn't exist
Solution: Use COND=EVEN when you want standard condition testing after abnormal termination
JCL offers two different methods of conditional execution: the COND parameter and the IF/THEN/ELSE statements. Each has advantages:
COND Parameter | IF/THEN/ELSE Statements |
---|---|
Available in all z/OS versions | Available in more recent z/OS versions |
More concise syntax | More readable syntax similar to programming languages |
Can test only return codes | Can test return codes, abend conditions, and more complex comparisons |
Step-oriented (each step decides if it runs) | Block-oriented (groups of statements controlled together) |
Logical OR between conditions | Supports both AND and OR between conditions |