MainframeMaster

JCL Tutorial

COND Parameter

Using the COND parameter for conditional job step execution in JCL

Progress0 of 0 lessons

Introduction to the COND Parameter

The COND parameter is a powerful feature in JCL that allows for conditional execution of job steps based on the return codes from previous steps. It provides a way to control the flow of job execution without using the more complex IF/THEN/ELSE structures.

By using the COND parameter, you can skip steps that would be unnecessary or potentially harmful if previous steps didn't complete as expected. This tutorial explores how to use the COND parameter effectively for conditional processing in your JCL jobs.

Basic COND Parameter Syntax

The COND parameter is specified on the EXEC statement and can take several forms:

Basic Syntax:

jcl
1
2
3
4
5
//stepname EXEC PGM=program-name,COND=(code,operator) //stepname EXEC PGM=program-name,COND=(code,operator,stepname) //stepname EXEC PGM=program-name,COND=((code1,operator1),(code2,operator2),...) //stepname EXEC PGM=program-name,COND=EVEN //stepname EXEC PGM=program-name,COND=ONLY

The components of the COND parameter are:

  • code: A numeric value (0-4095) to compare against the return code
  • operator: A comparison operator (GT, GE, EQ, NE, LT, LE)
  • stepname: Optional - specifies which step's return code to check

IMPORTANT: COND Logic is Counter-Intuitive

The COND parameter specifies when to bypass (skip) a step, not when to execute it. If the condition is true, the step is skipped. This often confuses JCL programmers.

For example, COND=(4,LT) means "bypass this step if any previous step's return code is less than 4" - this means the step only runs if all previous return codes are 4 or higher.

Comparison Operators

The COND parameter uses these comparison operators:

GT (Greater Than)

Bypass if return code is greater than the specified value

COND=(4,GT) - Skip if RC > 4

GE (Greater than or Equal)

Bypass if return code is greater than or equal to the specified value

COND=(8,GE) - Skip if RC >= 8

EQ (Equal)

Bypass if return code is equal to the specified value

COND=(0,EQ) - Skip if RC = 0

NE (Not Equal)

Bypass if return code is not equal to the specified value

COND=(0,NE) - Skip if RC ≠ 0

LT (Less Than)

Bypass if return code is less than the specified value

COND=(8,LT) - Skip if RC < 8

LE (Less than or Equal)

Bypass if return code is less than or equal to the specified value

COND=(4,LE) - Skip if RC <= 4

COND Parameter Variations

1. Basic COND - All Previous Steps

If you don't specify a step name, the condition applies to all previous steps:

jcl
1
2
3
//STEP1 EXEC PGM=PROGRAM1 //STEP2 EXEC PGM=PROGRAM2 //STEP3 EXEC PGM=PROGRAM3,COND=(4,LT)

STEP3 will be bypassed if STEP1 or STEP2 has a return code less than 4.

2. COND with Specific Step

You can specify a particular step to check:

jcl
1
2
3
//STEP1 EXEC PGM=PROGRAM1 //STEP2 EXEC PGM=PROGRAM2 //STEP3 EXEC PGM=PROGRAM3,COND=(0,NE,STEP1)

STEP3 will be bypassed if STEP1 has a return code not equal to 0.

3. Multiple Conditions

You can specify multiple conditions in a single COND parameter:

jcl
1
2
3
//STEP1 EXEC PGM=PROGRAM1 //STEP2 EXEC PGM=PROGRAM2 //STEP3 EXEC PGM=PROGRAM3,COND=((0,NE,STEP1),(4,GT,STEP2))

STEP3 will be bypassed if STEP1 has a return code not equal to 0 OR if STEP2 has a return code greater than 4.

4. COND=EVEN

To execute a step even if a previous step abended:

jcl
1
2
3
//STEP1 EXEC PGM=PROGRAM1 //STEP2 EXEC PGM=PROGRAM2 //CLEANUP EXEC PGM=CLEANUP,COND=EVEN

The CLEANUP step will execute even if STEP1 or STEP2 abended. This is ideal for cleanup steps that should always run.

5. COND=ONLY

To execute a step only if a previous step abended:

jcl
1
2
3
//STEP1 EXEC PGM=PROGRAM1 //STEP2 EXEC PGM=PROGRAM2 //RECOVERY EXEC PGM=RECOVERY,COND=ONLY

The RECOVERY step will only execute if STEP1 or STEP2 abended. This is useful for recovery procedures.

Practical Examples

Example 1: Compile, Link, Execute

A common pattern in mainframe processing is conditional compile, link, and execute:

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//JOBNAME JOB (ACCT),'DEVELOPER',CLASS=A //* //COMPILE EXEC PGM=IKFCBL00 //SYSIN DD DSN=SOURCE.COBOL(PROGRAM),DISP=SHR //SYSLIN DD DSN=&&OBJSET,DISP=(NEW,PASS), // UNIT=SYSDA,SPACE=(TRK,(5,5)) //SYSPRINT DD SYSOUT=* //* //LINK EXEC PGM=IEWL,COND=(4,LT,COMPILE) //SYSLIN DD DSN=&&OBJSET,DISP=(OLD,DELETE) //SYSLMOD DD DSN=LOAD.LIBRARY(PROGRAM),DISP=SHR //SYSPRINT DD SYSOUT=* //* //EXECUTE EXEC PGM=PROGRAM,COND=((4,LT,COMPILE),(0,NE,LINK)) //STEPLIB DD DSN=LOAD.LIBRARY,DISP=SHR //SYSOUT DD SYSOUT=*

Example 1 Explanation:

  • LINK step - Skip if COMPILE return code < 4 (Execute only if COMPILE was successful or had minor warnings)
  • EXECUTE step - Skip if COMPILE return code < 4 OR LINK return code ≠ 0 (Execute only if both steps completed successfully)

Example 2: Data Processing with Cleanup

This example shows a data processing job with cleanup that always runs:

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//JOBNAME JOB (ACCT),'DATA PROCESS',CLASS=A //* //EXTRACT EXEC PGM=EXTRACT //INPUT DD DSN=INPUT.DATA,DISP=SHR //OUTPUT DD DSN=&&TEMP1,DISP=(NEW,PASS), // UNIT=SYSDA,SPACE=(CYL,(10,5)) //SYSPRINT DD SYSOUT=* //* //SORT EXEC PGM=SORT,COND=(8,LT,EXTRACT) //SORTIN DD DSN=&&TEMP1,DISP=(OLD,PASS) //SORTOUT DD DSN=&&TEMP2,DISP=(NEW,PASS), // UNIT=SYSDA,SPACE=(CYL,(10,5)) //SYSIN DD * SORT FIELDS=(1,10,CH,A) /* //SYSOUT DD SYSOUT=* //* //REPORT EXEC PGM=REPORTER,COND=((8,LT,EXTRACT),(4,LT,SORT)) //INPUT DD DSN=&&TEMP2,DISP=(OLD,PASS) //OUTPUT DD DSN=FINAL.REPORT,DISP=(NEW,CATLG,DELETE), // UNIT=SYSDA,SPACE=(CYL,(5,1)) //SYSPRINT DD SYSOUT=* //* //CLEANUP EXEC PGM=IEFBR14,COND=EVEN //TEMP1 DD DSN=&&TEMP1,DISP=(OLD,DELETE) //TEMP2 DD DSN=&&TEMP2,DISP=(OLD,DELETE)

Example 2 Explanation:

  • SORT step - Skip if EXTRACT return code < 8 (Execute only if EXTRACT was at least moderately successful)
  • REPORT step - Skip if EXTRACT return code < 8 OR SORT return code < 4 (Execute only if both previous steps completed reasonably well)
  • CLEANUP step - Always execute (COND=EVEN), even if previous steps abended

COND Parameter with Cataloged Procedures

When using the COND parameter with cataloged procedures, you need a different syntax to reference steps within the procedure:

jcl
1
2
3
4
5
6
7
8
9
//JOBNAME JOB (ACCT),'PROCEDURE EXAMPLE',CLASS=A //* //STEP1 EXEC PGM=PROGRAM1 //SYSOUT DD SYSOUT=* //* //PROCSTEP EXEC PROC=MYPROC //* //STEP2 EXEC PGM=PROGRAM2,COND=(0,NE,PROCSTEP.COMPILE) //SYSOUT DD SYSOUT=*

In this example, STEP2 will be bypassed if the COMPILE step in the MYPROC procedure did not complete with a return code of 0. The format for referencing a step in a procedure is procstepname.stepname.

COND vs. IF/THEN/ELSE

While the COND parameter is powerful, it has some limitations compared to IF/THEN/ELSE structures:

COND Parameter

  • More concise for simple conditions
  • Uses OR logic (any condition true = bypass)
  • Counter-intuitive "bypass if true" logic
  • No nesting capability
  • Processed at step initiation time

IF/THEN/ELSE Statements

  • More readable for complex conditions
  • Supports AND, OR logic
  • More intuitive "execute if true" logic
  • Supports nesting of conditions
  • Processed during JCL interpretation

Choose the approach that best fits your needs. For simple conditional execution, COND is often sufficient. For more complex logic, IF/THEN/ELSE is usually more appropriate.

Best Practices

1. Add Comments

Always add comments to explain the COND logic, especially for complex conditions.

jcl
1
2
//* Skip this step if previous step had RC > 8 (major error) //STEP2 EXEC PGM=PROGRAM2,COND=(8,GT,STEP1)

2. Use Specific Step References

When possible, reference specific steps rather than all previous steps to make your logic more predictable.

3. Include Cleanup Steps

Always include cleanup steps with COND=EVEN to ensure temporary resources are released even if the job fails.

4. Test Your Conditions

Test your COND parameters with different return code scenarios to ensure they behave as expected.

5. Consider Using IF/THEN/ELSE for Complex Logic

If your conditional logic becomes difficult to express with COND parameters, consider switching to IF/THEN/ELSE statements.

Common Pitfalls

  • Misunderstanding the "bypass" logic: Remember that COND specifies when to skip a step, not when to execute it.
  • Forgetting that multiple conditions use OR logic: If any condition is true, the step is bypassed.
  • Not accounting for abnormal terminations: Standard COND conditions don't check for abends; use COND=EVEN or COND=ONLY for this.
  • Referencing non-existent steps: Ensure all referenced steps exist and are spelled correctly.
  • Using the wrong comparison operator: Double-check your operators (GT, LT, EQ, etc.) to ensure they express the intended logic.

Practice Exercises

Test your understanding of the COND parameter with these exercises:

Basic COND Parameter

Create a JCL job with two steps. In the second step, use the COND parameter to skip execution if the first step returns a code greater than 4.

View Solution
jcl
1
2
3
4
5
6
//EXERJOB JOB (ACCT),'COND EXERCISE',CLASS=A //STEP1 EXEC PGM=MYPROG1 //SYSOUT DD SYSOUT=* //* //STEP2 EXEC PGM=MYPROG2,COND=(4,GT,STEP1) //SYSOUT DD SYSOUT=*

Multiple Conditions

Create a JCL job with three steps. Add a fourth step that executes only if STEP1 had a return code of 0 or STEP3 had a return code less than or equal to 4.

View Solution
jcl
1
2
3
4
5
6
7
8
9
10
11
12
//EXERJOB JOB (ACCT),'COND EXERCISE',CLASS=A //STEP1 EXEC PGM=MYPROG1 //SYSOUT DD SYSOUT=* //* //STEP2 EXEC PGM=MYPROG2 //SYSOUT DD SYSOUT=* //* //STEP3 EXEC PGM=MYPROG3 //SYSOUT DD SYSOUT=* //* //STEP4 EXEC PGM=MYPROG4,COND=((0,NE,STEP1),(4,LT,STEP3)) //SYSOUT DD SYSOUT=*

Using COND=EVEN and COND=ONLY

Create a JCL job with four steps. Make one step execute only if a previous step abended (COND=ONLY) and another step execute regardless of whether previous steps abended (COND=EVEN).

View Solution
jcl
1
2
3
4
5
6
7
8
9
10
11
12
//EXERJOB JOB (ACCT),'COND EXERCISE',CLASS=A //STEP1 EXEC PGM=MYPROG1 //SYSOUT DD SYSOUT=* //* //STEP2 EXEC PGM=MYPROG2 //SYSOUT DD SYSOUT=* //* //STEP3 EXEC PGM=RECOVERY,COND=ONLY //SYSOUT DD SYSOUT=* //* //STEP4 EXEC PGM=CLEANUP,COND=EVEN //SYSOUT DD SYSOUT=*

Frequently Asked Questions

What is the difference between COND parameter and IF/THEN/ELSE statements?+
The COND parameter offers simpler conditional logic and is processed at step initiation time. It determines whether to bypass a step based on return codes. IF/THEN/ELSE statements provide more structured and readable conditional logic, allowing for complex conditions and nested statements. Generally, IF/THEN/ELSE is more flexible but COND is more concise for simple conditions.
Can I use the COND parameter with steps in a cataloged procedure?+
Yes, you can use the COND parameter with procedure steps. To specify a condition based on a return code from a step within a procedure, use the format COND=(code,operator,procstepname.stepname). For example, COND=(4,GT,PROC1.STEP1) would bypass the current step if STEP1 in procedure PROC1 had a return code greater than 4.
Why does my step execute when I specified COND=(0,EQ) and the previous step had a return code of 0?+
Remember that the COND parameter specifies when to BYPASS a step, not when to execute it. COND=(0,EQ) means 'bypass this step if any previous step had a return code equal to 0.' Since your previous step had a return code of 0, the condition was met, and the step was bypassed. To execute a step when the previous return code is 0, use COND=(0,NE) which means 'bypass if NOT equal to 0'.
How do multiple conditions in a COND parameter work together?+
Multiple conditions in a COND parameter are combined with logical OR. The step will be bypassed if ANY of the conditions are true. For example, COND=((4,GT,STEP1),(8,EQ,STEP2)) means 'bypass this step if either STEP1 had a return code greater than 4 OR STEP2 had a return code equal to 8'.
What happens if I specify a step name in COND that doesn't exist in the job?+
If you reference a step name that doesn't exist in the job, a JCL error will occur at submission time. The job will fail with a message indicating that the referenced step name could not be found.

Test Your Knowledge

1. What is the primary purpose of the COND parameter in JCL?

  • To define dataset conditions
  • To specify when to bypass job steps based on return codes
  • To set program parameters
  • To define memory requirements

2. In COND=(4,LT), what does this condition mean?

  • Execute this step if previous steps had return codes less than 4
  • Bypass this step if previous steps had return codes less than 4
  • Execute this step if previous steps had return codes greater than 4
  • Bypass this step if previous steps had return codes equal to 4

3. What does COND=EVEN do in a JCL step?

  • Executes the step only when previous steps returned even-numbered return codes
  • Executes the step only if all previous steps completed successfully
  • Executes the step even if a previous step abended abnormally
  • Executes the step only when there are an even number of previous steps

4. Which of the following is NOT a valid operator in a COND parameter?

  • GT
  • LT
  • NE
  • EQ
  • BT

5. How would you specify a COND parameter to bypass a step if STEP1 had a return code of 8?

  • COND=(8,EQ)
  • COND=(8,EQ,STEP1)
  • COND=(8,NE,STEP1)
  • COND=(STEP1,8,EQ)

6. When multiple conditions are specified in a COND parameter, what is the logical relationship between them?

  • AND (all must be true)
  • OR (any can be true)
  • XOR (exactly one must be true)
  • NAND (not all can be true)