Class Condition in COBOL

Class Condition

  • The class condition is used for checking alphabets or numeric data in an operand.
  • In ALPHABETIC, ALPHABETIC-LOWER, and ALPHABETIC-UPPER spaces are considered.
Syntax:
[Data Name/Arithmetic Operation]
[IS] [NOT]
[NUMERIC, ALPHABETIC, ALPHABETIC-LOWER, ALPHABETIC-UPPER]
[Data Name/Arithmetic Operation]

Example : Program to demonstrate class condition

IDENTIFICATION DIVISION.
PROGRAM-ID. CC.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 N1 PIC X(9) VALUE 'WXYZ '.
   01 N2 PIC 9(9) VALUE 591988.
   01 N3 PIC X(9) VALUE 'pqrs '.
   01 N4 PIC X(9) VALUE 'WXYZefgh '.

PROCEDURE DIVISION.
   A000-FIRST-PARA.
   
   IF N1 IS ALPHABETIC-UPPER THEN
      DISPLAY 'NUMBER 1 IS ALPHABETIC-UPPER'.
      
   IF N1 IS NUMERIC
      DISPLAY 'NUMBER 1 IS NUMERIC'
   ELSE
   DISPLAY 'NUMBER 1 IS NOT NUMERIC'.
  
   IF N2 IS NUMERIC THEN
      DISPLAY 'NUMBER 2 IS NUMERIC'.
   
    IF N3 IS ALPHABETIC-LOWER THEN
      DISPLAY 'NUMBER 3 IS ALPHABETIC-LOWER'.
    
     IF N4 IS ALPHABETIC THEN
      DISPLAY 'NUMBER 4 IS ALPHABETIC'.

   IF N4 IS ALPHABETIC-UPPER
      DISPLAY 'NUMBER 4 IS ALPHABETIC-UPPER'
   ELSE
   DISPLAY 'NUMBER 4 IS NOT ALPHABETIC-UPPER'.
STOP RUN.


Output:
NUMBER 1 IS ALPHABETIC-UPPER
NUMBER 1 IS NOT NUMERIC
NUMBER 2 IS NUMERIC
NUMBER 3 IS ALPHABETIC-LOWER
NUMBER 4 IS ALPHABETIC
NUMBER 4 IS NOT ALPHABETIC-UPPER