With dynamic filename assignment, the filename is specified in the SELECT clause as a COBOL data item:
select filename assign to dynamic data-item
|filename||The filename of the file that is to be assigned.|
|data-item||The name of a COBOL data item. If the data item is not explicitly declared in your program, the Compiler creates one for you, with a picture of PIC X(255). Before the OPEN statement for the file is executed, the program must give a value to the data item.|
In the following example, the file input.dat is created in the current directory:
... select fd-in-name assign to dynamic ws-in-file. ... working-storage section. 01 ws-in-file pic x(30). ... move "input.dat" to ws-in-file. ... open output fd-in-name.
select f1 assign to dynamic f1-name. ... working-storage section. 01 f1 pic x(30). ... move """spacey filename.dat""" to f1-name .... open output f1.