Microsoft KB Archive/40552
COBOL 3.00’s EVALUATE Is Like C’s SWITCH, BASIC’s SELECT CASE
PSS ID Number: Q40552 Article last modified on 06-20-1990
3.00 3.00a | 3.00 3.00a MS-DOS | OS/2
Summary: The EVALUATE statement is COBOL’s version of BASIC’s SELECT CASE, Pascal’s CASE, and C’s SWITCH statements. This article gives a brief explanation and example of the EVALUATE statement. QuickBASIC’s SELECT CASE structure, like COBOL’s EVALUATE statement, is essentially a more structured and readable form of an IF statement with multiple ELSEIFs. CASE structures in most languages (such as QuickBASIC) allow you to test only one item or condition at a time. They require nested case structures or nested IFs within the CASE structure in order to test multiple conditions. The COBOL EVALUATE statement has the added advantage of being able to test multiple items or conditions. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS-DOS and MS OS/2.
More Information: EVALUATE is an ANSI 85 feature only. The ANS85 compiler directive must be used. The EVALUATE statement is described on Pages 3-102 through 3-107 in the “Microsoft COBOL 3.0: Language Reference Manual.” Note that leaving a WHEN clause blank with no executable code beneath it is an implied logical “OR” connecting it to the next WHEN clause. Consider the following code fragment: WHEN condition-1 * No executable statements here WHEN condition-2 PERFORM 100-this-procedure 100-this-procedure will be PERFORMed when either condition-1 or condition-2 is true. This is not a problem with the compiler, but the correct way that ANSI 85 COBOL should behave. Note that the following syntax is NOT correct, and gives an “Unrecognized Verb” error at compile time: WHEN condition-1 OR condition-2 PERFORM 100-this-procedure
The program below should be compiled without a COBOL.DIR file. The compile and LINK lines are as follows: COBOL EVALUATE.COB; LINK EVALUATE.OBJ; The following is EVALUATE.COB: $SET ANS85 $SET MS(2) DATA DIVISION. WORKING-STORAGE SECTION. 01 INSURANCE-CUSTOMER. 05 CLIENT-NAME PIC x(20). 05 CLIENT-AGE PIC 9(3). 05 CLIENT-GENDER PIC X(6). 05 PREMIUM-RATE PIC 9. 78 HIGH-PREMIUM VALUE 1. 78 MEDIUM-PREMIUM VALUE 2. 78 LOW-PREMIUM VALUE 3. 78 CLEAR-SCREEN value x“e4”. PROCEDURE DIVISION. MOVE “MALE” TO CLIENT-GENDER. MOVE 16 TO CLIENT-AGE. CALL CLEAR-SCREEN. EVALUATE CLIENT-AGE ALSO CLIENT-GENDER WHEN 15 THRU 24 ALSO “MALE” MOVE HIGH-PREMIUM TO PREMIUM-RATE DISPLAY “HIGHEST RATE” AT 1515 WHEN 15 THRU 24 ALSO “FEMALE” MOVE HIGH-PREMIUM TO PREMIUM-RATE DISPLAY “HIGHEST RATE” AT 1515 WHEN 25 THRU 34 ALSO “MALE” MOVE MEDIUM-PREMIUM TO PREMIUM-RATE DISPLAY “MEDIUM RATE” AT 1515 WHEN 25 THRU 34 ALSO “FEMALE” MOVE MEDIUM-PREMIUM TO PREMIUM-RATE DISPLAY “MEDIUM RATE” AT 1515 WHEN OTHER MOVE LOW-PREMIUM TO PREMIUM-RATE DISPLAY “MEDIUM RATE” AT 1515 END-EVALUATE. DISPLAY " " AT 2301. STOP RUN.
Copyright Microsoft Corporation 1990.