|
INDEXED File Processing
INDEXED File Processing
INDEX SEQUENTIAL ORGANIZATION: Records in this file are stored
based on a key field which is part of record and this is also
called as index. Records in this file are accessible in sequent-
ial , dynamic & random mode. An index sequential file is concep-
tually made up of two files, a data file and an index file.
INDEXED FILE PROCESSING:
SELECT logical-file-name ASSIGN TO physical-file-name
[ORGANIZATION IS INDEXED]
[ACCESS MODE IS {SEQUENTIAL, RANDOM, DYNAMIC}]
[RECORD KEY IS data-name-1]
[ALTERNATE RECORD KEY is data-name-2 [WITH DUPLICATES]]
[FILE STATUS IS data-name-2]
Records in this file are stored based on a key field which is
part of record and this is also called as index and this organiz-
ation is called INDEXED.
Here RECORD KEY clause specifies the index based on which the
file is sequenced. The data-name-1 must be an alphanumeric field
within the record description for the file. In case there are
multiple record descriptions, the key field from any of the descri-
ptions can be used. Index sequential file is sorted and maintained
on the primary key, the records can also be accessed using the
ALTERNATE KEY. Further, the ALTERNATE KEY data item may also find
duplicate entries for records. To incorporate this, specify WITH
DUPLICATES option.
READ Statement
READ File name [NEXT RECORD]
INTO data-name
[KEY is data-name]
[INVALID KEY imperative statements]
Here, the data-name in the KEY phrase must be either the primary
key or one of the alternate keys. The option NEXT RECORD is speci-
fied when an index sequential file is being read sequentially
INVALID KEY condition arises when the specified key is not found
in the file.
WRITE statement:
If a file is opened in the OUTPUT mode, then the WRITE statement
releases the records to the file in the ascending order of the
record key values regardless of the access mode.
ACCESS mode SEQUENTIAL is specified and the file is opened OUTPUT
and the value of the primary key is not greater than that of the
previous record.
The file is opened in the OUTPUT or I-O modes and the value of the
primary record key is equal to that of an already existing record.
WRITE record-name [FROM data-name]
{INVALID KEY imperative statements}
REWRITE statement:
REWRITE statement requires that the file must be opened in the
I-O mode and if the SEQUENTIAL ACCESS mode is specified, the
value of the RECORD KEY being replaced must be equal to that of
the record last read from the file.
The INVALID KEY condition arises in the following situations.
The access mode is sequential and the value contained in the
RECORD KEY of the record to be replaced is not equal to the value
of the RECORD KEY data item of the last-retrieved record from the
file.
The value of an ALTERNATE RECORD KEY data item for which DUPLICATES
is not specified is equal to that of a record already in the file.
Format:
REWRITE record-name [FROM data-name]
{INVALID KEY imperative statements}
DELETE statement:
To delete a record from an index sequential file, the file must
be opened in the I-O mode. If the access mode is sequential, then
the INVALID KEY phrase should not be specified. Instead, the last
I/O statement executed on the file must be a successful READ stat-
ement for the record specified. IF the access mode is RANDOM or
DYNAMIC, then the record to be deleted is determined by the value
of the RECORD KEY. In this case the INVALID KEY phrase should be
specified. The INVALID KEY condition arises if the specified is
not found in the file.
DELETE file-name RECORD
{INVALID KEY imperative statements}
START statement:
The START statement provides positioning the file pointer at a
specific location within an index Sequential file for subsequent
sequential record retrieval. The access mode must be SEQUENTIAL
or DYNAMIC and the file must be opened in the INPUT or I-O modes.
Further, if the KEY phrase is specified, the file pointer is pos-
itioned at the logical record in the file whose key field satisfies
the comparison and if it is omitted, then KEY IS EQUAL (to the
RECORD KEY) is implied. If the comparison is not satisfied by any
record in the file, an invalid key condition exists; the position of
the file position indicator is undefined and (if specified) the
INVALID KEY imperative-statement is executed.
START file-name
[KEY is {=, <, >} data-name]
[INVALID KEY imperative statements]
click here to see the sample indexed cobol program
|
|