Easytrieve ELSE Control Flow

IF handles the happy path; ELSE handles everything else. In Easytrieve ELSE is optional, conditionless, and terminal—it must be the last branch before END-IF when present. Beginners underuse ELSE and leave GIVING fields stale on SEARCH miss, or overuse ELSE when ELSE-IF bands would read cleaner. ELSE is the right tool for unknown department codes, unexpected status values, and default messages on reports that must print every row. It pairs with audit counters, error file WRITE, and MOVE of literal defaults. This chapter page complements the ELSE statement reference with batch patterns: when catch-all beats another ELSE-IF, how ELSE nests secondary IF, formatting rules requiring ELSE on its own line, and maintainability habits that keep ELSE blocks short and named by purpose in comments.

Progress0 of 0 lessons

ELSE Position in the IF Group

text
1
2
3
4
5
6
7
8
9
10
IF PAY-TYPE EQ 'S' MOVE SALARY-RATE TO WS-RATE ELSE-IF PAY-TYPE EQ 'H' MOVE HOURLY-RATE TO WS-RATE ELSE-IF PAY-TYPE EQ 'C' MOVE COMM-RATE TO WS-RATE ELSE MOVE ZERO TO WS-RATE ADD 1 TO UNKNOWN-TYPE-CNT END-IF

Three known pay types map to rates. ELSE handles commission typos, blank types, and future codes not yet in the ELSE-IF list. UNKNOWN-TYPE-CNT supports trailer audit. Without ELSE, WS-RATE might retain a prior record's value—dangerous on reports.

ELSE Versus ELSE-IF — Decision Guide

Choose the right branch
SituationUse
Another testable conditionELSE-IF
Everything not matched aboveELSE
No false-path action neededOmit ELSE
False path only if outer IF trueNested IF inside true branch

ELSE With SEARCH Miss

text
1
2
3
4
5
6
7
SEARCH STATE-TAB WITH ST-CODE GIVING ST-NAME IF STATE-TAB * use ST-NAME on report ELSE ST-NAME = '** INVALID STATE **' ADD 1 TO ST-ERR-CNT END-IF

Classic decode ELSE: literal default plus counter. Operations reviews ST-ERR-CNT in job log summary procedures. ELSE is not optional when auditors require explicit handling of invalid codes—even if the literal is spaces, you must MOVE in ELSE to clear stale GIVING.

ELSE on Its Own Source Line

Broadcom requires ELSE on a separate statement unless using period-space alternate form. Do not append ELSE to the prior line in maintenance-friendly source. Align ELSE with IF and ELSE-IF in column area B for readability. Comments above ELSE should state business rule—UNKNOWN PRODUCT CODES TO ERROR FILE.

Nested IF Inside ELSE

text
1
2
3
4
5
6
7
8
9
IF AMT GT 10000 MOVE 'HIGH' TO WS-TIER ELSE IF AMT GT 5000 MOVE 'MID' TO WS-TIER ELSE MOVE 'LOW' TO WS-TIER END-IF END-IF

Outer ELSE contains inner IF for sub-bands below ten thousand. Alternative: flat ELSE-IF chain if all tiers are mutually exclusive at one level. Nested version emphasizes that mid/low only matter when not high—same outcome here, different readability. Pick one style per program.

ELSE and GOTO JOB

ELSE may end with GOTO JOB to skip PRINT for bad rows after handling error. Ensure END-IF still appears before label targets confuse the compiler. Pattern: IF valid PRINT; ELSE WRITE error; GOTO JOB; END-IF—GOTO inside ELSE skips remainder of iteration.

When to Skip ELSE

  • Bare IF guards action only when true—no false-path work.
  • Complete ELSE-IF coverage of enumerated codes with no unknowns allowed—job may abend on ELSE via STOP instead.
  • Outer IF false and inner logic handled by separate subsequent IF—not catch-all.

ELSE in SCREEN Validation

Online maps use ELSE to show error messages when validation IF fails—MOVE message to SCREEN field in ELSE, REFRESH or RESHOW in AFTER-SCREEN per screen rules. Batch JOB patterns transfer directly with DISPLAY instead of SCREEN map fields.

Common ELSE Mistakes

ELSE pitfalls
MistakeFix
ELSE-IF after ELSEMove new tests above ELSE
Empty ELSE with stale fieldsMOVE defaults in ELSE
Duplicate logic in every ELSE-IF and ELSEExtract procedure
Expecting END-ELSEUse single END-IF only

Explain It Like I'm Five

IF and ELSE-IF are special cases—red lunch ticket, blue lunch ticket. ELSE is everyone who did not get a special ticket still gets a plain sandwich so nobody goes hungry. You only need one plain-sandwich line at the end. If you forget the plain sandwich line, some kids might keep yesterday's lunch bag by mistake—that is stale data without ELSE.

Exercises

  1. Add ELSE with counter to a three-branch ELSE-IF pay type example.
  2. Write SEARCH decode with ELSE MOVE and error tally.
  3. Convert nested IF tier example to flat ELSE-IF chain—compare readability.
  4. Identify when ELSE can be omitted in a validation-only IF.
  5. Add ELSE branch that WRITE error and GOTO JOB.

Quiz

Test Your Knowledge

1. ELSE runs when:

  • All preceding IF and ELSE-IF conditions are false
  • Only the first IF is false
  • Every record
  • Compile time

2. Maximum ELSE branches per IF group:

  • One
  • Unlimited
  • Two
  • Zero only

3. ELSE after SEARCH miss often:

  • MOVE default text or write error record
  • CLOSE all files
  • Triggers SORT
  • Skips END-IF

4. ELSE requires:

  • No separate terminator—END-IF closes it
  • END-ELSE
  • END-DO
  • STOP

5. ELSE-IF after ELSE is:

  • Invalid—ELSE must be last before END-IF
  • Required
  • Same as nested IF
  • JCL only
Published
Read time16 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 ELSE, IF StatementSources: Broadcom Easytrieve 11.6 IF Statement; ELSE formatting rulesApplies to: Easytrieve ELSE catch-all branches in batch and online logic