The class condition is used to check the contents of data items. For example, it can be used to check to see if the data item consists of only numeric data.
This sample uses classes that have already been defined (alphabetic character check and numeric data check). However, defining a class using the CLASS clause of the SPECIAL-NAMES paragraph enables checking using any arbitrarily defined class.
000010 @OPTIONS MAIN 000020*---------------------------------------------------------------------- 000030* The type of character data can be checked using a class condition. 000040*---------------------------------------------------------------------- 000050 IDENTIFICATION DIVISION. 000060 PROGRAM-ID. SAMPLE. 000070 DATA DIVISION. 000080 WORKING-STORAGE SECTION. 000090 01 NAME PIC X(20). 000100 01 BIRTHDAY PIC X(8). 000110 PROCEDURE DIVISION. 000120 DISPLAY "Please input your name in alphabetic characters. >>" 000125 WITH NO ADVANCING. 000130 ACCEPT NAME FROM CONSOLE. 000140*---------------------------------------------------------------------- 000150* The ALPHABETIC condition is used for the alphabetic character check. 000160*---------------------------------------------------------------------- 000170 IF NAME IS NOT ALPHABETIC THEN 000180 DISPLAY "The input data is incorrect." 000190 EXIT PROGRAM 000200 END-IF. 000210*---------------------------------------------------------------------- 000220 DISPLAY "Please input your birthday. Example: 19690123 >>" 000225 WITH NO ADVANCING. 000230 ACCEPT BIRTHDAY FROM CONSOLE. 000240*---------------------------------------------------------------------- 000250* The NUMERIC condition is used for the numeric data check. 000260*---------------------------------------------------------------------- 000270 IF BIRTHDAY IS NOT NUMERIC THEN 000280 DISPLAY "The input data is incorrect." 000290 EXIT PROGRAM 000300 END-IF. 000310*---------------------------------------------------------------------- 000320 DISPLAY " ". 000330 DISPLAY "Name : " NAME. 000340 DISPLAY "Birthday: " BIRTHDAY. 000350 END PROGRAM SAMPLE.