Level-88 condition names
Code full of IF WS-STATUS = "C" OR WS-STATUS = "X" makes the reader look
up what "C" and "X" mean. COBOL's answer is the level-88 condition
name: a named condition attached to a field.
IDENTIFICATION DIVISION.
PROGRAM-ID. COND88.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-STATUS PIC X VALUE "A".
88 ACCT-ACTIVE VALUE "A".
88 ACCT-DORMANT VALUE "D".
88 ACCT-CLOSED VALUE "C" "X".
01 WS-SCORE PIC 999 VALUE 640.
88 SCORE-POOR VALUE 0 THRU 579.
88 SCORE-FAIR VALUE 580 THRU 669.
88 SCORE-GOOD VALUE 670 THRU 999.
PROCEDURE DIVISION.
IF ACCT-ACTIVE
DISPLAY "ACTIVE ACCOUNT"
END-IF
SET ACCT-CLOSED TO TRUE
DISPLAY "STATUS IS NOW " WS-STATUS
IF ACCT-CLOSED
DISPLAY "CLOSED ACCOUNT"
END-IF
IF SCORE-FAIR
DISPLAY "FAIR CREDIT SCORE"
END-IF
IF NOT SCORE-POOR
DISPLAY "NOT A POOR SCORE"
END-IF
STOP RUN.
Output:
ACTIVE ACCOUNT
STATUS IS NOW C
CLOSED ACCOUNT
FAIR CREDIT SCORE
NOT A POOR SCORE
How it works
An 88 entry has no storage of its own. It sits under a field (its
conditional variable) and names one or more values of that field:
VALUE "A"— a single valueVALUE "C" "X"— any of a list (commas are optional)VALUE 580 THRU 669— a range, inclusive at both ends
IF ACCT-CLOSED is exactly the same test as
IF WS-STATUS = "C" OR WS-STATUS = "X" — only now it's readable, and if the
business adds a new closed code, you change one line in the data division
instead of every IF in the program.
SET ... TO TRUE
To make a condition true, don't MOVE the code. Use:
SET ACCT-DORMANT TO TRUE
That moves "D" into WS-STATUS. If the 88 lists several values,
SET uses the first one — SET ACCT-CLOSED TO TRUE stores "C",
as the output shows.
You can't SET a condition to FALSE unless the 88 has a
WHEN SET TO FALSE clause; in practice you SET a different condition
to TRUE instead.
Switches and flags
The most common use is a yes/no flag:
01 WS-EOF-FLAG PIC X VALUE "N".
88 END-OF-FILE VALUE "Y".
88 NOT-END-OF-FILE VALUE "N".
Loops then read PERFORM ... UNTIL END-OF-FILE — you'll write exactly this
when you process files.
On the job
Copybooks for real record layouts are full of 88s: status codes, transaction types, product categories. When you're asked "where does the program handle closed accounts?", search for the 88 name, not the literal — and when you add a code, add it to the 88.
Your task
A nightly job reviews each account's status. Read two lines: the
one-character status code into WS-STATUS, and the days since the
last transaction into WS-DAYS.
Add level-88 condition names to WS-STATUS:
| Name | Values |
|---|---|
ACCT-ACTIVE |
A |
ACCT-DORMANT |
D |
ACCT-CLOSED |
C, X |
ACCT-VALID |
A, D, C, X |
Rules:
- Not a valid code → display
INVALID STATUSand nothing else. - Active and more than 365 days → make it dormant with
SET, displayMARKED DORMANT. - Dormant and fewer than 30 days → make it active with
SET, displayREACTIVATED. - Every valid code ends with
STATUS:and the (possibly new) code.
For A and 400:
MARKED DORMANT
STATUS: D
Test the codes only through the 88 names, and change the status only with
SET ... TO TRUE.