Condition Names - Level 88
Condition names say exactly what they do - they give a name to a condition.
For example, in your programs we have used an indicator to tell whether we
have reached end of file. The processing checks the value of the indicator
to make sure that end of file has not been reached before each performance
of the loop. For clarity, we can give the end of file condition a name.
For example, if our indicator is named MORE-RECS and given an initial value
of YES (to indicate that YES there are more records), the end of file
condition will be met when the MORE-RECS indicator gets changed so it has a
value of NO. We can give the condition when MORE-RECS = "NO " a name by
using a condition name or a level 88. In the example below, the condition
MORE-RECS = "NO" will be given the condition name IT-IS-END-OF-FILE.
WORKING-STORAGE SECTION.
01 INDICATORS.
05 MORE-RECS PIC XXX VALUE "YES".
88 IT-IS-END-OF-FILE VALUE "NO ".
The level 88 condition name can now be used in the PROCEDURE DIVISION to
test the value of the indicator. For example, instead of coding:
PERFORM B-200-LOOP
UNTIL MORE-RECS = "NO ".
The programmer can code:
PERFORM B-200-LOOP
UNTIL IT-IS-END-OF-FILE.
As you can see, in this example the level 88 condition name takes the place
of the implied IF in the UNTIL clause. NOTE: An implied IF is a
condition that acts like an IF but does not have the syntax of the IF
statement or even the command IF.
The level 88 condition name can be used to give a name to the values in a
code field. For example, if you have full time employees and part-time
employees, your input could have the following setup.
01 EMPLOY-REC.
05 EMP-NO PIC X(9).
05 EMP-NAME PIC X(25).
05 EMP-TYPE PIC X.
88 FULL-TIME-EMPLOYEE VALUE "F".
88 PART-TIME-EMPLOYEE VALUE "P".
Note that a level 88 value is the only use of VALUE that is allowed in the
FILE SECTION. That is because the VALUE in this case is not assigning a
VALUE it is naming a condition. VALUE clauses that assign initial values
are not allowed in the FILE SECTION.
Using the level 88 condition name, the test to find out whether the employee
is full time can be written like this:
IF FULL-TIME-EMPLOYEE
PERFORM B-300-FULL-TIME-ROUTINE.
Without using the level 88 condition name, the test would look like this:
IF EMP-TYPE = "F"
PERFORM B-300-FULL-TIME-ROUTINE.
As can be seen, the condition name took the place of the condition meaning
that you do not have to name the field, use the relational operator and
state what you are testing the field against. All of that is implicit in
the condition name.
Multiple values:
The level 88 condition name can have multiple entries in the VALUE clause.
When a level 88 with multiple entries in the VALUE clause is tested, a match
to anyone of the values indicates a match. This is similar to using a
complex implied if with the OR. For example if FLAG-COLOR is the level 88
for the input field called INPUT-COLOR and FLAG-COLOR was given the value
"BLUE", "RED", "WHITE" then the following test would be true if the field
called INPUT-COLOR contained either BLUE or RED or WHITE.
05 INPUT-COLOR PIC X(10).
88 FLAG-COLOR VALUE "BLUE", "RED", "WHITE".
In the PROCEDURE DIVISION, the test would be:
IF FLAG-COLOR
MOVE "THIS IS A FLAG COLOR" TO MSG-PR.
MSG-PR will contain the message only if the INPUT-COLOR was either BLUE or
RED or WHITE.
Another example might involve finding out where someone is in school.
01 INPUT-REC.
05 ID-NO PIC X(5).
05 NAMZ PIC X(20).
05 YRS-SCHOOL PIC 99.
88 ELEM-SCHOOL VALUES 00 THRU 06.
88 JR-HIGH-SCHOOL VALUES 07, 08.
88 HIGH-SCHOOL VALUE 09 THRU 12.
88 COLLEGE VALUE 13 THRU 16.
88 ADVANCED VALUE 17 THRU 99.
This field can be tested in the PROCEDURE DIVISION in the following way:
B-200-LOOP.
...
IF ELEM-SCHOOL OR JR-HIGH-SCHOOL
ADD 1 TO PRE-HIGH-CT
ELSE
IF HIGH-SCHOOL
ADD 1 TO HIGH-CT
ELSE
IF COLLEGE
ADD 1 TO COLLEGE-CT
ELSE
ADD 1 TO ADV-CT.
Notice that the level 88 condition name takes the place of the condition.
The statement IF HIGH-SCHOOL accomplishes the same thing as saying IF
YRS-SCHOOL > 8 AND YRS-SCHOOL < 13.