At large installations, with many clients and servers, changes in file location and network configuration can mean frequent tedious maintenance of client runtime configuration files. Every time a new server comes on-line, or a network reorganization moves data files from one server to another, the FILE_PREFIX and CODE_PREFIX definitions and name aliases must be updated.
One way to simplify the network maintenance would be to create a file that contains the name of the file server. Each application would then be written so that it reads this file and uses the name it finds there when referencing the server. If you need to move your files to a new server, you have to change only this single file.
Here's an example of this approach:
First determine a permanent location for the server name file, and create it there. The following program creates a server name file on machine "faithful," on our hypothetical network:
identification division. program-id. svnamcrt. environment division. input-output section. file-control. select namefile assign to disk "@faithful:/usr/acucobol/srvrnam.dat". data division. file section. fd namefile. 01 namerec pic x(60). screen section. 01 enter-screen. 03 "REMOTE DIRECTORY: " line 5. 03 using namerec. procedure division. main-logic. open output namefile. display window erase. display enter-screen. accept enter-screen. write namerec. close namefile. stop run.
For the purposes of this example, enter @helios:/usr2/sales/records at the ACCEPT. This string designates the machine (helios) and the directory on that machine (/usr2/sales/records) where our data files can be found.
The next step is to create a front-end program that your application will use to read the server name file. It is possible for this program to be written in such a way that you can avoid any recompilation of existing programs within your application. The following is an example of such a front-end program:
identification division. program-id. srvrnam. environment division. input-output section. file-control. select namefile assign to disk "@faithful:/usr/acucobol/srvrnam.dat". data division. file section. fd namefile. 01 namerec pic x(60). working-storage section. 01 ws-prefix pic x(80). procedure division. main-logic. open input namefile. read namefile. close namefile. string namerec delimited by spaces into ws-prefix. set environment "FILE_PREFIX" to ws-prefix. call "your_app". stop run.
In the above example, the program reads the server name file (found on faithful), creates the environment variable FILE_PREFIX set to the value found in the server name file (@helios:/usr2/sales/records), and then calls the existing application. Because the variable is defined in the same run unit in which the application runs, the variable is available to the application. File operations are now routed to the machine helios.
A file trace for this program might look like:
Configuration file = '/etc/cblconfig' Try loading 'srvrnam'... srvrnam loaded @faithful:/usr/acucobol/srvrnam.dat: open input @faithful:/usr/acucobol/srvrnam.dat: next @faithful:/usr/acucobol/srvrnam.dat: close Set parameter 'FILE_PREFIX' to '@helios:/usr2/sales/records' Try loading your_app... your_app loaded Set keystroke to 'Edit=Next Terminate=13 ^M' thelp.dat: open I-o tword.dat: open I-o users.dat: open I-o
Note that FILE_PREFIX is set to the directory on helios where the data files are found. The application behaves normally, and the FILE_PREFIX variable works just as if it had been changed in the runtime configuration file, but without the effort.
There are other approaches that the front-end program might take to define FILE_PREFIX. In the following program, FILE_PREFIX includes the value held in the server name file, as well as any values that exist in the configuration file:
identification division. program-id. srvrnam. environment division. input-output section. file-control. select namefile assign to disk "@faithful:/usr/acucobol/srvrnam.dat". data division. file section. fd namefile. 01 namerec pic x(60). working-storage section. 01 ws-prefix pic x(80). 01 full-path pic x(120). procedure division. main-logic. open input namefile. read namefile. close namefile. accept ws-prefix from environment "FILE_PREFIX". move spaces to full-path. string namerec, " ", ws-prefix delimited by " " into full-path. set environment "FILE_PREFIX" to full-path. call "your_app". stop run.
This program accesses the server name file and calls the application, just as in the first example. However, the construction of the FILE_PREFIX variable includes both the value found in the server name file and the existing definition of FILE_PREFIX, as defined in the configuration file.
In the next example, the front-end program creates a full pathname for each file in the application, using a different variable to hold the location of each file:
identification division. program-id. srvrnam. environment division. input-output section. file-control. select namefile assign to disk "@faithful:/usr/acucobol/srvrnam.dat". data division. file section. fd namefile. 01 namerec pic x(60). working-storage section. 01 first-file pic x(20) value "THELP_FILE". 01 second-file pic x(20) value "KEYWORDS_FILE". 01 third-file pic x(20) value "USER_FILE". 01 file-1 pic x(20) value "thelp". 01 file-2 pic x(20) value "tword". 01 file-3 pic x(20) value "users". 01 ws-suffix pic x(10). 01 full-path pic x(90). procedure division. main-logic. open input namefile. read namefile. close namefile. accept ws-suffix from environment "FILE_SUFFIX". move spaces to full-path. string namerec, "/", file-1, "." ws-suffix delimited by spaces into full-path. set environment first-file to full-path. move spaces to full-path. string namerec, "/", file-2, "." ws-suffix delimited by spaces into full-path. set environment second-file to full-path. move spaces to full-path. string namerec, "/", file-3, "." ws-suffix delimited by spaces into full-path. set environment third-file to full-path. call "your_app". stop run.
Notice that the program constructs the full path name of each file. If there is a file suffix, and it is known, it could be hard coded into this program. If there is a file suffix, but it is variable, this program could extract that information from the environment and append this variable suffix to the full path name. However, be aware that this approach may require recompilation of the existing programs within the application. In the case of the above example, the ASSIGN clause in each of the affected SELECT statements includes a hard coded file suffix. The period character (".") in that name cannot be used in the name of the environment variable, so the program must be recompiled after the code change:
input-output section. file-control. select optional thelp-file * assign to "thelp.dat" assign to disk ... select optional keywords-file * assign to "tword.dat" assign to disk ... select optional user-file * assign to "users.dat" assign to disk ...
A file trace for this example might look like:
Configuration file = '/etc/cblconfig' Try loading 'srvrnam'... srvrnam loaded @faithful:/usr/acucobol/srvrnam.dat: open input @faithful:/usr/acucobol/srvrnam.dat: next @faithful:/usr/acucobol/srvrnam.dat: close Assign 'THELP_FILE' to '@helios:/usr2/sales/records/thelp.dat' Assign 'KEYWORDS_FILE' to '@helios:/usr2/sales/records/tword.dat' Assign 'USER_FILE' to '@helios:/usr2/sales/records/users.dat' Try loading 'your_app'... your_app loaded THELP-FILE: open I-o >>>translated name = @helios:/usr2/sales/records/thelp.dat KEYWORDS-FILE: open I-o >>>translated name = @helios:/usr2/sales/records/tword.dat USER-FILE: open I-o >>>translated name = @helios:/usr2/sales/records/users.dat
Note that in the above example, only those files specifically named in an environment variable will be looked for or created on the file server.