A useful variation of the binary search is that of specifying multiple search
keys. Multiple search keys allow you to select a specified table element from
among several elements that have duplicate low-order keys. An example is
a telephone listing where several people have the same last and first names,
but different middle initials. All specified keys must be either ascending or
descending. Example 4–24 shows how to use multiple search keys.
The table in Example 4–18 is followed by several examples (Examples 4–19, 4–20,
4–21, 4–22, and 4–23) of how to search it.
Example 4–18 Sample Table
DATA DIVISION.
WORKING-STORAGE SECTION.
01 TEMP-IND
01 FED-TAX-TABLES.
02 ALLOWANCE-DATA.
03 FILLER
"0101440
-
"0202880
-
"0304320
-
"0405760
-
"0507200
-
"0608640
-
"0710080
-
"0811520
-
"0912960
-
"1014400".
02 ALLOWANCE-TABLE REDEFINES ALLOWANCE-DATA.
03 FED-ALLOWANCES OCCURS 10 TIMES
ASCENDING KEY IS ALLOWANCE-NUMBER
INDEXED BY IND-1.
04 ALLOWANCE-NUMBER
04 ALLOWANCE
02 SINGLES-DEDUCTION-DATA.
03 FILLER
"0250006700000016
-
"0670011500067220
-
"1150018300163223
-
"1830024000319621
-
"2400027900439326
-
"2790034600540730
-
"3460099999741736".
02
SINGLE-DEDUCTION-TABLE REDEFINES SINGLES-DEDUCTION-DATA.
03 SINGLES-TABLE OCCURS 7 TIMES
ASCENDING KEY IS S-MIN-RANGE S-MAX-RANGE
INDEXED BY IND-2, TEMP-INDEX.
04 S-MIN-RANGE
04 S-MAX-RANGE
04 S-TAX
04 S-PERCENT
Handling Tables
4.3 Accessing Table Elements
USAGE IS INDEX.
PIC X(70) VALUE
PIC XX.
PIC 99999.
PIC X(112) VALUE
PIC 99999.
PIC 99999.
PIC 9999.
PIC V99.
(continued on next page)
Handling Tables 4–19
Need help?
Do you have a question about the COBOL AAQ2G1FTK and is the answer not in the manual?