I don't think you can do that. Unfortunately COBOL does not yet support actual FILE-type variables. COBOL files are essentially CONSTANTS in the language definition. I wish that we had PL/I's FILE variable capability, but we don't.
IMHO your best bet is to avoid multiple DD allocations entirely. Instead start with a list of DSN's to be input (can be another separate input file) and dynamically assign each DSN you wish to process to the "constant" COBOL DD name in the ASSIGN clause, then FREE it (also using BPXWDYN) when you finish processing each file and then start with the next DSN (if any left). You could also leave the DD names allocated as they already are and use an assembler function to retrieve the JFCB (or BXWDYN) to get the DSN of each assigned DD name and then use those to do a dynamic assign of each DSN to the COBOL file DD name from the ASSIGN clause, but the you will have two DD names assigned to the same file in the same step, which won't work unless DISP=SHR for all of them. And if any of them is a GDG (+1) from a prior step, you have to mess around with getting the GDG suffix right in the dynamic allocate. I once tried to mess around with dynamically changing the DCB DD name field of the closed COBOL file, but finding the DCB for a COBOL file is very compiler-release dependent and is a reverse-engineering effort that can be upset by IBM any time they decide to update COBOL implementation structures. Messy and a maintenance nightmare, so I dropped that effort. HTH Peter -----Original Message----- From: IBM Mainframe Discussion List <IBM-MAIN@LISTSERV.UA.EDU> On Behalf Of Schmitt, Michael Sent: Friday, April 28, 2023 3:38 PM To: IBM-MAIN@LISTSERV.UA.EDU Subject: COBOL to dynamic DD name 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. -- This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system. ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN