I am writing a subprogram that will write some wrapper information to a work file. I want to be able to call this subprogram multiple times from the same program to write to different work files. Is there any way to do this?
My first thought was to supply the work file number as a variable, but Natural complained when I did that. Then I tried using this code:
DECIDE ON FIRST #P-WORK-FILE VALUE 1 WRITE WORK FILE 1 VARIABLE #OUTPUT VALUE 2 WRITE WORK FILE 2 VARIABLE #OUTPUT VALUE 3 WRITE WORK FILE 3 VARIABLE #OUTPUT /* AND SO ON UP TO WORK FILE 9... NONE VALUE IGNORE END-DECIDE
This worked well in programs that only generated output files. I ran into a problem, though, when I tried to use the subprogram in a program that reads work file 1 and writes work file 2. When I called the subprogram, it would close work file 1 for input and re-open it as output instead, even though the subprogram never executed the line that actually performs a write to work file 1. It appears that Natural is scanning through the subprogram for any write work file statements and when it finds one, it opens that file for output.