COND Parameter

Purpose

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.

Syntax

Basic Format

jcl
1
//stepname EXEC PGM=program,COND=(code,operator)

Multiple Conditions

jcl
1
//stepname EXEC PGM=program,COND=((code1,operator1),(code2,operator2),...)

With Step References

jcl
1
//stepname EXEC PGM=program,COND=((code,operator,stepname))

With Procedure Step References

jcl
1
//stepname EXEC PGM=program,COND=((code,operator,stepname.procstepname))

EVEN/ONLY Format

jcl
1
2
//stepname EXEC PGM=program,COND=EVEN //stepname EXEC PGM=program,COND=ONLY

Parameter Components

Return Code

A decimal number from 0 to 4095 that is compared with the return code from a previous step. Common return code values:

  • 0: Successful completion
  • 4: Warning message
  • 8: Error condition
  • 12: Serious error
  • 16: Fatal error

Operators

OperatorMeaningStep is bypassed if...
GTGreater thanReturn code > specified code
GEGreater than or equal toReturn code ≥ specified code
EQEqual toReturn code = specified code
LTLess thanReturn code < specified code
LELess than or equal toReturn code ≤ specified code
NENot equal toReturn code ≠ specified code

Special COND Values

ValueDescription
EVENExecute this step even if a previous step abnormally terminated
ONLYExecute this step only if a previous step abnormally terminated

How COND Processing Works

  1. When a step completes, it generates a return code (a value from 0 to 4095).
  2. Before executing a subsequent step with a COND parameter, the system evaluates the COND test(s).
  3. If any of the conditions tests true, the step is bypassed (not executed).
  4. If all conditions test false, the step is executed.
  5. When a step is bypassed, the return code from that step is set to 0 for evaluation in subsequent steps.
  6. If a step specifies COND=EVEN, it executes regardless of whether previous steps ended abnormally (but still evaluates return codes).
  7. If a step specifies COND=ONLY, it executes only if a previous step ended abnormally.

Examples

Basic Conditional Execution

jcl
1
2
3
//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.

Multiple Conditions

jcl
1
2
3
//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

Error Recovery

jcl
1
2
//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).

Using EVEN

jcl
1
2
3
//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.

Using ONLY

jcl
1
2
3
//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.

References to Specific Steps

jcl
1
2
3
//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."

Combining EVEN with Conditions

jcl
1
2
//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.

Common Usage Patterns

Skip on Any Error

jcl
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.

Skip on Serious Errors

jcl
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.

Run Cleanup for Any Job

jcl
1
//CLEANUP EXEC PGM=HOUSEKEEP,COND=EVEN

The cleanup step will execute even if previous steps ended abnormally.

Run Only on Success of Specific Step

jcl
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.

Logical Interpretation

Understanding the logical interpretation of COND tests can be helpful. Remember:

  • The step is bypassed if the test is true, which is the opposite of traditional "if" statements.
  • For multiple conditions, they are combined with a logical OR (if any condition is true, the step is bypassed).
  • To create an AND condition, you need to think in terms of bypassing steps.
Desired LogicCOND Parameter
IF return code = 0 THEN run stepCOND=(0,NE) (Skip if return code ≠ 0)
IF return code `>` 4 THEN skip stepCOND=(4,GT) (Skip if return code `>` 4)
IF STEP1 = 0 AND STEP2 = 0 THEN run stepCOND=((0,NE,STEP1),(0,NE,STEP2))
(Skip if STEP1 ≠ 0 OR STEP2 ≠ 0)

Common Mistakes

  • Inverse logic misunderstanding: Forgetting that COND tests specify when to skip (not when to execute)
    jcl
    1
    //STEP2 EXEC PGM=PROG2,COND=(0,EQ) // Skips if previous RC = 0, not what is often intended
  • Operator confusion: Using the wrong comparison operator
    jcl
    1
    //STEP2 EXEC PGM=PROG2,COND=(8,LT) // Skips if RC < 8, not if RC >= 8 as might be intended
  • Multiple condition logic: Not understanding the OR relationship between conditions
    jcl
    1
    //STEP3 EXEC PGM=PROG3,COND=((0,EQ,STEP1),(0,EQ,STEP2)) // Skips if STEP1=0 OR STEP2=0
  • Referencing non-existent steps: Referring to a step that doesn't exist or was bypassed
    jcl
    1
    //STEP3 EXEC PGM=PROG3,COND=(0,NE,STEP9) // Error if STEP9 doesn't exist
  • Forgetting abnormal termination behavior: Not considering that standard COND tests are ignored after an abnormal termination

    Solution: Use COND=EVEN when you want standard condition testing after abnormal termination

COND vs. IF/THEN/ELSE

JCL offers two different methods of conditional execution: the COND parameter and the IF/THEN/ELSE statements. Each has advantages:

COND ParameterIF/THEN/ELSE Statements
Available in all z/OS versionsAvailable in more recent z/OS versions
More concise syntaxMore readable syntax similar to programming languages
Can test only return codesCan 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 conditionsSupports both AND and OR between conditions

Limitations

  • Abnormal termination handling: Standard COND tests are ignored after an abnormal termination (use COND=EVEN or COND=ONLY)
  • Limited condition testing: Can only test return codes, not more complex conditions
  • OR-only logic: Multiple conditions are always combined with OR logic, limiting complex condition expressions
  • Step-level only: Cannot conditionally execute individual DD statements or other JCL elements
  • No access to execution-time variables: Cannot test dynamic values determined during job execution
  • No support for procedure step return codes: Cannot test against return codes from steps within a procedure without specific syntax

Best Practices

  • Consider readability: Use comments to explain complex condition logic
  • Consistent return codes: Establish standard return code meanings across your applications (e.g., 0=success, 4=warning, 8=error)
  • Use EVEN for cleanup: Employ COND=EVEN for cleanup steps that should always execute
  • IF/THEN/ELSE for complex logic: Consider using IF/THEN/ELSE statements for more complex conditional logic
  • Explicit step references: Reference specific steps when testing their return codes rather than relying on the default behavior
  • Test your logic: Verify conditional execution by deliberately forcing different return codes during testing

Related Concepts

  • IF Statement - Alternative method for conditional processing in JCL
  • THEN Statement - Used with the IF statement for conditional processing
  • ELSE Statement - Used with the IF statement for conditional processing
  • ENDIF Statement - Used with the IF statement for conditional processing
  • Return Codes - Understanding the meaning of different return code values

Related Pages