Home » COBOL File Access Mode

COBOL File Access Mode

by Online Tutorials Library

COBOL – File Access Mode

Every file organization (In our previous section, we discussed many file organizations) has different modes of access.

The access mode is used to define the accessing way of the file based on the requirements in the program. In short, we can say, access mode defines how the data is required to read and write from the file.

Mainly there are three access modes:

  • Sequential Access
  • Random Access
  • Dynamic Access

Sequential Access

As the name indicates, the records in the file can be read sequentially for the sequential access, i.e., one after the other from the beginning.

The method to retrieve the record varies according to the chosen file organization.

In sequential files, records are retrieved in the same way as they were inserted.

For indexed files, records are accessed in the order of the key filed selected, beginning at the present position of the file position indicator.

For relative files, records are accessed in the order of the relative record number.

Syntax:

Disadvantages of Sequential Access Mode

The sequential access mode is very effective when the file has fewer records, but when the file has a huge number of records, it will take too much time to read a specific record from the file.

Random Access

In the random access mode, we can access the records randomly, i.e., directly by providing the key.

This mode of access is often used only for indexed and relative files.

For indexed files, records are retrieved according to the value you place in a key field. Value can be primary, alternative, or relative. There can be one or more alternate indexes.

Records are retrieved for relative files based on the value you put in the relative key.

Syntax:

Dynamic Access

In the same program, dynamic access allows sequential as well as random access. In dynamic access mode, we can use a file description for both types of processing i.e., random and sequential processing, such as retrieving some records with the help of keys and some records in sequential order.

With relative and indexed files, the dynamic access mode provides you to move between random access mode and sequential access mode when reading a file by using the NEXT phrase on the READ statement.

Syntax:


You may also like