Function
The SELECT clause is used to give a name to each file in the program.
Format 1
SELECT
[
OPTIONAL
] file-name
Format 2
SELECT
file-name
Syntax rule for format 1 and format 2
file-name stands for the name by which a file is referenced in the compilation unit (internal file-name). Each file-name used in a program, a factory, an object or a method may only occur in one SELECT clause.
Syntax rules for format 1
Each file specified in a SELECT clause must have precisely one file description (FD) entry in the DATA DIVISION of the same program, the same method, the same factory or the same object.
The OPTIONAL phrase is required for files that are not necessarily present at object time. When a file is not present at object time, the first READ statement for that file passes control to the associated at end condition. The OPTIONAL phrase is permitted only for files opened in INPUT, I-O or EXTEND mode.
Syntax rules for format 2
file-name designates a sort file.
For each sort file specified in a SELECT clause, there must be precisely one sort file description entry (SD) in the DATA DIVISION of the same program or the same method.
Within a class definition, this format may only be specified in a method definition.
A maximum of 30 characters of the file name are used at runtime (e.g. for messages and default settings).
General rules for format 1
If no SET-FILE-LINK command is given for a file when the program is executed, the runtime system creates a file named FILE.COB85.linkname at OPEN OUTPUT. The link name is formed from the specifications in the ASSIGN clause (see the section "ASSIGN clause").
If the OPTIONAL phrase refers to an external file, OPTIONAL must be specified in all programs that describe this external file.
General rules for format 2
No further clauses other than the ASSIGN clause are permitted.
Each sort-file described in the Data Division must be designated once, and only once, as a file-name in the FILE-CONTROL paragraph.
The following file-names must not be used in SELECT clauses within a program that uses SORT:
MERGExx(xx = 01,...,99) SORTIN SORTINxx(xx = 01,...,99) SORTOUT SORTWK SORTWKx(x = 1,...,9) SORTWKxx(xx = 01,...,99) SORTCKPT