COBOLbeginner
Condition Names (88-Levels)
Use 88-level condition names to give meaningful names to specific values of a data item and write self-documenting conditional logic.
An 88-level gives a name to a value. Instead of comparing against a literal everywhere, you name the meaning once.
An 88-level is like a labeled light switch position — instead of remembering that flipping the breaker to 'position 3' means the porch light is on, you flip a switch labeled PORCH-LIGHT-ON, and the wiring detail is hidden behind that name.
Key Concepts
1
05 WS-STATUS PIC X.
88 WS-ACTIVE VALUE 'A'.
88 WS-PENDING VALUE 'P'.
88 WS-CLOSED VALUE 'C'.2
IF WS-ACTIVE
PERFORM PROCESS-ORDER
END-IF.3
It occupies no storage. An 88-level is not a field. It is a test against its parent, evaluated wherever
it appears.
4
Why this is more than cosmetic. IF WS-STATUS = 'A' repeats a literal in every place that tests it.
Somebody types 'a' once, and the comparison silently fails — no compiler error, because both are valid
values for a PIC X.
IF WS-STATUS = 'A''a'PIC X
5
With a condition name the literal appears once, in the DATA DIVISION. A typo in WS-ACTVE does not
compile.
WS-ACTVE
6
Multiple values and ranges.
88 WS-VALID-STATUS VALUE 'A' 'P' 'S'.
88 WS-IN-RANGE VALUE 1 THRU 100.7
IF WS-VALID-STATUS now tests three values in one condition. As an IF it is three comparisons joined
with OR, repeated wherever the check is needed — and easy to update in one place and miss in another.
IF WS-VALID-STATUSIFOR
8
SET ... TO TRUE works in the other direction.
SET WS-ACTIVE TO TRUE. <- moves 'A' into WS-STATUSSET ... TO TRUE
9
So the mapping between the name and the value lives in exactly one place, for both reading and writing.
MOVE 'A' TO WS-STATUS puts the literal back into the procedure code and reintroduces the problem.
MOVE 'A' TO WS-STATUS
10
The idiom you will see constantly: end-of-file flags.
05 WS-EOF-FLAG PIC X VALUE 'N'.
88 END-OF-FILE VALUE 'Y'.11
READ CUST-FILE
AT END SET END-OF-FILE TO TRUE
END-READ.12
PERFORM UNTIL END-OF-FILE
...
END-PERFORM.13
That reads almost like prose, and it is why production COBOL is dense with 88-levels. Being able to read
them is not optional for understanding any real program's control flow.
14
One caution. Setting one 88-level to true overwrites the parent field, so it makes every sibling
condition false. That is usually what you want, and it is worth knowing that these are views of a single
field rather than independent flags.
15
What the interviewer is probing.1. "What does an 88-level buy you?" Probing: the value. Stalls: "Shorter code." Moves up:
the condition is named once, so the logic reads as business meaning rather than a magic value
comparison scattered everywhere.
16
2. "Can you assign through a condition name?" Probing: the lesser-known feature. Stalls:
"No." Moves up: yes — SET condition-name TO TRUE puts the associated value into the field, which
keeps the literal in one place.
17
3. "What happens if an 88 lists several values?" Probing: the semantics. Stalls: "It takes
the first." Moves up: the condition is true if the field matches any of them, which is how you
express a set membership test.
18
4. "Why does this matter for maintenance?" Probing: the argument. Stalls: "Style." *Moves
up:* when the valid codes change you edit the data division, not every branch in the procedure
division.