HP 3000 Manuals

SEEK Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

SEEK Statement 

The SEEK statement is an HP extension to the ANSI COBOL standard.  It is
provided for COBOL'68 compatibility.

The SEEK statement initiates access to a relative file whose access mode
is dynamic or random, and to a random access file, prior to execution of
a format 2 READ statement.

Syntax 

     SEEK file-name RECORD

Description 

The SEEK statement is valid only for input files.

The file specified in a SEEK statement must be opened prior to the first
SEEK statement.

The SEEK statement causes a transfer of the physical record containing
the logical record to be read in a subsequent READ statement from storage
into main memory.

Using the SEEK statement before a format 2 READ statement may improve the
performance of your program.  However, because the SEEK function is
implicit in the READ statement, its use is not mandatory in this case.

Two SEEK statements may logically follow each other.  However, it is poor
programming practice to do this because of the time expended on
input-output operations for data that will not be accessed.

For relative files, the SEEK statement uses the value of the data item
named in the RELATIVE KEY clause of the file SELECT statement to find the
desired record.  Thus, before a SEEK statement is executed for a relative
file, the relative record number of the desired record must be moved to
the RELATIVE KEY data item.

Similarly, for random access files, the SEEK statement uses the value of
the data item named in the ACTUAL KEY clause of the file's SELECT
statement to find the desired record.

Thus, you must move the ACTUAL KEY value for the desired record to the
data item named by the ACTUAL KEY clause before executing a SEEK
statement for the file.

In either case, if the value moved to the data item named in a RELATIVE
KEY or ACTUAL KEY clause is invalid, the SEEK statement is ignored.  If a
subsequent format 2 READ statement is executed for the file, an INVALID
KEY condition exists, and the appropriate action is taken.



MPE/iX 5.0 Documentation