COBOL - Class Condition
Class condition checks if an operand contains only alphabets or numeric data. Whitespaces are considered in ALPHABETIC, ALPHABETIC-LOWER, and ALPHABETIC-UPPER.
Syntax:
Identifier - IS [NOT] - NUMERIC
- ALPHABETIC
- ALPHABETIC-LOWER
- ALPHABETIC-UPPER
- class-name
- DBCS
- KANJI
|
Identifier - Must reference a data item described with one of the following usages:
- DISPLAY, NATIONAL, COMPUTATIONAL-3, or PACKED-DECIMAL when NUMERIC is specified
- DISPLAY or NATIONAL when ALPHABETIC, ALPHABETIC-UPPER, or ALPHABETIC-LOWER is specified
NOT
When used, NOT and the next keyword define the class test to be executed for truth value. For example, NOT NUMERIC is a truth test for determining that the result of a NUMERIC class test is false (in other words, the item contains data that is nonnumeric).
NUMERIC
Identifier consists entirely of the characters 0 through 9, with or without an operational sign.
If its PICTURE does not contain an operational sign, the identifier being tested is determined to be numeric only if the contents are numeric and an operational sign is not present.
If its PICTURE does contain an operational sign, the identifier being tested is determined to be numeric only if the item is an elementary item, the contents are numeric, and a valid operational sign is present.
ALPHABETIC
Identifier consists entirely of any combination of the lowercase or uppercase Latin alphabetic characters A through Z and the space.
ALPHABETIC-LOWER
Identifier consists entirely of any combination of the lowercase Latin alphabetic characters a through z and the space.
ALPHABETIC-UPPER
Identifier consists entirely of any combination of the uppercase Latin alphabetic characters A through Z and the space.
class-name
Identifier consists entirely of the characters listed in the definition of class-name in the SPECIAL-NAMES paragraph.
DBCS
Identifier consists entirely of DBCS characters.
A range check is performed on the item for valid character representation. The valid range is X'41' through X'FE' for both bytes of each DBCS character and X'4040' for the DBCS blank.
KANJI
Identifier consists entirely of DBCS characters.
A range check is performed on the item for valid character representation. The valid range is from X'41' through X'7E' for the first byte, from X'41' through X'FE' for the second byte, and X'4040' for the DBCS blank.
Example:
IDENTIFICATION DIVISION.
PROGRAM-ID. COBCLASS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAL1 PIC X(9) VALUE 'NIKITA '.
01 WS-VAL2 PIC 9(9) VALUE 123456789.
PROCEDURE DIVISION.
A000-FIRST-PARA.
IF WS-VAL1 IS ALPHABETIC THEN
DISPLAY 'WS-VAL1 IS ALPHABETIC'.
IF WS-VAL1 IS NUMERIC THEN
DISPLAY 'WS-VAL1 IS NUMERIC'.
IF WS-VAL2 IS NUMERIC THEN
DISPLAY 'WS-VAL2 IS NUMERIC'.
STOP RUN.
|
When you compile and execute the above program, it produces the following result −
WS-VAL1 IS ALPHABETIC
WS-VAL1 IS NUMERIC |
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!