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.
123456789101112CASE 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
123456789101112FILE 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 form | Matches when | Example |
|---|---|---|
| Single literal | Field equals literal | WHEN 99 |
| THRU range | Field in inclusive range | WHEN 10 THRU 19 |
| Multiple literals | Per manual grouped WHEN syntax | WHEN A WHEN B |
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.
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.
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.
1234567891011CASE REGION WHEN 'E' CASE STATUS WHEN 'A' PERFORM ACTIVE-EAST WHEN 'I' PERFORM INACTIVE-EAST END-CASE WHEN 'W' PERFORM WEST-LOGIC END-CASE
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.
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.
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.
1. CASE field-name compares:
2. WHEN 0 THRU 4 includes:
3. If no WHEN matches and no OTHERWISE:
4. END-CASE is:
5. CASE can nest: