Introduction
The COND parameter in JCL is used to control the execution of steps based on the return code (RC) from previous steps. This is essential for conditional execution of jobs and avoiding unnecessary steps when a failure or specific condition has already occurred.
You can use COND on:
- The JOB level: to skip entire steps.
- The EXEC statement: to control individual step execution.
Common format:
COND=(rc,operator[,stepname])
Where:
- rc is a return code (e.g., 8)
- operator can be EQ, NE, LT, GT, LE, GE
- stepname is optional but refers to a previous step
The IF/THEN/ELSE/ENDIF structure in JCL lets you conditionally control which job steps run, based on return codes (RC) or abend conditions. It improves clarity and flexibility compared to the older COND parameter, especially in complex jobs.
You can test for specific step outcomes, catch abends, and even nest conditions up to 15 levels. This makes it easier to write smarter and more maintainable JCL.
This exercise is designed to help you understand the behavior and usage of the COND parameter and IF/THEN/ELSE/ENDIF statement through hands-on experimentation.
By running a sample JCL and analyzing different scenarios, you will observe how return codes influence the execution of subsequent steps. A small REXX utility will be used to simulate return codes, providing a controlled environment to explore different Condition settings.
For all the exercise instructions, Apply both COND Parameter as well as IF/THEN/ELSE/ENDIF individually to achieve the result. Not all conditions are achievable through one of the mean identify them too.
Before starting the exercise, set up your environment using the sample JCL and REXX script provided. This setup will allow you to simulate different return codes in your JCL steps, which you can then use to explore the behavior of the COND parameter.
Exercise: Find and fix Invalid JCL
//STEP10 EXEC PGM=PROG1,COND=(GT,8)
//STEP1 EXEC PGM=PROGA
//STEP2 EXEC PGM=PROGB
//STEP5 EXEC PGM=PROGC
//STEP8 EXEC PGM=PROGD,COND=(4,EQ,STEPX)
//STEP1 EXEC PGM=PROG1
// IF (STEP1.RC = 0) THEN
// ENDIF
//STEP1 EXEC PGM=PROG1
// ELSE
//STEP2 EXEC PGM=PROG2
// ENDIF
//STEP1 EXEC PGM=PROG1
// IF (STEP1.RC == 0) THEN
//STEP2 EXEC PGM=PROG2
// ENDIF
//STEP1 EXEC PGM=PROG1
// IF (STEP1.RC = 0) THEN
// IF (RC = 4) THEN
//STEP2 EXEC PGM=PROG2
// ENDIF
//STEP1 EXEC PGM=PROG1
// IF (ABENDCODE = SOC7) THEN
//STEP2 EXEC PGM=RECOVER
// ENDIF
Exercise: Create JCL as Requested.
Create a job with two steps:
- STEP1: Return RC = 0
- STEP2: Should be skipped if STEP1 returns RC = 0
Create a job with two steps:
- STEP1: Return RC = 4
- STEP2: Should only run if STEP1 RC is less than or equal to 4
Create a job with four steps:
- STEP1: Return RC = 8
- STEP2: Return RC = 4 (run only if STEP1 RC ≠ 8)
- STEP3: Return RC = 0 (skip if STEP2 RC = 4)
- STEP4: Return RC = 16 (run only if STEP3 did not run)
Create a Job with 5 Steps each with the following specification:
- STEP1
- RC = 8
- STEP2
- RC = 6
- Run only if STEP1 RC = 6
- STEP3
- RC = 4
- Run only if STEP2 RC = 8
- STEP4
- RC = 2
- Run only if STEP1 RC = 8
- STEP5
- RC = 16
- Run only if STEP4 RC is between 4 and 8
Create a Job with 3 Steps each with the following specification:
- STEP1: Return RC = 0
- STEP2: Return RC = 8
- STEP3: Should be skipped if any previous step returns RC ≥ 8
Create a Job with 3 Steps each with the following specification:
- STEP1: RC = 0
- STEP2: RC = 12
- STEP3: Run only if:
- STEP1 RC ≠ 0 AND
- STEP2 RC ≠ 12
Create a Job with 3 Steps each with the following specification:
- STEP1: RC = 4
- STEP2: RC = 0
- STEP3: Run if either STEP1 or STEP2 have RC > 0
Create a Job with 4 Steps each with the following specification:
- STEP1: RC = 12
- STEP2: RC = 8
- STEP3: Skip if STEP2 RC ≥ 8
- STEP4: Always run regardless of STEP1 to 3 results
- Create 5 steps:
- Each step should run only if the previous step returns RC = 0
- Modify STEP3 to return RC = 4 and observe the chain break.
Create a job with the following steps:
- STEP1 calls a program that will abend (our U4038PGM created in setup)
- STEP2 should execute only if STEP1 fails
Create a job with the following steps:
- STEP1 fails due to an abend (our U4038PGM created in setup)
- STEP2 should execute regardless of abend or not
Create a job with the following steps:
- STEP1 fails due to an abend (our SOC4PGM created in setup)
- STEP2 should execute only if STEP1 abend
- STEP3 should execute regardless of abend or not
Summary
What is COND?
The COND parameter is used to bypass (skip) a step based on the return code (RC) of previous steps. If the COND condition evaluates to true, the step is skipped.
Think of it as: 👉 “Skip this step if...”
What is IF/THEN/ELSE/ENDIF
in JCL?
The IF/THEN/ELSE/ENDIF
construct allows you to conditionally run job steps based on the return code (RC) or abend condition of previous steps. It's a more readable and flexible alternative to the older COND
parameter.
Think of it as: 👉 “Run this block only if...”
Equivalent of COND=ONLY and COND=EVEN
COND Style | IF/THEN Equivalent |
---|---|
COND=ONLY | IF (ABEND) |
COND=EVEN | Code the same block in IF AND ELSE Block(Not Ideal) |