JCLintermediate
Conditional Step Execution: COND and IF/THEN/ELSE
Control whether a job step executes based on prior step return codes, using both the legacy COND parameter and the more readable IF/THEN/ELSE construct.
A job often needs to skip a step when an earlier one failed, or run a cleanup step only on failure. JCL has two mechanisms, and one of them reads backwards.
COND is a note that says 'do NOT proceed unless this comparison is false' pinned to the door — it works, but you have to read it twice to be sure which way it swings; IF/THEN/ELSE is a green light and a red light, exactly as intuitive as they look.
Key Concepts
1
COND says when to SKIP, not when to run. That inversion is the whole difficulty.
COND
2
//STEP2 EXEC PGM=PGMB,COND=(4,LT)3
Read it as: "if 4 is less than the return code of any previous step, skip this step."
4
So the step runs when every previous return code is 4 or lower. Most people read it as the opposite the
first time, and that is exactly what the question is testing.
5
COND=(0,NE) skip unless the previous RC is 0
COND=(4,LT) skip if any RC is greater than 4
COND=(8,LE) skip if any RC is 8 or more
COND=ONLY run ONLY if a previous step abended
COND=EVEN run even if a previous step abended6
ONLY and EVEN are how cleanup steps are written in older JCL.
ONLYEVEN
7
IF/THEN/ELSE reads the way you expect.
// IF (STEP1.RC > 4) THEN
//ERRSTEP EXEC PGM=NOTIFY
// ELSE
//OKSTEP EXEC PGM=CONTINUE
// ENDIFIF/THEN/ELSE
8
It names a specific step rather than "any previous step", which is the second advantage — COND compares
against every preceding step, so a step that returned 4 five steps ago still affects the decision.
COND
9
It also nests, tests abend conditions (STEP1.ABEND), and can check whether a step ran at all
(STEP1.RUN).
STEP1.ABENDSTEP1.RUN
10
Translating between them is a standard exercise:
11
COND=(4,LT) -> IF (STEP1.RC <= 4) THEN ... ENDIF
COND=(0,NE) -> IF (STEP1.RC = 0) THEN ... ENDIF
COND=ONLY -> IF (STEP1.ABEND) THEN ... ENDIF12
Note the comparison flips, because one says skip and the other says run.
13
Use IF/THEN/ELSE in anything new. COND is worth knowing because production JCL is full of it, and
misreading one is how a step gets skipped or run in exactly the circumstances it should not have been.
IF/THEN/ELSECOND
14
What the interviewer is probing.1. "How does COND actually read?" Probing: the famous confusion. Stalls: "It runs if true."
Moves up: backwards — the step is SKIPPED when the condition is true, which is why IF/THEN/ELSE
replaced it.
15
2. "Why prefer IF/THEN/ELSE?" Probing: the modern answer. Stalls: "Style." Moves up: it
reads in the obvious direction and supports ABEND and RC tests clearly, so fewer production jobs do
the wrong thing.
16
3. "What does COND=EVEN mean?" Probing: the detail. Stalls: "Always run." Moves up: run
the step even if a previous one abended — used for cleanup steps that must happen regardless.
17
4. "How do you handle a step that legitimately returns 4?" Probing: practical knowledge.
Stalls: "Treat it as failure." Moves up: test for the specific code rather than any non-zero,
since utilities use 4 for conditions like empty input that are often acceptable.