THROUGH 19.4

15.7 THROUGH 19.4

3. The values specified after the EVALUATE verb but before the first WHEN clause are known as selection subjects

while the values specified on each WHEN clause are known as selection objects.

4. Each WHEN clause must have the same number of selection objects as the EVALUATE verb has selection subjects.

5. Each EVALUATE clause’s selection subject will be tested for equality to each WHEN clauses corresponding selection object.

6. The first WHEN clause found where all such equality tests described in rule #5 result in TRUE results will be the

one whose imperative statement will be executed.

7. If none of the WHEN clauses have all such equality tests as described in rule #5 resulting in TRUE results then the imperative statement associated with the WHEN OTHER clause (imperative-statement-2) will be executed. If there is no WHEN OTHER clause, control will simply fall into the next statement following the EVALUATE statement.

8. Once a WHEN or WHEN OTHER clause’s imperative statement has been executed, control will fall into the next

statement following the EVALUATE statement.

9. Using a selection object of ANY will cause an automatic match with whatever selection subject the ANY was matched against.

Here’s a “case study” that will illustrate the usefulness of the EVALUATE statement. A program is being developed to compute the interest to be paid on accounts based upon their average daily balance [ADB]. The business rules for this process are as follows:

1. Interest-bearing checking accounts will receive no interest if their ADB is less than $1000. Interest-bearing

checking accounts with an ADB $1000 to $1499.99 will receive 1% of the ADB as interest. Those with an ADB of $1500 or more will receive 1.5% of the ADB as interest.

2. Statement savings accounts will receive 1.5% interest on an ADB up to $10000 and 1.75% for any ADB amounts

over $10000.

3. Platinum savings accounts receive 2% interest on their ADB, regardless of average balance amounts.

4. No other types of accounts receive interest. Here’s a sample OpenCOBOL program that can be used to test an “EVALUATE” implementation of these business

rules. Output from the program is shown in the inset. Figure 6-52 - An EVALUATE Demo Program

>>SOURCE FORMAT FREE IDENTIFICATION DIVISION.

Enter Account Type (c,s,p,other): c

PROGRAM-ID. evaldemo.

Enter Ave Daily Balance (nnnnnnn.nn): 250

ENVIRONMENT DIVISION.

Accrued Interest = 0.00

DATA DIVISION.

Enter Account Type (c,s,p,other): c

WORKING-STORAGE SECTION.

Enter Ave Daily Balance (nnnnnnn.nn): 1250

01 Account-Type PIC X(1).

Accrued Interest = 12.50

88 Interest-Bearing-Checking VALUE 'c'.

Enter Account Type (c,s,p,other): c

88 Statement-Savings VALUE 's'.

Enter Ave Daily Balance (nnnnnnn.nn): 1899.99

88 Platinum-Savings VALUE 'p'.

Accrued Interest = 28.50

01 ADB-Char PIC X(10).

Enter Account Type (c,s,p,other): s

01 Ave-Daily-Balance PIC 9(7)V99.

Enter Ave Daily Balance (nnnnnnn.nn): 22000.00

01 Formatted-Amount PIC Z(6)9.99.

Accrued Interest = 2430.00

01 Interest-Amount PIC 9(7)V99.

Enter Account Type (c,s,p,other): p

PROCEDURE DIVISION.

Enter Ave Daily Balance (nnnnnnn.nn): 1.98

000-Main.

Accrued Interest = 0.04

PERFORM FOREVER DISPLAY "Enter Account Type (c,s,p,other): " WITH NO ADVANCING ACCEPT Account-Type IF Account-Type = SPACES

STOP RUN END-IF DISPLAY "Enter Ave Daily Balance (nnnnnnn.nn): " WITH NO ADVANCING ACCEPT ADB-Char MOVE FUNCTION NUMVAL(ADB-Char) TO Ave-Daily-Balance EVALUATE TRUE ALSO Ave-Daily-Balance

WHEN Interest-Bearing-Checking ALSO 0.00 THRU 999.99 MOVE 0 TO Interest-Amount WHEN Interest-Bearing-Checking ALSO 1000.00 THRU 1499.99 COMPUTE Interest-Amount ROUNDED = 0.01 * Ave-Daily-Balance WHEN Interest-Bearing-Checking ALSO ANY COMPUTE Interest-Amount ROUNDED = 0.015 * Ave-Daily-Balance WHEN Statement-Savings ALSO 0.00 THRU 10000.00 COMPUTE Interest-Amount ROUNDED = 0.015 * Ave-Daily-Balance WHEN Statement-Savings ALSO ANY COMPUTE Interest-Amount ROUNDED = 0.015 * Ave-Daily-Balance

+ 0.175 * (Ave-Daily-Balance - 10000)

WHEN Platinum-Savings ALSO ANY COMPUTE Interest-Amount ROUNDED = 0.020 * Ave-Daily-Balance WHEN OTHER MOVE 0 TO Interest-Amount END-EVALUATE MOVE Interest-Amount TO Formatted-Amount DISPLAY "Accrued Interest = " Formatted-Amount

END-PERFORM .