|
RELATIVE File Processing
RELATIVE File Processing
RELATIVE ORGANIZATION: This file is divided into fixed number
of slots each slot has one record. This is identified as
relative record number. The access method stores and retrieves
a record, based on its relative record number. Records can be
accessed as sequentially or randomly or dynamically. This
relative files faster access compared to other 2 organizations.
File description entries for a Relative file:
SELECT logical-file-name ASSIGN TO physical-file-name
[RESERVE integer {AREA, AREAS}]
[ORGANIZATION IS RELATIVE]
[ACCESS MODE IS {SEQUENTIAL {RANDOM, DYNAMIC}, RELATIVE KEY is data-name-1}]
[FILE STATUS IS data-name-2]
Here records are stored based on unique record number which is
not part of record is called relative organization.
Here, RELATIVE KEY must be specified when the access mode is
RANDOM or DYNAMIC. The dataname-1 is called the relative key data
item and it indicates the field that contains the relative record
number. This dataname-1 is not part of record description.
The programmer must place an appropriate value in the relative
key data item while accessing a record randomly.
READ file-name RECORD [INTO identifier]
[; AT END imperative statements]
[END-READ]
This format is applicable to SEQUENTIAL ACCESS MODE. If the
RELATIVE KEY phrase is also specified with the ACCESS MODE
SEQUENTIAL clause, then upon the successful completion of the
READ statement, the relative record number of the accessed
record is placed in the relative key data item.
Format 2:
READ file-name RECORD [INTO identifier]
[; INVALID KEY imperative statements]
This format is applicable when ACCESS MODE is either RANDOM or
DYNAMIC. In this case the record to be read is identified from
the contents of the RELATIVE KEY data item. The INVALID KEY case
arises when the READ is unsuccessful.
Format 3:
READ file-name [NEXT] RECORD [INTO identifier]
[; INVALID KEY imperative statements]
This format is applicable when the ACCESS MODE is DYNAMIC and the
records are to read sequentially. Here the NEXT RECORD is
identified according to the following rules.
The READ NEXT statement is the first statement to be executed
after the OPEN statement, Then the NEXT RECORD is the first
record itself.
The READ NEXT statement follows a successful execution of another
READ NEXT on the same file; the NEXT RECORD is the record
following the one previously read record.
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. The INVALID KEY
condition arises for an index sequential file in the following
situations.
Format:
WRITE record-name [FROM data-name]
{INVALID KEY imperative statements}
{NOT INALID KEY imperative statements}
[END-WRITE]
REWRITE statement:
The 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 does not equal 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:
If 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 statement 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.
Format:
DELETE file-name RECORD
{INVALID KEY imperative statements}
{NOT INVALID KEY imperative statements}
[END-REWRITE]
START statement:
The START statement enables the programmer to position the relat-
ive file at some specified point so that subsequent sequential
operations on the file can start from this point instead of the
beginning. They KEY IS phrase indicates how the file is to be
positioned. The data-name in this phrase must be the data-name
in the RELATIVE KEY phrase of the SELECT . . . ASSIGN clause.
When the EQUAL TO or NOT LESS THAN condition is specified, the
file is positioned at the point indicated by the relative key-data
item. When the GREATER THAN condition is specified, the file is
positioned at the next relative position of the position indicated
by the RELATIVE KEY data item.
START file-name Key is OPERATOR data name
[; INVALID KEY imperative statements]
Below is sample COBOL program using relative file
click here to see the sample RRDS cobol program
|
|