Example: using different input files

This example shows that you can use the same COBOL program to access different files by setting an environment variable before the programs runs.

Consider a COBOL program that contains the following SELECT clause:


SELECT MAINFILE ASSIGN TO MAINA

Suppose you want the program to access either the checking or savings file using the file called MAINFILE within the program. To do so, set the MAINA environment variable before the program runs by using one of the following two statements as appropriate, assuming that the checking and savings files are in the /accounts directory:


export MAINA=/accounts/checking
export MAINA=/accounts/savings

You can thus use the same program to access either the checking or savings file as the file called MAINFILE within the program without having to change or recompile the source.