Class Condition
Class Condition
The CLASS condition tests whether the data in a variable belongs to a specific category of characters such as ALPHABETIC, ALPHABETIC-LOWER, ALPHABETIC-UPPER, NUMERIC, etc. It also verifies the data that belongs to a category coded by the CLASS in the SPECIAL-NAMES.
Syntax -
Parameters -
- identifier-1 - Specifies the variable.
- NOT - used to validate the negate condition.
- NUMERIC - Used to validate the data is numeric or not.
- ALPHABETIC - Used to validate the data contains only any A to Z (lowercase or uppercase) and the space.
- ALPHABETIC-UPPER - Used to validate the data contains only any uppercase A to Z and the space.
- ALPHABETIC-LOWER - Used to validate the data contains only any lowercase a to z and the space.
- class-name - Used to validate the data contains characters listed in the definition of CLASS in the SPECIAL-NAMES paragraph.
Valid forms of the class condition for different types of variables -
Variable Type in Declaration | Valid class condition |
---|---|
Alphabetic | ALPHABETIC ALPHABETIC-LOWER ALPHABETIC-UPPER class-name NOT ALPHABETIC NOT ALPHABETIC-LOWER NOT ALPHABETIC-UPPER NOT class-name |
Alphanumeric, alphanumeric-edited, numeric-edited |
ALPHABETIC ALPHABETIC-LOWER ALPHABETIC-UPPER NUMERIC class-name NOT ALPHABETIC NOT ALPHABETIC-LOWER NOT ALPHABETIC-UPPER NOT NUMERIC NOT class-name |
Decimal | NUMERIC NOT NUMERIC |
Numeric | NUMERIC class-name NOT NUMERIC NOT class-name |
Practical Example -
Scenario1 - Validating Alphabetic
05 WS-VAR1 PIC A(10) VALUE "MAINFRAME ".
...
IF WS-VAR1 IS ALPHABETIC
DISPLAY "Data is alphabetic"
ELSE
DISPLAY "Data is not alphabetic"
END-IF
Result - Data is alphabetic
Scenario2 - Validating Numeric value
05 WS-VAR2 PIC 9(02) VALUE 25.
...
IF WS-VAR2 IS NUMERIC
DISPLAY "Data is numeric"
ELSE
DISPLAY "Data is not numeric"
END-IF
Result - Data is numeric
Scenario3 - Validating custom class
SPECIAL-NAMES.
CLASS ALPHA-NUMERIC IS 'A' THROUGH 'Z' '0' THROUGH '9'.
...
05 WS-VAR1 PIC X(10) VALUE "MAINFRAME1".
...
IF WS-VAR1 IS ALPHA-NUMERIC
DISPLAY "Data is Alpha-numeric"
ELSE
DISPLAY "Data is not Alpha-numeric"
END-IF
Result - Data is Alpha-numeric