Master Mainframe Technologies - COBOL, JCL, DB2, VSAM, CICS & More
ABEND Codes SQLCODEs File Status Interview Prep Contact
← Back to JCL Utilities
JCL Utilities | Intermediate | JCL

JCL Condition Codes

Problem Description

Write JCL that runs STEP2 only if STEP1 returns RC=0, and STEP3 runs if either step failed.

Expected Output

Conditional step execution

Hints

Use COND parameter or IF/THEN/ELSE.

Solution

//CONDJOB JOB (ACCT),CLASS=A //* //STEP1 EXEC PGM=PROG1 //SYSPRINT DD SYSOUT=* //* //* STEP2 RUNS ONLY IF STEP1 RC=0 //STEP2 EXEC PGM=PROG2,COND=(0,NE,STEP1) //SYSPRINT DD SYSOUT=* //* //* STEP3 RUNS IF ANY PREVIOUS STEP FAILED (RC > 0) //STEP3 EXEC PGM=CLEANUP,COND=(0,EQ) //SYSPRINT DD SYSOUT=* //

Explanation:

COND=(0,NE,STEP1) skips if STEP1 RC != 0. COND=(0,EQ) skips if ALL RCs = 0.