Language Structure

IB Statements

File System

Comet 32 Runtime


Indexed Sequential Files

Records in indexed sequential files are stored in the order that they are written to the disk. Records may be retrieved in sequential order or in random order using a numeric index to represent the record number in the file.

The record size, specified when the file is created, may range from 1 to 8000 bytes.

When an Internet Basic program opens an indexed sequential file, the Comet operating system assigns a unique record pointer to the file. Each user opening the file is assigned a unique pointer, allowing multiple users to access data from the same file at the same time. To avoid data integrity problems when more than one user is accessing a file, Comet provides a record locking mechanism. The EXTRACT statement is used to read and lock individual data records.

When an indexed sequential file is opened, the record pointer is positioned at the first record. Subsequent I/O operations change the location of the pointer. Note: Some I/O operations do not move the pointer. See the Procedure Division.

For example, to read all the records from an indexed sequential file in order, you would open the file and read the records without specifying an index. This would move through the file in sequential order and end when the last record was read.

To read a specific record from an indexed sequential file, you would include the KEY= parameter in the READ (or associated input) statement. The "key" in this case would be a specific record number (e.g., the number 35 would represent the 35th record in the file). The direct access to a record moves the record pointer, so that subsequent sequential access would take place from the new record pointer location, rather than the beginning of the file.

Application note: Indexed sequential files are commonly used for transaction files because they take less disk space than keyed files, and are faster to read from beginning to end than a keyed file.