ACCESS MODE clause

The ACCESS MODE clause defines the manner in which the records of the file are made available for processing. If the ACCESS MODE clause is not specified, sequential access is assumed.

For sequentially accessed relative files, the ACCESS MODE clause does not have to precede the RELATIVE KEY clause.

ACCESS MODE IS SEQUENTIAL
Can be specified in all formats.
Format 1: sequential
Records in the file are accessed in the sequence established when the file is created or extended. Format 1 supports only sequential access.
Format 2: indexed
Records in the file are accessed in the sequence of ascending record key values according to the collating sequence of the file.
Format 3: relative
Records in the file are accessed in the ascending sequence of relative record numbers of existing records in the file.
Format 4: line-sequential
Records in the file are accessed in the sequence established when the file is created or extended. Format 4 supports only sequential access.
The following is the syntax of the sequential access mode:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
   SELECT file-name ASSIGN TO dd-name
   ORGANIZATION IS SEQUENTIAL
   ACCESS MODE IS SEQUENTIAL
	
	
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
   FILE-CONTROL.
   SELECT file-name ASSIGN TO dd-name
   ORGANIZATION IS INDEXED
   ACCESS MODE IS SEQUENTIAL
   RECORD KEY IS rec-key1
   ALTERNATE RECORD KEY IS rec-key2

		
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
   FILE-CONTROL.
   SELECT file-name ASSIGN TO dd-name
   ORGANIZATION IS RELATIVE
   ACCESS MODE IS SEQUENTIAL
   RELATIVE KEY IS rec-key1
ACCESS MODE IS RANDOM
Can be specified in formats 2 and 3 only.
Format 2: indexed
The value placed in a record key data item specifies the record to be accessed.
Format 3: relative
The value placed in a relative key data item specifies the record to be accessed.
The following is the syntax of the random access mode:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
   FILE-CONTROL.
   SELECT file-name ASSIGN TO dd-name
   ORGANIZATION IS INDEXED
   ACCESS MODE IS RANDOM
   RECORD KEY IS rec-key1
   ALTERNATE RECORD KEY IS rec-key2

		
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
   FILE-CONTROL.
   SELECT file-name ASSIGN TO dd-name
   ORGANIZATION IS RELATIVE
   ACCESS MODE IS RANDOM
   RELATIVE KEY IS rec-key1
ACCESS MODE IS DYNAMIC
Can be specified in formats 2 and 3 only.
Format 2: indexed
Records in the file can be accessed sequentially or randomly, depending on the form of the specific input-output statement used.
Format 3: relative
Records in the file can be accessed sequentially or randomly, depending on the form of the specific input-output request.
The following is the syntax of the dynamic access mode:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
   FILE-CONTROL.
   SELECT file-name ASSIGN TO dd-name
   ORGANIZATION IS SEQUENTIAL
   ACCESS MODE IS DYNAMIC
   RECORD KEY IS rec-key1
   ALTERNATE RECORD KEY IS rec-key2

		
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
   FILE-CONTROL.
   SELECT file-name ASSIGN TO dd-name
   ORGANIZATION IS RELATIVE
   ACCESS MODE IS DYNAMIC
   RELATIVE KEY IS rec-key1