Filename Mapping

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.

In this topic, the term "environment variable" should be read as including the Micro Focus extended environment variables which are enabled via use of the External File Mapper (see the section External File Mapper (Mfextmap) later in this chapter).

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:

  1. Isolates the first element of the filename, that is, all the text before the first slash character (\), all the text if the name does not include such a character or nothing if the filename starts with a slash character.
  2. If the first element begins with two dollar characters ($$), indicating that the file is located on a Fileshare server, switches the search process to that Fileshare server, and continues the filename mapping process with the next element.
  3. Removes the leading dollar character ($) if it is present, prefixes the characters "dd_" to this first element and searches for an environment variable with this name.
  4. If it does not find this environment variable and either the ASSIGN EXTERNAL syntax was used or the element began with a dollar character, looks for an environment variable with the same name as the element (minus the leading dollar character if present).
  5. If the search is unsuccessful, leaves the element unchanged, except in the case where the element begins with a dollar character and the whole filename contains at least one slash character. In this case, the whole of the first element, together with the first slash, is removed from the name.

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