Example of dynamic filename assignment

 select fd-in-name
     assign to dynamic ws-in-file.
 select fd-out-name
     assign to dynamic ws-out-file.
 working-storage section.
 01 ws-in-file  pic x(30) value "input.dat".
 01 ws-out-file pic x(40).
 procedure division.
     accept ws-out-file.
     open input fd-in-name fd-out-name

In this example, the file input.dat in the current directory and the file specified by the current value of ws-out-file, are opened.