Compaq COBOL AAQ2G1FTK User Manual

Page 499

Advertising
background image

Optimizing Your Compaq COBOL Program

15.5 Choices in Procedure Division Statements

15.5.2 Using Indexing Instead of Subscripting

Using index names for table handling is generally more efficient than using
PACKED-DECIMAL or numeric DISPLAY subscripts, since the compiler
declares index names as binary data items. Subscript data items described
in the Working-Storage Section as binary items are as efficient as index items.
Indexing also provides more flexibility in table-handling operations, since it
allows you to use the SEARCH statement for sequential and binary searches.

The following two examples are equally efficient:

Example 1

WORKING-STORAGE SECTION.
01

TABLE-SIZE.
03

FILLER

PIC X(300).

01

THE-TABLE REDEFINES TABLE-SIZE.
03

TABLE-ENTRY OCCURS 30 TIMES PIC X(10).

01

SUB1

PIC S9(5) BINARY VALUE ZEROES.

Example 2

WORKING-STORAGE SECTION.
01

TABLE-SIZE.
03

FILLER

PIC X(300).

01

THE-TABLE REDEFINES TABLE-SIZE.
03

TABLE-ENTRY OCCURS 30 TIMES PIC X(10)

INDEXED BY IND-1.

15.5.3 Using SEARCH ALL Instead of SEARCH

When performing table look-up operations, SEARCH ALL, a binary search
operation, is usually faster than SEARCH, a sequential search operation.
However, SEARCH ALL requires the table to be in ascending or descending order
by search key, while SEARCH imposes no restrictions on table organization. Also,
with SEARCH ALL there should be unique key values in the table. Before using
SEARCH ALL, you must pre-sort the table. If the table is not sorted, SEARCH
ALL often gives incorrect results.

The SORT statement (Format 2, which is a Compaq extension) can be used to
sort an entire table. This is particularly useful in connection with SEARCH ALL.
See the SORT statement description in the Procedure Division chapter of the
Compaq COBOL Reference Manual for the syntax and examples.

A binary search (SEARCH ALL) determines a table’s size, finds the median
table entry, and searches the table in sections, by using compare processes. A
sequential search (SEARCH) manipulates the contents of an index to search
the table sequentially. Section 4.3.8 contains examples of binary and sequential
table-handling operations.

15.5.4 Selecting Hypersort for Sorting Tasks

Hypersort is a high-performance sorting method. COBOL has Hypersort on all
three Alpha platforms: OpenVMS, Tru64 UNIX, and Windows NT. On the latter
two, Hypersort is the only method.

On OpenVMS Alpha, a different sorting method, Sort-32, is the default, but
you can choose Hypersort instead for both sorting within COBOL and sorting
at the DCL level. See the DCL online help (type $HELP SORT) for details on
the differences between the two sorting methods and instructions for switching
between methods.

Optimizing Your Compaq COBOL Program 15–9

Advertising