Professional Documents
Culture Documents
An Indexed File is a computer file with an index that allows easy random access to
any record given its file key.
The key must be such that it uniquely identifies a record. If more than one index is
present the other ones are called Alternate Indexes. The indexes are created with the
file and maintained by the system.
The purpose of an Index file is to provide direct (also called Random) access to data in a
database file.
IBM supports indexed files with the Indexed Sequential Access Method on OS/360 and
successors.
The COBOL language supports indexed files with the following command in the FILE
CONTROL section as (ORGANIZATION IS INDEXED).
Concept of indexed files
Searches
Operations on an Indexed File
Creating an Indexed file Writing an Indexed file
• Input is a sorted sequential • File defined as
file SEQUENTIAL access
• Index file is defined for • File OPEN OUTPUT
SEQUENTIAL access • WRITE record-name INVALID
• Duplicates must be removed KEY imperative statements
from the input file or trapped NOT INVALID KEY imperative
using the FILE STATUS. statements END-WRITE
Index file-Select Clause
• ORGANISATION IS INDEXED
• ACCESS IS SEQUENTIAL RANDOM DYNAMIC
• RECORD KEY IS data-name identifies the primary record key
within the files record description.
• ALTERNATE RECORD KEY is data-name-2 WITH
DUPLICATES
• FILE STATUS IS data-name-3
• An operational working storage item to record the status of I/O
operations
Reading an Indexed
File
• SEQUENTIAL access
• File OPEN INPUT
• READ file –name KEY IS data-name
INVALID KEY imperative statements
NOT INVALID KEY imperative statements
END-READ
• RANDOM access
• File OPEN INPUT
• RECORD KEY must be set prior to READ
• READ file-name KEY IS data-name
INVALID KEY imperative statements
NOT INVALID KEY imperative statements
END-READ
Operations on an Indexed File
Updating an Indexed Deleting records from an
File Indexed File
• If Access is SEQUENTIAL a
• Access defined as SEQUENTIAL READ must precede the
or RANDOM DELETE
• If RANDOM the RECORD KEY
• File OPEN I-O must be set prior to the DELETE
• DELETE file-name
• A Read must precede any write
INVALID KEY imperative
statements