This COBOL system provides several ways of mapping the filename supplied by the program via the ASSIGN clause onto a different name, for greater flexibility at run time. These rely on the use of environment variables.
Before you run the program, you should give any environment variables you are using an appropriate value using the operating system SET command, for example:
set dir=d2
When presented with a filename (which may be a literal, the contents of a data item, or, in the case of the ASSIGN TO EXTERNAL syntax, an external reference), the File Handler follows this procedure:
This procedure is then repeated for the next element in the filename, and continues until all the elements in the name have been processed. The result is then considered to be the filename of the physical file.
Consider the following examples:
Filename in ASSIGN Clause | Environment Variables Searched For | Contents of Environment Variable | Filename of Physical File |
---|---|---|---|
dir\file1 | dd_dir | d2 | d2\file1 |
$dir\file1 | dd_dir;dir | d2\d4 | d2\d4\file1 |
dir1\dir2\file1 | dd_dir1 | d4 | d4\dir2\file1 |
$dir1\$dir2\file1 | First iteration: dd_dir1;dir1 Second iteration: dd_dir2;dir2 | dd_dir1 or dir1: d2\d4 dd_dir2 or dir2: d3 | d2\d4\d3\file1 |
file1 | dd_file1 | d2 | d2 |