You are on page 1of 7

INDEXED FILES

 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

The figure below illustrates the concept of an index


file. We have changed the Publishers data for
illustration purposes, to include a city column. The
file on the left is the index file and indexes the
Publishers data file by the City field, which is
therefore called the indexed field. The city file is
called an index for the PUBLISHERS table. (The
index file is not a table in the same sense as the
PUBLISHERS table is a table. That is to say, we
cannot directly access the index file—instead we use
it indirectly.) The index file contains the cities for
each publisher, along with a pointer to the
corresponding data record in the Publishers file.
Create (when data file is created).

Load into memory

Write upload file to permanent storage


Operations on an Record(s) added to the file.
Indexed File Records deleted to the file.

Update record(s) in data file.

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

You might also like