Identifying files to the operating system (ASSIGN)

The ASSIGN clause associates the name of a file as it is known within a program to the associated file that will be used by the operating system.

About this task

You can use an environment variable, a system file-name, a literal, or a data-name in the ASSIGN clause. If you specify an environment variable as the assignment-name, the environment variable is evaluated at run time and the value (including optional directory and path names) is used as the system file-name.

If you use a file system other than the default, you need to indicate the file system explicitly, for example, by specifying the file-system identifier before the system file-name. For example, if MYFILE is an STL file, and you use F1 as the name of the file in your program, you can code the ASSIGN clause as follows:


SELECT F1 ASSIGN TO STL-MYFILE

If MYFILE is not an environment variable, or is an environment variable that is set to the empty string, the code shown above treats MYFILE as a system file-name. If MYFILE is an environment variable that has a value at run time other than the empty string, the value of the environment variable is used.

For example, if MYFILE is set by the command export MYFILE=RSD-YOURFILE, the system file-name is YOURFILE, and the file is treated as an RSD file, overriding the file-system ID (STL) coded in the ASSIGN clause.

If you enclose an assignment-name in quotation marks or single quotation marks (for example, "STL-MYFILE"), the value of any environment variable is ignored. The literal assignment-name is used.

Related references  
Precedence of file-system determination  
FILESYS  
ASSIGN clause (COBOL for Linux® on x86 Language Reference)