Compaq COBOL AAQ2G1FTK User Manual

Page 141

Advertising
background image

Handling Tables

4.3 Accessing Table Elements

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

USAGE IS INDEX.

01

FED-TAX-TABLES.
02

ALLOWANCE-DATA.
03

FILLER

PIC X(70) VALUE

"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

PIC XX.

04

ALLOWANCE

PIC 99999.

02 SINGLES-DEDUCTION-DATA.

03

FILLER

PIC X(112) VALUE

"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

PIC 99999.

04

S-MAX-RANGE

PIC 99999.

04

S-TAX

PIC 9999.

04

S-PERCENT

PIC V99.

(continued on next page)

Handling Tables 4–19

Advertising