Write to arbitrary work file

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.

Q1) What are the NTWORK AM/OPEN/CLOSE/DISP settings ?
Q2) Which operating system are you using?
http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat426mf2/parms/work.htm#work_OPEN

See http://techcommunity.softwareag.com/ecosystem/documentation/natural/nat426mf2/sm/definewo.htm#Work_Files_under_OS390

With the DEFINE WORK FILE and USR2021N, you should be able to change the file that is written to without having to use different file numbers.

I’m using Z/VSE. I don’t think that DEFINE WORK FILE would provide any advantage to me because I’m not trying to allocate multiple files to a single file number (although I have other applications where that may be helpful).

I found that changing the OPEN mode to ACC allowed my logic to work as I expected in this situation. I’ll have to do some testing to make sure it works correctly in other situations, but I think that my problem is solved.

Thanks for the help!