Understanding condition codes and their role in conditional JCL execution
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.
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:
Indicates the program completed successfully with no issues.
Minor issues occurred but did not prevent successful execution.
Significant issues occurred that may have affected output.
Major issues prevented proper execution of the program.
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.
Many IBM utilities follow standard patterns for condition codes. Here are some examples:
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:
123IEF142I 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.
JCL provides several ways to use condition codes for conditional processing. The most common methods are:
The COND parameter on the EXEC statement allows you to skip a step based on condition codes from previous steps:
12//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
The IF/THEN/ELSE structure provides more flexible conditional logic:
1234567//STEP1 EXEC PGM=PROGRAM1 //* // IF (STEP1.RC = 0) THEN //STEP2A EXEC PGM=PROGRAM2A // ELSE //STEP2B EXEC PGM=PROGRAM2B // ENDIF
You can use condition codes to evaluate multiple steps and take action based on the result:
123456//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.
This practical example demonstrates how condition codes control the flow of a multi-step job:
1234567891011121314151617181920212223242526272829303132333435//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
This ensures that programs only run if they compiled and link-edited successfully, preventing cascading errors and wasted resources.
Add comments to your JCL explaining what condition codes are expected from each step and what they indicate.
In your own programs, follow the standard conventions (0=success, 4=warning, etc.) to maintain consistency across your applications.
Choose the right conditional construct (COND parameter or IF/THEN/ELSE) based on the complexity of your conditional logic.
Add steps that execute only on failure to perform cleanup, notification, or diagnostic actions.
In IF statements, you can use MAXCC to refer to the highest condition code of all previous steps in the job.
1. What is the standard range for condition codes in JCL?
2. Which condition code typically indicates successful execution with no errors?
3. What condition code typically represents a serious error?
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?
5. How would you reference the condition code from a step named COMPILE in a subsequent step?
6. Which IBM utility returns a condition code of 4 when a member being copied already exists in the target library?