Easytrieve CASE Statement

CASE provides structured multi-way branching on a single field value—cleaner than ten ELSE-IF lines when years of service, status code, or region drives different processing. Syntax opens with CASE field-name, lists WHEN compare-literal or WHEN low THRU high ranges each followed by statements, optional OTHERWISE for default path, and mandatory END-CASE terminator. First satisfied WHEN wins; later WHEN clauses skip. Without OTHERWISE and no match, control falls through to statement after END-CASE. CASE nests inside IF or other CASE blocks per Broadcom grammar. Broadcom vacation example: EMPYRS CASE with WHEN 0 THRU 4, WHEN 5 THRU 10, OTHERWISE assigning different DISPLAY messages. Beginners duplicate ranges across WHEN lines or forget END-CASE causing compile errors. This page teaches full grammar, THRU semantics, OTHERWISE patterns, nesting, comparison with IF and EQ THRU, performance on hot paths, and testing boundary values at range edges.

Progress0 of 0 lessons

Statement Format

text
1
2
3
4
5
6
7
8
9
10
11
12
CASE field-name WHEN compare-literal-1 [THRU range-literal-1] statement-1 WHEN compare-literal-n [THRU range-literal-n] statement-n [OTHERWISE statement-default] END-CASE

Broadcom Vacation Example

text
1
2
3
4
5
6
7
8
9
10
11
12
FILE EMPLOYEE EMPYRS 5 2 N JOB INPUT EMPLOYEE CASE EMPYRS WHEN 0 THRU 4 DISPLAY 'ONE WEEK VACATION' WHEN 5 THRU 10 DISPLAY 'TWO WEEKS VACATION' OTHERWISE DISPLAY 'THREE WEEKS VACATION' END-CASE

EMPYRS two-digit numeric years of service: zero through four gets one week message, five through ten two weeks, all higher values OTHERWISE three weeks. Boundary four and five belong to different branches—test both.

WHEN Clause Semantics

WHEN forms
WHEN formMatches whenExample
Single literalField equals literalWHEN 99
THRU rangeField in inclusive rangeWHEN 10 THRU 19
Multiple literalsPer manual grouped WHEN syntaxWHEN A WHEN B

OTHERWISE Default Branch

OTHERWISE executes when no WHEN matched—catch-all for unexpected codes. Omit OTHERWISE when fall-through to code after END-CASE is intentional silent ignore. Data quality jobs often OTHERWISE DISPLAY unknown code and increment error counter. Document whether unknown status should fail job or continue.

CASE Versus IF ELSE-IF Chain

IF DEPT EQ 10 ... ELSE-IF DEPT EQ 20 equivalent to CASE DEPT WHEN 10 ... WHEN 20. CASE wins readability when many values of same field. IF wins when conditions mix unrelated fields— IF DEPT EQ 10 AND STATUS EQ ACTIVE. Do not force CASE when no single driving field exists.

Nesting Rules

Broadcom allows CASE nested in CASE, CASE in IF, IF in WHEN body. Deep nesting hurts readability—extract inner CASE to PROC when beyond two levels. Each nested CASE needs its own END-CASE—match terminators carefully in code review.

text
1
2
3
4
5
6
7
8
9
10
11
CASE REGION WHEN 'E' CASE STATUS WHEN 'A' PERFORM ACTIVE-EAST WHEN 'I' PERFORM INACTIVE-EAST END-CASE WHEN 'W' PERFORM WEST-LOGIC END-CASE

Overlap and Order

First matching WHEN executes; overlapping ranges cause earlier WHEN to shadow later—order WHEN from most specific to general or ensure ranges disjoint. WHEN 0 THRU 10 before WHEN 5 THRU 7 means five through seven never reach second WHEN if first matches—actually first includes five through seven so second is dead code. Static analysis in review catches dead WHEN branches.

Statements Inside WHEN

WHEN body may contain multiple statements—DISPLAY, assignment, PERFORM, nested CASE. No requirement for single statement. Indent for maintenance. Large bodies suggest PERFORM PROC per branch keeping CASE skeleton visible.

Testing CASE Logic

  1. Test value below lowest range, each boundary, mid-range, above highest.
  2. Test OTHERWISE with value outside all WHEN ranges.
  3. Test no OTHERWISE no match falls through after END-CASE.
  4. Verify numeric versus character CASE field type matches literals.
  5. Regression test after adding new WHEN in middle of list.

Common CASE Mistakes

  • Missing END-CASE.
  • Overlapping WHEN ranges with wrong order.
  • Using CASE when conditions are not on one field.
  • Character literal without quotes on alphabetic field.
  • Assuming last WHEN wins—first match wins.
  • Deep nest without PROC extraction.

Explain It Like I'm Five

CASE is a vending machine with labeled buttons for one knob position. The knob is your field value. When knob points at five, the machine looks for the button labeled five or the range that includes five and drops that snack. OTHERWISE is the default snack if no label fits. END-CASE is closing the machine door when you are done choosing.

Exercises

  1. Write CASE on STATUS with three WHEN codes and OTHERWISE.
  2. Convert four-line ELSE-IF on REGION to CASE form.
  3. Identify dead WHEN in overlapping range example.
  4. Add nested CASE for STATUS inside REGION WHEN E.
  5. List test values for EMPYRS vacation example.

Quiz

Test Your Knowledge

1. CASE field-name compares:

  • Field value against WHEN literals or ranges
  • Two files for merge
  • JCL parameters
  • Sort keys only

2. WHEN 0 THRU 4 includes:

  • Values 0 through 4 inclusive
  • Only 0 and 4
  • Values above 4
  • Compile error

3. If no WHEN matches and no OTHERWISE:

  • Execution continues after END-CASE
  • Program abends always
  • Infinite loop
  • FILE closes

4. END-CASE is:

  • Required terminator for each CASE
  • Optional decoration
  • Same as END-IF
  • Library only

5. CASE can nest:

  • Inside other CASE or IF blocks per rules
  • Never
  • Only in REPORT
  • Only in JCL
Published
Read time15 min
AuthorMainframeMaster
Reviewed by MainframeMaster teamVerified: Broadcom Easytrieve Report Generator 11.6 CASE and END-CASE statementsSources: Broadcom Easytrieve 11.6 Language Reference CASE and END-CASEApplies to: Easytrieve CASE multi-way branching