Thursday, September 3, 2009

THE INDEXED FILE ORGANIZATION

In this file organization, the records of the file are stored one after another in the order they are added to the file.

In contrast to RELATIVE files, records of a INDEXED SEQUENTIAL file can be accessed by specifying an ALPHANUMERIC key in the READ statement (the KEY) .

It is the programmer's responsibility to take care of the record sizes in files. You must be careful when declaring record structures for files. Any mistake you make in record sizes will cause an error and abnormal termination.

Please note that you must provide the record structure to have a special field allocated to contain the KEY.

INDEXED files can have RANDOM or SEQUENTIAL ACCESS MODEs. If the ACCESS MODE is declared to be RANDOM in the corresponding SELECT statement, the program can read the record with key value "ABC" and then the record with key="A12", then record with key "D2X" etc etc. In short, one can access any record of an indexed file, in any order, provided that the KEY value is specified before the READ statement is executed.

If the ACCESS MODE is SEQUENTIAL, that means the records of the file will be accesses in their physical sequential order (just like SEQUENTIAL and LINE SEQUENTIAL files) and no specific KEY value be given for the READ statements; but instead, the NEXT clause will appear in READ statements meaning "Go get the record with the next consecutive key value.

SELECT MYFILE ASSIGN TO DISK "C:\DATADIR\MYFILE.DAT"

ORGANIZATION IS INDEXED

ACCESS MODE IS RANDOM

RECORD KEY IS M-IDNO.





SELECT MYFILE-2 ASSIGN TO DISK "C:\DATADIR\MYFILE2.TXT"

ORGANIZATION IS INDEXED

ACCESS MODE IS SEQUENTIAL

RECORD KEY IS M-IDNO.

In the FILE-SECTION, you must provide fields for the KEY, the M-IDNO in this example, in the FD block of the INDEXED file;

FD MYFILE.

01 MYFILE-REC.

02 M-IDNO PIC XXXX.

02 M-NAME PIC X(16).

02 M-SURNAME PIC X(16).

02 M-BIRTHDATE.

03 M-BD-YEAR PIC 9999.

03 M-BD-MONTH PIC 99.

03 M-BD-DAY PIC 99.

Note : Since the keys are not supposed to be numerical, you can use the X picture for key fields.