Level-88 condition names

The first lesson on level numbers introduced 88 as a condition name. This is what that name is for: a test on a field, written once in the data division and used in every place the program asks the question, so the value "D" appears in one line instead of forty.

A name for a value

An 88 entry sits directly under the field it tests, takes no storage and holds no picture. It gives a name to one value or to a list of them, and the name is used as a condition:

IDENTIFICATION DIVISION. PROGRAM-ID. COND88. DATA DIVISION. WORKING-STORAGE SECTION. 01 ORDER-STATUS PIC X VALUE "N". 88 STATUS-NEW VALUE "N" FALSE "X". 88 STATUS-DONE VALUE "D". 01 QTY-F PIC 9(2) VALUE 3. 88 QTY-SMALL VALUE 1 THRU 5 FALSE 0. 88 QTY-EDGE VALUE 0, 99. PROCEDURE DIVISION. IF STATUS-NEW DISPLAY "new order" END-IF. IF NOT STATUS-DONE DISPLAY "not done yet" END-IF. SET STATUS-DONE TO TRUE. DISPLAY "status " ORDER-STATUS. SET STATUS-NEW TO FALSE. DISPLAY "after false " ORDER-STATUS. SET QTY-SMALL TO TRUE. DISPLAY "small true " QTY-F. SET QTY-SMALL TO FALSE. DISPLAY "small false " QTY-F. SET QTY-EDGE TO TRUE. DISPLAY "edge true " QTY-F. STOP RUN.

cobc -x -free -Wall -o cond88 cond88.cob
./cond88

new order
not done yet
status D
after false X
small true 01
small false 00
edge true 00

IF STATUS-NEW is the whole condition: no field, no operator, no literal. The compiler reads it as ORDER-STATUS = "N", and the program never has to spell that out.

SET ... TO TRUE

SET ... TO TRUE stores the value the condition names. SET STATUS-DONE TO TRUE put D into the field, which the next line printed, and the program then tested for the new order and found it false.

The advantage over MOVE "D" TO ORDER-STATUS is that the letter exists in one place. A program that has to change the code for a completed order changes the 88 entry and nothing else, and a search for the letter finds the one line that defines it.

SET ... TO FALSE and the FALSE clause

SET ... TO FALSE stores a value that is not the condition, and that value has to be declared: the clause FALSE IS of the 88 entry. Without it the compiler refuses the statement:

IDENTIFICATION DIVISION. PROGRAM-ID. BADFALSE. DATA DIVISION. WORKING-STORAGE SECTION. 01 STATUS-F PIC X VALUE "N". 88 STATUS-NEW VALUE "N". PROCEDURE DIVISION. SET STATUS-NEW TO FALSE. DISPLAY STATUS-F. STOP RUN.

cobc -x -free -Wall -o badfalse badfalse.cob
./badfalse

badfalse.cob:10: error: field does not have a FALSE clause
8 |
9 | PROCEDURE DIVISION.
10 > SET STATUS-NEW TO FALSE.
11 | DISPLAY STATUS-F.
12 | STOP RUN.

The block above is a deliberate mistake and builds nothing, which is why the command is followed by the error and not by a run. In the first program the clause is there: FALSE "X" for the status and FALSE 0 for the quantity, and SET QTY-SMALL TO FALSE therefore stored 00.

A range of values

VALUE ... THRU names a range, and the condition is true anywhere inside it. A range works on numbers and on text, in the order of the collating sequence:

IDENTIFICATION DIVISION. PROGRAM-ID. GRADES. DATA DIVISION. WORKING-STORAGE SECTION. 01 MARK-F PIC 9(3) VALUE 72. 88 MARK-FAIL VALUE 0 THRU 49. 88 MARK-PASS VALUE 50 THRU 100. 01 LETTER-F PIC X VALUE "C". 88 LETTER-EARLY VALUE "A" THRU "M". PROCEDURE DIVISION. IF MARK-PASS AND NOT MARK-FAIL DISPLAY "mark " MARK-F " is a pass" END-IF. IF LETTER-EARLY DISPLAY "letter " LETTER-F " is in the first half" END-IF. IF MARK-FAIL DISPLAY "fail" ELSE DISPLAY "not a fail" END-IF. STOP RUN.

cobc -x -free -Wall -o grades grades.cob
./grades

mark 072 is a pass
letter C is in the first half
not a fail

The two ranges of the mark cover 0 to 49 and 50 to 100, so the test MARK-PASS AND NOT MARK-FAIL has a redundant half: a value inside 50 to 100 cannot be inside 0 to 49. The redundancy is harmless and often useful as documentation; it is also a sign that the 88 names were written by hand and not derived, so a value of 101 falls outside both, and the only line that says anything about it is the ELSE of the later test, which prints not a fail for a mark the school never gave.

NOT and combined conditions

An 88 name is a condition like any other: NOT in front of it negates it, and AND and OR join it to its neighbours. The third test in the program above wrote the negative case with IF MARK-FAIL and an ELSE, which is the same question as the second test and prints the answer the reader expects.

One rule follows from the fact that an 88 is only a name: the field it tests still exists, and a program can write any value into it with a MOVE. A code of "Z" moved into ORDER-STATUS makes both STATUS-NEW and STATUS-DONE false, and no compiler here reports it. The next lesson combines these conditions properly and shows where the parentheses change the answer.

Exercises

  1. Add an 88 for a cancelled order with the value "C" and set it true. What does the status field hold afterwards?
  2. Remove the FALSE "X" clause and keep the SET ... TO FALSE. Copy the compiler message.
  3. Change MARK-F to 49, 50 and 101 and run the grades program each time. Which test reports what?
  4. Write an 88 for the range "A" THRU "Z" and test it on a lower case letter. Is the condition true, and why?

Questions

A new set of questions in a new order every time. Choose one answer for each, then check.

  1. What does a level-88 entry hold?

    Answer

    Nothing: it is a name for a value or a range of the field above it

    An 88 entry takes no storage; the field it is written under holds the value.

  2. What does SET STATUS-DONE TO TRUE do?

    Answer

    It stores the value the 88 names into the field

    The program prints D after the statement, because SET TO TRUE moves the value of the condition into the field.

  3. Which clause must an 88 have for SET ... TO FALSE to compile?

    Answer

    FALSE with a value that is not in the condition

    The program on this page fails with "field does not have a FALSE clause" until FALSE "X" is added.

  4. What is true of an 88 with VALUE 1 THRU 5?

    Answer

    It is true for every value from 1 to 5

    THRU names a continuous range, and SET ... TO TRUE of a range stores its first value.

  5. What does this program print? IDENTIFICATION DIVISION. PROGRAM-ID. Q5. DATA DIVISION. WORKING-STORAGE SECTION. 01 S-F PIC X VALUE "N". 88 S-NEW VALUE "N". PROCEDURE DIVISION. IF S-NEW DISPLAY "new" ELSE DISPLAY "old" END-IF. STOP RUN.

    Answer

    new

    The field holds N, so the condition named for N is true.

  6. What does this program print? IDENTIFICATION DIVISION. PROGRAM-ID. Q6. DATA DIVISION. WORKING-STORAGE SECTION. 01 S-F PIC X VALUE "N". 88 S-NEW VALUE "N". PROCEDURE DIVISION. SET S-NEW TO TRUE. DISPLAY "[" S-F "]". STOP RUN.

    Answer

    [N]

    SET TO TRUE stores the value of the condition, which is the letter N.

  7. What does this program print? IDENTIFICATION DIVISION. PROGRAM-ID. Q7. DATA DIVISION. WORKING-STORAGE SECTION. 01 Q-F PIC 9(2) VALUE 7. 88 Q-SMALL VALUE 1 THRU 5. 88 Q-BIG VALUE 6 THRU 10. PROCEDURE DIVISION. IF Q-SMALL DISPLAY "small" END-IF. IF Q-BIG DISPLAY "big" END-IF. STOP RUN.

    Answer

    big

    Seven is inside 6 to 10 and outside 1 to 5, so only the second condition is true.

  8. What does this program print? IDENTIFICATION DIVISION. PROGRAM-ID. Q8. DATA DIVISION. WORKING-STORAGE SECTION. 01 L-F PIC X VALUE "C". 88 L-EARLY VALUE "A" THRU "M". PROCEDURE DIVISION. IF NOT L-EARLY DISPLAY "late" ELSE DISPLAY "early" END-IF. STOP RUN.

    Answer

    early

    C is inside A to M, so the negated condition is false and the ELSE branch runs.

  9. What does this program print? IDENTIFICATION DIVISION. PROGRAM-ID. Q9. DATA DIVISION. WORKING-STORAGE SECTION. 01 S-F PIC X VALUE "N". 88 S-NEW VALUE "N" FALSE "X". PROCEDURE DIVISION. SET S-NEW TO FALSE. DISPLAY "[" S-F "]". STOP RUN.

    Answer

    [X]

    SET TO FALSE stores the FALSE value of the entry, which is the letter X.

  10. A code of "Z" is moved into a status field whose 88 names are only "N" and "D". What happens?

    Answer

    Neither condition is true, and nothing reports the bad code

    The 88 entries name values, they do not restrict the field, so an unknown value makes every condition false and is otherwise silent.

The code on this page was built with cobc (GnuCOBOL) 3.2.0 and run on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev