1. Input-Output Section
The Input-Output section determines the file organization and access methods. For more details, refer to ORGANIZATION Clause and ACCESS MODE Clause.
The Input-Output section must be defined in the Environment division and includes the following two paragraphs:
-
FILE-CONTROL
-
The FILE-CONTROL keyword identifies the FILE-CONTROL paragraph. This keyword can be specified only once, at the beginning of the FILE-CONTROL paragraph.
-
The FILE-CONTROL paragraph can be omitted if no file exists in a program, even if FILE-CONTROL is specified.
-
The FILE-CONTROL paragraph specifies physical files.
-
-
I-O-CONTROL
-
The I-O-CONTROL keyword identifies the I-O-CONTROL paragraph.
-
The I-O-CONTROL paragraph specifies information that is necessary for effective data transfer between COBOL programs and external data sets.
-
1.1. FILE-CONTROL Paragraph
The FILE-CONTROL paragraph associates each file in a COBOL program with an external data set, and specifies information such as file organization and access methods.
The following table lists available file organizations and access methods.
| File Organization | Access Method |
|---|---|
Sequential |
Non-VSAM, VSAM |
Relative |
VSAM |
Indexed |
VSAM |
Line sequential |
Text stream I-O |
The FILE-CONTROL paragraph starts with the FILE CONTROL keyword followed by a period (.).
The FILE-CONTROL paragraph must include one entry for each file described with an FD or SD in the data division. In each entry, the SELECT clause must appear first. The other clauses can appear in any order.
The following figure shows the formats for the FILE-CONTROL paragraph.
-
Sequential file entries
FILE-CONTROL Format 1 -
Indexed file entries
FILE-CONTROL Format 2
FILE-CONTROL Format 2 - entry -
Relative file entries
FILE-CONTROL Format 3 -
Line-sequential file entries
FILE-CONTROL Format 4
1.1.1. SELECT Clause
The SELECT clause defines a file identifier for a COBOL program.
| Item | Description |
|---|---|
SELECT OPTIONAL |
Syntax checked. SELECT has the same function. |
file-name-1 |
Must be identified with an FD or SD in the data division. Must follow the rules for COBOL user-defined names. Must include at least one alphabetical character, and cannot use names that are duplicated in the current program. |
1.1.2. ASSIGN Clause
The ASSIGN clause associates a file name with an actual external data set.
| Item | Description |
|---|---|
assignment-name-1 |
Specifies an external data set name. Specifies a name or file path described in a JCL DD statement. If the file is a sort or merge file, it is treated as comments. |
1.1.3. ORGANIZATION Clause
The ORGANIZATION clause identifies the logical structure for a file. The logical structure is determined when a file is created, and cannot be changed.
-
ORGANIZATION IS SEQUENTIAL (format 1)
-
ORGANIZATION IS INDEXED (format 2)
-
ORGANIZATION IS RELATIVE (format 3)
-
ORGANIZATION IS LINE SEQUENTIAL (format 4)
|
If the ORGANIZATION clause is omitted, the compiler assumes ORGANIZATION IS SEQUENTIAL. |
The data organization must be established when a file is created. After the file has been created, it can be extended, but the organization cannot be changed.
-
Sequential organization
-
The physical order of records is the actual order of records. The relationship between records is not changed even if the file is extended.
-
Records can be fixed length or variable length.
-
There are no keys.
-
-
Indexed organization
-
Each record in a file has one or more internal keys (key data items). Each key has an index with which a specific record can be searched according to the contents in an internal key data item.
-
Records can be fixed length or variable length.
-
Each record must include a prime key data item.
When a record is inserted, updated, or deleted, it can be searched using a prime key. Therefore, the prime key data item must be unique and cannot be changed even if the record is updated. A prime key data item can be used by being described in the RECORD KEY clause of the FILE-CONTROL paragraph.
-
Each record can have one or more alternate key data items.
A record to be read can be identified with an alternate key. An alternate key data item can be used by describing it in the ALTERNATE RECORD KEY clause of the FILE-CONTROL paragraph.
-
-
Relative organization
-
Each record is identified by a relative record number. Relative record numbers are not included in records.
-
An access method saves and gets records based on relative record numbers.
-
The physical order of records in a file is not related to each record’s relative record number.
-
Records can be fixed length or variable length.
-
-
Line-sequential organization
-
Each record ends with a record delimiter. The delimiter is not counted in the length of the record.
-
When a record is written in a file, trailing blanks are removed and a record delimiter is added.
-
When a record is read, the record delimiter is removed and the remaining part of the record (after EOF) is filled with blanks.
-
The new line character is a delimiter.
-
|
The compiler does not directly provide indexed organization or relative organization. However, the organizations are supported if the compiler is integrated with the OpenFrame file system. |
1.1.4. ACCESS MODE Clause
The ACCESS MODE clause defines which records in a file can be accessed.
-
ACCESS MODE IS SEQUENTIAL
Can be specified in all formats.
Format Description Format 1: Sequential
Records in a file can be accessed with the sequence created when the file is created or extended.
Format 1 only supports sequential access.
Format 2: Indexed
Records in a file can be accessed in the sequential order of ascending record keys.
Format 3: Relative
Records in a file can be accessed in the sequential order of relative record numbers.
Format 4: Line-sequential
Records in a file can be accessed with the sequence created when the file is created or extended.
Format 4 only supports sequential access.
-
ACCESS MODE IS RANDOM
Can be specified in format 2 and format 3.
Format Description Format 2: Indexed
Records can be accessed according the value of the record key data item.
Format 3: Relative
Records can be accessed according the value of the relative key data item.
-
ACCESS MODE IS DYNAMIC
Can be specified in format 2 and format 3.
Format Description Format 2: Indexed
Records in a file can be sequentially or randomly accessed based on input-output statements.
Format 3: Relative
Records in a file can be sequentially or randomly accessed based on input-output statements.
1.1.5. RECORD KEY Clause
The RECORD KEY clause (format 2) specifies the data item that defines the prime RECORD KEY in an indexed file. The prime RECORD KEY data item must be unique.
-
data-name-2
-
The prime RECORD KEY data item.
-
Must be described in a record description entry of a file.
The data categories are as follows:
-
Alphanumeric
-
Numeric
-
Numeric-edited
-
Alphanumeric-edited
-
Alphabetic
-
External floating-point
-
Internal floating-point
-
DBCS
-
-
data-name-2 cannot reference a group item that includes a variable-occurrence data item. data-name-2 can be qualified.
-
data-name-2’s data description and relative position in a record must be the same as when the file was defined.
-
1.1.6. ALTERNATE RECORD KEY Clause
The ALTERNATE RECORD KEY clause (format 2) specifies the data item that defines the alternative RECORD KEY in an indexed file.
-
data-name-3
-
The ALTERNATE RECORD KEY data item.
-
Must be described in a record description entry of a file.
The data categories are as follows:
-
Alphanumeric
-
Numeric
-
Numeric-edited
-
Alphanumeric-edited
-
Alphabetic
-
External floating-point
-
Internal floating-point
-
DBCS
-
-
data-name-3 cannot reference a group item that includes a variable-occurrence data item. data-name-3 can be qualified.
-
data-name-2’s data description and relative position in a record must be the same as those at the time a file is defined.
-
|
If the DUPLICATES phrase is not specified, the contents referenced by the ALTERNATE RECORD KEY data item must be unique in a file. |
1.1.7. RELATIVE KEY Clause
The RELATIVE KEY clause (format 3) identifies the data item that specifies the relative file’s relative record number.
| Item | Description |
|---|---|
data-name-4 |
Must be an unsigned integer data item and must not include the symbol P in the PICTURE phrase. data-name-4 cannot be described in a record description entry of a file. That is, RELATIVE KEY is not a part of a record. data-name-4 can be qualified. data-name-4 is only required for ACCESS IS SEQUENTIAL to use the START statement. It is always required for ACCESS IS RANDOM and ACCESS IS DYNAMIC. |
1.1.8. FILE STATUS Clause
The FILE STATUS clause monitors the execution of input-output statements. If the FILE STATUS clause is specified, the result of an input-output operation for a corresponding file is saved in the file status key data item.
| Item | Description |
|---|---|
data-name-1 |
The file status key data item can be defined with one of the following in the working-storage, local-storage, or linkage section.
data-name-1 must not include the PICTURE symbol 'P'. data-name-1 can be qualified. data-name-1 cannot be placed in a variable position. That is, it cannot follow a data item that includes an OCCURS DEPENDING ON clause. |
data-name-8 |
Syntax checked, but not used. |
1.2. I-O-CONTROL Paragraph
The I-O-CONTROL paragraph is used when different files share storage areas.
1.2.1. SAME AREA Clause
The SAME AREA clause allows two or more files to use the same record buffer space. The files do not need to have the same organization or access mode.
| Item | Description |
|---|---|
filename-3, file-name-4 |
Must be specified in the file-control paragraph of the same program. The EXTERNAL clause must not be specified. |