Varying the input or output file at run time

The file-name that you code in a SELECT clause is used as a constant throughout your COBOL program, but you can associate the name of that file with a different system file at run time.

About this task

Changing a file-name within a COBOL program would require changing the input statements and output statements and recompiling the program. Alternatively, you can change the DSNAME value in the DD statement or the DSN or PATH value in the export command to use a different file at run time.

Environment variable values that are in effect at the time of the OPEN statement are used for associating COBOL file-names to the system file-names (including any path specifications).

The name that you use in the assignment-name of the ASSIGN clause must be the same as the ddname in the DD statement or the environment variable in the export command.

The file-name that you use in the SELECT clause (such as SELECT MAINFILE) must be the same as in the FD file-name entry.

Two files should not use the same ddname or environment variable name in their SELECT clauses; otherwise, results could be unpredictable. For example, if DISPLAY output is directed to SYSOUT, do not use SYSOUT as the ddname or environment variable name in the SELECT clause for a file.