Level 88 conditions in COBOL
Level 88 gives a data value a name you can test and SET like a flag.
IDENTIFICATION DIVISION.
PROGRAM-ID. CONDITION-NAMES.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 LOCK-STATE PIC X VALUE "C".
88 LOCK-OPEN VALUE "O".
88 LOCK-CLOSED VALUE "C".
88 LOCK-FAULTED VALUE "F" "X".
PROCEDURE DIVISION.
*> Level 88 names a condition; SET ... TO TRUE stores its value.
IF LOCK-CLOSED DISPLAY "Canal gate sealed" END-IF
SET LOCK-OPEN TO TRUE
IF LOCK-OPEN DISPLAY "Gate open, tug may pass" END-IF
STOP RUN.
How it works
- Three
88entries name the states ofLOCK-STATE; one lists two values. IF LOCK-CLOSEDreads as prose but testsLOCK-STATE = "C".SET LOCK-OPEN TO TRUEstores the value that makes the condition hold.
Keywords and builtins used here
DATADISPLAYDIVISIONIDENTIFICATIONIFPROCEDURESECTIONSETSTOPTRUE
The run, in numbers
- Lines
- 14
- Characters to type
- 432
- Tokens
- 56
- Three-star pace
- 40 tpm
At the three-star pace of 40 tokens a minute, this run takes about 84 seconds.
Step 3 of 3 in Conditions, step 15 of 27 in Language basics.