Return codes (also called condition codes) are numeric values returned by programs and job steps to indicate their completion status. These codes are fundamental to job flow control in JCL, enabling conditional execution based on the success or failure of previous steps.
Key Benefit:
Return codes provide a standardized way to determine whether a job step executed successfully, encountered errors, or requires special handling. By evaluating these codes, JCL can implement complex logic for error recovery, alternative processing paths, and job flow control.
Return codes in z/OS and JCL environments follow these conventions:
The COND parameter on JOB and EXEC statements allows conditional execution based on return codes from previous steps.
12//STEP2 EXEC PGM=PROGRAM2, // COND=(code,comparison,stepname)
COND Operation: A step is bypassed (not executed) if any of the conditions specified is true. This can be counterintuitive - the condition describes when to skip the step, not when to run it.
12//JOBABC JOB accounting-info,name, // COND=(code,comparison)
The COND parameter on a JOB statement applies to all steps in the job. If the condition becomes true, all remaining steps are bypassed.
12//STEP3 EXEC PGM=PROGRAM3, // COND=((4,LT,STEP1),(8,EQ,STEP2))
This example bypasses STEP3 if STEP1 returned a code less than 4 OR if STEP2 returned a code equal to 8.
Modern JCL offers IF/THEN/ELSE statements for more intuitive conditional logic:
1234567//STEP1 EXEC PGM=PROGRAM1 //* // IF (STEP1.RC <= 4) THEN //STEP2 EXEC PGM=PROGRAM2 // ELSE //STEP3 EXEC PGM=PROGRAM3 // ENDIF
This example runs STEP2 if STEP1 was successful or had only warnings, otherwise it runs STEP3.
IF/THEN/ELSE advantages over COND:
Utility | RC=0 | RC=4 | RC=8 | RC>8 |
---|---|---|---|---|
IEBCOPY | Successful | Minor issues (e.g., duplicate member replaced) | Processing errors | Serious errors, processing terminated |
IEBGENER | Successful | Warnings | Processing errors | Serious errors |
IDCAMS | Successful | Warnings | Function completed with error | Function not completed due to error |
SORT | Successful | Warnings (e.g., duplicate records) | Processing errors | Serious errors |
COBOL Compiler | Clean compile | Warnings, executable created | Errors, no executable | Severe errors |
IEFBR14 | Always returns 0 | N/A | N/A | N/A |
Different programming languages have different methods for setting return codes:
Language | Method | Example |
---|---|---|
Assembler | Load register 15 before program exit | asm
|
COBOL | RETURN-CODE special register | cobol
|
PL/I | PLIRETC function | pli
|
C | return statement in main() | c
|
REXX | EXIT instruction | rexx
|
JCL provides several ways to access return codes for conditional processing:
STEP.RC
or stepname.RC
1// IF (STEP1.RC > 0) THEN
RC
(shorthand for previous step)1// IF (RC = 0) THEN
JOBRC
(maximum return code so far)1// IF (JOBRC <= 4) THEN
STEP.ABEND
or STEP.ABENDCC
1// IF (STEP1.ABEND) THEN
1// IF (STEP1.ABENDCC = 'S0C7') THEN
123// IF ((STEP1.RC > 4) & (STEP1.RC < 12)) | (STEP2.RC = 0) THEN //STEP3 EXEC PGM=PROGRAM3 // ENDIF
This example runs STEP3 if STEP1 had an error (but not a serious one) OR if STEP2 was successful.
12345678// IF (STEP1.RC = 0) THEN //STEP2 EXEC PGM=PROGRAM2 // IF (STEP2.RC <= 4) THEN //STEP3 EXEC PGM=PROGRAM3 // ENDIF // ELSE //STEP4 EXEC PGM=PROGRAM4 // ENDIF
This example demonstrates nested IF statements for complex job flow logic.
Sometimes it's useful to set an artificial return code for testing or control purposes:
12345678//SETRCODE EXEC PGM=IEFBR14 // IF (CONDITION) THEN //SET SET RC=8 // ENDIF //* // IF (RC = 8) THEN //ERRPROC EXEC PROC=ERRORHANDLING // ENDIF
This example sets a synthetic return code based on a condition for subsequent decision making.
Issue | Possible Causes | Solutions |
---|---|---|
Steps running when they should be skipped | COND logic inverted (tests when to skip, not run) |
|
Steps skipped incorrectly | Incorrect comparison operator or return code value |
|
Unexpected return codes | Program error or misunderstood program behavior |
|
COND parameter ignored | Job abended (COND parameters don't apply after abends) |
|
Every job returns a final return code, which is used by job schedulers and dependent jobs to determine subsequent actions.
12//MYJOB JOB (ACCT),'MY NAME',MSGLEVEL=(1,1) //JOBRC JOBRC MAXIMUM
Return code handling is generally the same in both JES2 and JES3 environments, but there are some considerations:
Feature | JES2 | JES3 |
---|---|---|
Return code visibility | Standard format in job log | Standard format in job log |
Dependent job control | Through job scheduler or automation tools | Native dependent job control features |
Condition code treatment | Standard | Enhanced options with JES3 control statements |