Skip to main content

Introduction - Why We Need Condition Handling in JCL

In JCL, conditions are essential to control the execution flow of job steps based on the success or failure of earlier steps. This ensures that unnecessary or harmful steps are skipped if a previous step fails, avoiding wasted resources or corrupted data.

The COND parameter was introduced in early JCL as a simple method to skip steps using return codes. However, as jobs grew more complex, it became harder to read and manage with COND alone.

IBM Docs - COND

To address this, IBM later introduced the IF/THEN/ELSE/ENDIF construct in z/OS 1.3, which offered a clearer and more flexible way to express job logic. Conditional logic helps ensure data integrity, error handling, and clean recovery in multi-step batch jobs. Without these controls, JCL jobs would execute blindly, leading to potential failures or incorrect results.

IBM Docs - IF ELSE

COND Parameter in JCL

The COND parameter controls whether a step should be skipped based on return codes from previous steps.

  • It means "condition to bypass", not "condition to run".
  • If the condition is true, the step is skipped.
  • If the condition is false, the step is executed.

Syntax

//STEP10 EXEC PGM=MYPROG,COND=(rc,operator,stepname)

Here:

  • rc: Return code to compare (e.g., 4, 8)
  • operator: Comparison like GT, LT, EQ, etc.
  • stepname: (Optional) Check return code from a specific step

If stepname is not provided, comparison is done against all previous steps.


Simple Example

//STEP3 EXEC PGM=PROGC,COND=(4,LT)
  • STEP3 is skipped if any previous step has RC less than 4.

JOB-level vs STEP-level COND

If COND is coded at the JOB level:

  • It is evaluated first.
  • If true → entire job is stopped.
  • All step-level COND values are ignored.

If false → step-level COND values are evaluated next.


Multiple Conditions

You can list multiple (RC,OPERATOR[,STEP]) conditions:

//STEP3 EXEC PGM=XYZ,COND=((8,EQ,STEP1),(4,GT,STEP2))
  • This means: skip STEP3 if STEP1 RC = 8 OR STEP2 RC > 4

If any one of the conditions is true → step is skipped. It is Logical behavior = OR


Special Keywords: EVEN and ONLY

In JCL, special COND keywords EVEN and ONLY are used to control step execution based on whether a previous step abended (failed abnormally). These keywords override the default behavior, allowing steps to run either always (EVEN) or only on abend (ONLY).

Here is a summary

KeywordWhen does the step run?Use Case
(default)Only if all previous steps did not abendNormal job flow
EVENAlways, even if previous step abendedCleanup, notification
ONLYOnly if a previous step abendedError recovery or alerting

Example

//STEP4 EXEC PGM=PROG,COND=ONLY
  • STEP4 runs only if a previous step abended

IF/THEN/ELSE/ENDIF in JCL

This structure gives a clearer way to conditionally execute steps based on:

  • Return codes (RC)
  • Abnormal ends (ABENDs)

It's a newer alternative to using COND.


Syntax for IF/THEN/ELSE/ENDIF

//STEP1 EXEC PGM=PROGA
// IF (STEP1.RC = 0) THEN
//STEP2 EXEC PGM=PROGB
// ELSE
//STEP3 EXEC PGM=PROGC
// ENDIF
  • If STEP1 ends with RC = 0 → STEP2 runs
  • Else → STEP3 runs

Operators You Can Use:

TypeOperators
RelationalEQ, NE, GT, GE, LT, LE
Logical& (AND), `(OR),¬` (NOT)

Nesting:

  • You can nest up to 15 levels of IF/THEN/ELSE/ENDIF
  • Every block must include at least one EXEC step

Return Code Checks Example:

IF (RC = 0) THEN         ← Highest RC from previous steps
IF (STEP1.RC = 4) THEN ← specific step RC

ABEND Checks Example:

IF (ABEND) THEN          ← any previous abend
IF (ABENDCC = S0C7) THEN ← specific abend code
tip

In COND parameter when we do not specific any step name it checks for any of the previous step RC to match the condition.

In IF/THEN/ELSE/ENDIF when we do not specific any step name it checks for the highest return code for any of the previous steps.