A program-internal name is specified in the SELECT clause (see “COBOL2000 Reference Manual” [1]) for each file to be processed by a COBOL program. The COBOL statements for a given file reference the file via this name. During program execution, each of the specified file-names must be assigned an actual file.
This assignment can be defined before the program call by means of a ADD-FILE-LINK or ASSIGN system-file command. Which of the two commands should be used is determined by the entry in the ASSIGN clause (see “COBOL2000 Reference Manual” [1]) for the file. If no file is explicitly assigned, the default values generated during compilation come into effect.
The individual methods used for the assignment of files are summarized below:
Assignment via the ADD-FILE-LINK command
Assignment via the ADD-FILE-LINK command is therefore possible only if the link name of the file is specified in the form “literal” or “data-name” in the ASSIGN clause. “literal” specifies the link name statically for the program. The “data-name” data item can be used to modify the link name dynamically, i.e. during program execution.
To assign a cataloged file, the user must issue an ADD-FILE-LINK command for this file before the program call; this ADD-FILE-LINK command must include a LINK-NAME operand specifying the declared link name. File attributes can also be specified at the same time using other operands of the ADD-FILE-LINK command.
Any link name must conform to BS2000 requirements in respect of link names (see also “Introductory Guide to DMS” [4]). More specifically, this means that
it must be alphanumeric,
it may consist of a maximum of eight characters, and
it must not contain any lowercase letters.
Example 9-1
Assignment of a cataloged file via the ADD-FILE-LINK command
|
In the case of COBOL programs using SORT (see chapter "Sorting and merging"), the following link names are reserved for the SORT utility routine and are thus not available for other files:
MERGEnn (nn=01,...99)
SORTIN
SORTINnn (nn=01,...99)
SORTOUT
SORTWK
SORTWKn (n=1,...9)
SORTWKnn (nn=01,...99)
SORTCKPT
A file assignment remains in effect until it is
released explicitly by a REMOVE-FILE-LINK command or implicitly at end of task, or
modified by means of a subsequent ADD-FILE-LINK command.
This should be noted particularly where several different files are to be successively assigned to one program-internal file-name within the same task.
Information regarding currently assigned cataloged files can be obtained by using the SHOW-FILE-LINK command (see “Commands” manual [3]).
Example 9-2
Changing file assignments :
/ADD-FILE-LINK INOUTFIL,FILE.UPDATE.1 —————————————————————————————(1) /START-PROGRAM UPDPROG ... /ADD-FILE-LINK INOUTFIL,FILE.UPDATE.2 —————————————————————————————(2) /START-PROGRAM UPDPROG ... /REMOVE-FILE-LINK INOUTFIL ————————————————————————————————————————(3)
The COBOL program UPDPROG specifies the link name INOUTFIL for a input/output file. This program successively actualizes the cataloged files FILE.UPDATE.1 and FILE-UPDATE.2.
(1) | The file named FILE.UPDATE.1 is assigned via link name INOUTFIL to the program UPDPROG for subsequent processing. |
(2) | After processing, a further ADD-FILE-LINK command terminates the previously valid file assignment for the link name INOUTFIL and assigns the file named FILE.UPDATE.2 as the new file. |
(3) | The file assignment for link name INOUTFIL is released by means of the REMOVE-FILE-LINK command. |
Assignment via the default settings
If a cataloged file has not been explicitly assigned at program runtime to an internal file name (with the link name “linkname”), the following defaults come into effect:
In the case of an output file and ENABLE-UFS-ACCESS = NO, the program attempts to access a cataloged file with the name from the SELECT clause. If no catalog entry is found under this name, the program writes to a previously created file with the name FILE.COBOL.linkname.
In the case of ENABLE-UFS-ACCESS = YES, the program writes directly to the file FILE.COBOL.linkname.For an input file whose SELECT clause contains the OPTIONAL phrase, the first read access attempt causes an AT END condition and passes control to the procedures declared in the program for such a case.
In the case of an input file (without the OPTIONAL phrase in the SELECT clause) and ENABLE-UFS-ACCESS = NO or of an input-output file, the program attempts to access a cataloged file with the name from the SELECT clause. If no catalog entry is found under this name, execution is interrupted with error message COB9117 and may be continued with the RESUME-PROGRAM command after a correct file assignment is made.
Assignment via the ASSIGN-systemfile command
The prerequisite for this is that the name of a system file must not have been specified in the ASSIGN clause. The system files are designated vendorname-1 (PRINTER) or vendorname-2 (PRINTER01...PRINTER99, SYSIPT, SYSOPT).
By issuing a ASSIGN-systemfile command for the specified system file,
a cataloged file or
another system file
can be assigned before the program is called. The permissible assignments for each system file are given in the description of the ASSIGN-systemfile command in the “Commands” manual [3].
Example 9-3
Assigning a cataloged file via the ASSIGN systemfile command
|
If no file is explicitly assigned at program runtime, the program will execute its I-O operations on the specified system file.
A file assignment remains in effect until it is
released at the end of the task, or
modified by means of a subsequent ASSIGN-systemfile command.
This should be noted particularly where several different files are to be successively assigned to one program-internal file name within the same task.
Information regarding current file assignments can be obtained by using the SHOW-SYSTEM-FILE-ASSIGNMENTS command.