Conditions and relation tests
| Relational tests | |
| Level 88 names | |
| Class tests |
Relational tests
COBOL compares with =, NOT =, GREATER THAN, LESS THAN, and their abbreviations (>, <, >=, <=). Tests appear inside IF and EVALUATE sentences:
IF WS-HOURS > 40
COMPUTE WS-PAY = WS-HOURS * WS-RATE * 1.5
END-IF.
Level 88 names
Level 88 gives a name to a value or range. The condition name then reads like a flag in IF sentences:
01 WS-STATUS PIC X.
88 WS-OK VALUE "A".
88 WS-ERROR VALUE "E" "F".
Class tests
CLASS tests check the shape of a field: NUMERIC, ALPHABETIC, ALPHABETIC-UPPER, and ALPHABETIC-LOWER. They are the safe way to validate input before arithmetic:
IF WS-INPUT IS NUMERIC
MOVE WS-INPUT TO WS-COUNT
END-IF.
Next: IF, ELSE and EVALUATE
Article author: Arthur Isaev