Compaq COBOL AAQ2G1FTK User Manual
Page 145
Handling Tables
4.3 Accessing Table Elements
Example 4–24 shows how to perform a multiple-key, binary search.
Example 4–24 A Multiple-Key, Binary Search
IDENTIFICATION DIVISION.
PROGRAM-ID. MULTI-KEY-SEARCH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 DIRECTORY-TABLE.
05 NAMES-NUMBERS.
10 FILLER
PIC X(30)
VALUE "SMILEY
HAPPY
T.213-4332".
10 FILLER
PIC X(30)
VALUE "SMITH
ALAN
C.881-4987".
10 FILLER
PIC X(30)
VALUE "SMITH
CHARLES
J.345-2398".
10 FILLER
PIC X(30)
VALUE "SMITH
FREDERICK
745-0223".
10 FILLER
PIC X(30)
VALUE "SMITH
HARRY
C.573-3306".
10 FILLER
PIC X(30)
VALUE "SMITH
HARRY
J.295-3485".
10 FILLER
PIC X(30)
VALUE "SMITH
LARRY
X.976-5504".
10 FILLER
PIC X(30)
VALUE "SMITHWOOD ALBERT
J.349-9927".
05 PHONE-DIRECTORY-TABLE REDEFINES NAMES-NUMBERS OCCURS 8 TIMES
ASCENDING KEY IS LAST-NAME
FIRST-NAME
MID-INIT
INDEXED BY DIR-INDX.
15 LAST-NAME
PIC X(10).
15 FIRST-NAME
PIC X(10).
15 MID-INIT
PIC XX.
15
PHONE-NUM
PIC X(8).
PROCEDURE DIVISION.
MULTI-KEY-BINARY-SEARCH.
SEARCH ALL PHONE-DIRECTORY-TABLE
WHEN LAST-NAME(DIR-INDX) = "SMITH"
AND FIRST-NAME(DIR-INDX) = "HARRY"
AND MID-INIT(DIR-INDX) = "J."
NEXT SENTENCE.
DISPLAY-RESULTS.
DISPLAY LAST-NAME(DIR-INDX)","
FIRST-NAME(DIR-INDX)
MID-INIT(DIR-INDX) " "
PHONE-NUM(DIR-INDX).
Handling Tables 4–23