JCL

Using JCL IF/THEN/ELSE and Return Codes to Protect a Claims Batch Flow

Learn how JCL IF/THEN/ELSE conditions and clear return-code rules protect claims batch flows from unsafe downstream processing.

Job stepReturn codeSafe decisionNext step
Original DBala learning flow — a visual summary of this article’s practical decision path.

Short introduction

A batch job can finish with a condition code and still leave an operational problem. For example, an extract step may complete with RC=4 because it found no qualifying records. That may be acceptable on a quiet business day. But a subsequent load step should not always run simply because the previous program did not abend. If a required input file is empty because an upstream transfer failed, continuing to update a DB2 table can create a misleading reconciliation result.

JCL IF/THEN/ELSE/ENDIF statements let a job express the intended operational decision: run the next step only when the earlier outcome is suitable. Used with clear return-code conventions, they make a job easier to support and reduce risky “everything ran” failures. This article uses a fictional healthcare-claims batch flow; adapt the thresholds, dataset names, and standards to your own environment.

Real-world production use case

Imagine a nightly claims process with three stages:

1. CLMEDIT reads an incoming file and writes valid claim records plus a reject report.
2. CLMLOAD loads or updates a staging table using the valid-record file.
3. CLMRECON produces totals for operations and downstream teams.

The application team agrees on these return codes for the edit program:

Without conditional JCL, a CLMLOAD step might attempt to process a missing or partial output dataset. With conditional control, the job can run the load only after RC=0, while still creating a useful report for RC=4 or RC=8. Operations gets a clear step outcome instead of needing to infer intent from a long spool listing.

Step-by-step explanation

### 1. Define the meaning of return codes before writing JCL

The most important work happens outside the IF statement. Document what each return code means for the program and job stream. A return code should describe an outcome, not merely a technical event. For example, RC=4 from a utility can be a warning, but RC=4 from an edit program may mean rejected claims must be reviewed.

Avoid a blanket rule such as “anything below 8 is okay.” It can silently authorize a DB2 update after an application-level warning. The step owner, application support team, and scheduler standards should decide the acceptable ranges.

### 2. Place the decision immediately after the producing step

Code the conditional block after the step whose result controls the next action. This keeps the job flow readable. CLMEDIT creates the file used by CLMLOAD, so the load condition belongs directly after CLMEDIT.

Use named step identifiers consistently. A condition such as CLMEDIT.RC = 0 tells a support analyst exactly which result is being evaluated. It is clearer than relying on an implicit “last executed step” interpretation in a complex job.

### 3. Separate the load decision from the reporting decision

Not every dependent step has the same safety requirement. Loading DB2 changes data and usually needs the strictest condition. Reconciliation is generally read-only and can be valuable after a warning or controlled business failure. Give each action its own condition rather than putting all later steps under one large block.

### 4. Ensure the program and JCL agree on output handling

If CLMEDIT can return RC=4, decide whether it creates the valid-record file, creates an empty file, or deletes it. The JCL must match that contract. A conditional load is safer than depending on an empty dataset, but the program’s file-close and allocation behavior still needs to be known.

For DB2 load programs, also define commit scope, restart handling, and what happens if the update step fails midway. IF/THEN/ELSE controls whether a step starts; it does not make a partially completed update reversible.

### 5. Test each branch deliberately

In a test region, exercise at least four scenarios: clean input (RC=0), expected warning (RC=4), data failure (RC=8), and an abend. Check the JES log to confirm which steps executed, which were bypassed, and which return code the job reported. Save representative spool output or test evidence with the change record according to local practice.

Example JCL

The following simplified job runs the DB2 staging load only for a clean edit result. It runs reconciliation for edit return codes from 0 through 8, so a report is available for normal, warning, and business-error outcomes. It is illustrative only: use your site’s PROC libraries, DB2 attachment method, security rules, and dataset naming conventions.

//CLMDAILY JOB (ACCT),'CLAIMS BATCH',CLASS=A,MSGCLASS=X,
//             NOTIFY=&SYSUID
//*
//CLMEDIT  EXEC PGM=CLMEDIT
//STEPLIB  DD  DISP=SHR,DSN=APP.TEST.LOADLIB
//INCLAIM  DD  DISP=SHR,DSN=APP.TEST.CLAIMS.INCOMING
//VALIDOUT DD  DISP=(NEW,CATLG,DELETE),
//             DSN=APP.TEST.CLAIMS.VALID(+1),
//             SPACE=(CYL,(10,5)),DCB=(RECFM=FB,LRECL=300,BLKSIZE=0)
//REJECTS  DD  SYSOUT=*
//SYSOUT   DD  SYSOUT=*
//*
//IFLOAD   IF (CLMEDIT.RC = 0) THEN
//CLMLOAD  EXEC PGM=IKJEFT01,DYNAMNBR=20
//SYSTSPRT DD  SYSOUT=*
//SYSTSIN  DD  *
  DSN SYSTEM(DBT1)
  RUN PROGRAM(CLMLOAD) PLAN(CLMPLAN) LIBRARY('APP.TEST.LOADLIB')
  END
/*
//VALIDIN  DD  DISP=SHR,DSN=APP.TEST.CLAIMS.VALID(0)
//SYSOUT   DD  SYSOUT=*
//         ENDIF
//*
//IFRECON  IF (CLMEDIT.RC LE 8) THEN
//CLMRECON EXEC PGM=CLMRECON
//VALIDIN  DD  DISP=SHR,DSN=APP.TEST.CLAIMS.VALID(0)
//REPORT   DD  SYSOUT=*
//SYSOUT   DD  SYSOUT=*
//         ELSE
//OPSNOTE  EXEC PGM=IEBGENER
//SYSUT1   DD  *,DLM=##
CLMEDIT FAILED TECHNICALLY. REVIEW THE FAILED STEP BEFORE RERUN.
##
//SYSUT2   DD  SYSOUT=*
//SYSPRINT DD  SYSOUT=*
//SYSIN    DD  DUMMY
//         ENDIF

A few details matter. The IFLOAD block explicitly permits only zero. The IFRECON block permits values through 8, but that threshold is an example, not a universal standard. The ELSE message does not repair the failure; it leaves a visible operational marker. In a production schedule, alerts and completion-code rules should also match this design.

Common mistakes

Practical checklist

Summary

JCL conditional processing is a simple but important batch-control tool. It turns return codes into deliberate operational choices: load trusted data, report controlled warnings, and stop unsafe downstream work after serious failures. The strongest design combines explicit return-code contracts, narrowly scoped conditions, readable step names, and branch testing. In claims-style processing and other regulated batch flows, that clarity helps teams support jobs safely without assuming that a nonzero condition code always means the same thing.

← Back to all articles