This works, and is the winning solution!
All that is needed is to add a nested program: identification division. program-id. set_dd_name. data division. linkage section. 01 dcb-i. 05 filler pic x(40). 05 dd-name-dcb-i pic x(8). 01 dd-name-i pic x(8). procedure division using dcb-i dd-name-i. move dd-name-i to dd-name-dcb-i. goback. end program set_dd_name. In the parent program the select/assign is to a dummy dd name: select output-file assign to DUMMYDD To use, while the file is closed, call set_dd_name with the file name (e.g. output-file) and the desired dd name. -----Original Message----- From: IBM Mainframe Discussion List <IBM-MAIN@LISTSERV.UA.EDU> On Behalf Of Schmitt, Michael Sent: Monday, May 1, 2023 9:39 AM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: COBOL to dynamic DD name That's an interesting idea: add a nested program, call it passing the file-name (so it passes the FD), and then within the nested program find the offset of the ddname in the passed data and change it. But it assumes that when you then open the file, COBOL doesn't move the select/assign dd name to the DCB again. -----Original Message----- From: IBM Mainframe Discussion List <IBM-MAIN@LISTSERV.UA.EDU> On Behalf Of Charles Hardee Sent: Friday, April 28, 2023 3:50 PM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: COBOL to dynamic DD name *I have not tried this*, but could you use SET FILE-VAR TO ADDRESS OF FILE-NAME? Does that make FILE-VAR point to the DCB? If so, then, with the file closed, move in your DD name, open, write, close. Rinse and repeat. Like I said, I don't know if this will work, but it's worth a try. Chuck On Fri, Apr 28, 2023 at 2:38 PM Schmitt, Michael <michael.schm...@dxc.com> wrote: > I know how to have a COBOL program on z/OS use a data set name that isn't > determined until runtime, via an environment variable. My question is can > you use one file (i.e. one select/assign and one FD) to write to different > DD names, that were already allocated in the JCL? > > I can't find a way, and in the manual the syntax for the environment > variable method requires a DSN or PATH, no option for a DD name. > > ---------------------------------------------------------------------- > For IBM-MAIN subscribe / signoff / archive access instructions, > send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN > ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN