MainframeMaster

JCL Tutorial

Condition Codes

Understanding condition codes and their role in conditional JCL execution

Progress0 of 0 lessons

Introduction to Condition Codes

Condition codes (also called return codes) are numeric values that programs set when they finish execution. These codes indicate the outcome of the program's execution and can be used by JCL to make decisions about subsequent steps.

By checking condition codes, JCL can implement conditional logic, allowing jobs to adapt based on the success or failure of previous steps. This tutorial explores how condition codes work and how they're used within JCL.

Understanding Condition Codes

Condition codes are integer values that can range from 0 to 4095, although in practice most programs use a more limited range (typically 0-16). Each program defines its own condition codes, but there are commonly accepted conventions:

0 - Successful execution

Indicates the program completed successfully with no issues.

4 - Warning

Minor issues occurred but did not prevent successful execution.

8 - Error

Significant issues occurred that may have affected output.

12 - Serious error

Major issues prevented proper execution of the program.

16 - Fatal error

Critical failure occurred, execution could not complete.

When a step completes, JCL captures its condition code and can use it to determine whether subsequent steps should execute, and how they should execute. This is the foundation of conditional processing in JCL.

How Programs Set Condition Codes

Programs written in different languages set condition codes in different ways:

Common IBM Utilities Condition Codes:

Many IBM utilities follow standard patterns for condition codes. Here are some examples:

  • IDCAMS: 0 (successful), 4 (warning), 8 (error), 12 (serious error), 16 (terminal error)
  • IEBCOPY: 0 (successful), 4 (warning, e.g., member already exists), 8 (error)
  • SORT: 0 (successful), 4 (warning), 16 (error)
  • IEFBR14: Always returns 0 (this is a "do nothing" program often used for allocation/deallocation)

Viewing Condition Codes in Job Output

When a job runs, the condition code for each step is recorded in the job log. In most mainframe environments, you can see these codes in the job output by looking at the messages produced by the system:

text
1
2
3
IEF142I USERA JOB12345 STEP1 - STEP WAS EXECUTED - COND CODE 0000 IEF142I USERA JOB12345 STEP2 - STEP WAS EXECUTED - COND CODE 0004 IEF142I USERA JOB12345 STEP3 - STEP WAS EXECUTED - COND CODE 0008

In this example, STEP1 completed with condition code 0 (success), STEP2 with code 4 (warning), and STEP3 with code 8 (error). Understanding these codes helps you diagnose issues and understand the flow of your job.

Using Condition Codes in JCL

JCL provides several ways to use condition codes for conditional processing. The most common methods are:

1. The COND Parameter

The COND parameter on the EXEC statement allows you to skip a step based on condition codes from previous steps:

jcl
1
2
//STEP2 EXEC PGM=PROGRAM2,COND=(4,LT) // Run only if all previous steps had CC < 4 //STEP3 EXEC PGM=PROGRAM3,COND=(8,LE,STEP1) // Run only if STEP1 had CC <= 8

2. IF/THEN/ELSE/ENDIF Statements

The IF/THEN/ELSE structure provides more flexible conditional logic:

jcl
1
2
3
4
5
6
7
//STEP1 EXEC PGM=PROGRAM1 //* // IF (STEP1.RC = 0) THEN //STEP2A EXEC PGM=PROGRAM2A // ELSE //STEP2B EXEC PGM=PROGRAM2B // ENDIF

3. Job Step Evaluation

You can use condition codes to evaluate multiple steps and take action based on the result:

jcl
1
2
3
4
5
6
//STEP1 EXEC PGM=PROGRAM1 //STEP2 EXEC PGM=PROGRAM2 //* // IF (STEP1.RC <= 4 & STEP2.RC = 0) THEN //STEP3 EXEC PGM=PROGRAM3 // ENDIF

Note: These examples provide a brief introduction to conditional processing in JCL. The COND parameter and IF/THEN/ELSE statements will be covered in more detail in the next tutorials in this section.

Practical Example: Using Condition Codes

This practical example demonstrates how condition codes control the flow of a multi-step job:

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
27
28
29
30
31
32
33
34
35
//JOBNAME JOB (ACCT),'CONDITION CODE DEMO',CLASS=A //* //* STEP 1: COMPILE A COBOL PROGRAM //* //COMPILE EXEC PGM=IKFCBL00,REGION=4M //SYSIN DD DSN=SOURCE.COBOL(PROGRAM1),DISP=SHR //SYSLIN DD DSN=&&OBJSET,DISP=(NEW,PASS), // UNIT=SYSDA,SPACE=(TRK,(5,5)) //SYSPRINT DD SYSOUT=* //* //* STEP 2: IF COMPILE WAS SUCCESSFUL (RC <= 4), LINK-EDIT THE PROGRAM //* // IF (COMPILE.RC <= 4) THEN //LKED EXEC PGM=IEWL,REGION=4M //SYSLIN DD DSN=&&OBJSET,DISP=(OLD,DELETE) //SYSLMOD DD DSN=LOADLIB(PROGRAM1),DISP=SHR //SYSPRINT DD SYSOUT=* //* //* STEP 3: IF LINK-EDIT WAS SUCCESSFUL (RC = 0), RUN THE PROGRAM //* // IF (LKED.RC = 0) THEN //RUN EXEC PGM=PROGRAM1 //STEPLIB DD DSN=LOADLIB,DISP=SHR //INPUT DD DSN=INPUT.DATA,DISP=SHR //OUTPUT DD DSN=OUTPUT.DATA,DISP=(NEW,CATLG), // UNIT=SYSDA,SPACE=(TRK,(10,5)) //SYSOUT DD SYSOUT=* // ENDIF // ENDIF //* //* STEP 4: ALWAYS RUN REGARDLESS OF PREVIOUS STEPS (CLEAN UP) //* //CLEANUP EXEC PGM=IEFBR14 //TEMP DD DSN=&&OBJSET,DISP=(MOD,DELETE), // UNIT=SYSDA

How this job uses condition codes:

  • The COMPILE step creates an object module if successful
  • The LKED step only runs if COMPILE had a condition code of 0 or 4
  • The RUN step only executes if LKED had a condition code of 0
  • The CLEANUP step always runs, regardless of previous condition codes

This ensures that programs only run if they compiled and link-edited successfully, preventing cascading errors and wasted resources.

Best Practices for Condition Codes

1. Document Expected Condition Codes

Add comments to your JCL explaining what condition codes are expected from each step and what they indicate.

2. Standardize Condition Code Usage

In your own programs, follow the standard conventions (0=success, 4=warning, etc.) to maintain consistency across your applications.

3. Use Appropriate Conditional Logic

Choose the right conditional construct (COND parameter or IF/THEN/ELSE) based on the complexity of your conditional logic.

4. Include Error Handling Steps

Add steps that execute only on failure to perform cleanup, notification, or diagnostic actions.

5. Consider Using MAXCC

In IF statements, you can use MAXCC to refer to the highest condition code of all previous steps in the job.

Test Your Knowledge

1. What is the standard range for condition codes in JCL?

  • 0-9
  • 0-16
  • 0-255
  • 0-4095

2. Which condition code typically indicates successful execution with no errors?

  • 0
  • 4
  • 8
  • 12

3. What condition code typically represents a serious error?

  • 0
  • 4
  • 8
  • 12

4. In the IF statement, what operator would you use to check if a step's return code is less than or equal to 4?

  • LE
  • LT
  • EQ
  • NE

5. How would you reference the condition code from a step named COMPILE in a subsequent step?

  • RC=COMPILE
  • COMPILE.RC
  • RC.COMPILE
  • COMPILE

6. Which IBM utility returns a condition code of 4 when a member being copied already exists in the target library?

  • IEBGENER
  • IEBCOPY
  • IDCAMS
  • IKJEFT01