Home › COBOL Tutorial › COBOL class tests and condition names
COBOL class tests and condition names
NUMERIC, ALPHABETIC and level 88.
IS NUMERIC and IS ALPHABETIC test what a field contains, which is useful to validate input. A level 88 item is a named condition on the field above it, and SET name TO TRUE gives the field that value.
Example code
IDENTIFICATION DIVISION.
PROGRAM-ID. CLS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A-VAL PIC X(3) VALUE "123".
01 B-VAL PIC X(3) VALUE "abc".
01 SW-CODE PIC X VALUE "A".
88 IS-ACTIVE VALUE "A".
88 IS-CLOSED VALUE "C".
PROCEDURE DIVISION.
IF A-VAL IS NUMERIC
DISPLAY "A numeric"
END-IF.
IF B-VAL IS NUMERIC
DISPLAY "B numeric"
ELSE
DISPLAY "B not numeric"
END-IF.
IF IS-ACTIVE
DISPLAY "Active"
END-IF.
SET IS-CLOSED TO TRUE.
DISPLAY SW-CODE.
STOP RUN.