From the COBOL Language Reference:

The ADDRESS OF special register references the address of a data item in the 
LINKAGE SECTION, the LOCAL-STORAGE SECTION, or the WORKING-STORAGE SECTION.

Note the exclusion of the FILE SECTION from that list.  We had to set up an 
assembler "get address of" subroutine and pass a file name to get a FILE 
address when we had a particular need.

As I remember it, the address you get even using a subroutine may be the COBOL 
FCB rather than the actual DCB, but it's been too long and I don't remember 
accurately if that is true or not, and it may be compiler-release dependent.  
Plus no one can promise you that future generated COBOL code or updated 
compiler subroutines won't overlay your dynamic DCB changes with values 
declared in the program (e.g., record length and format from the COBOL FCB 
area), thus undoing the change you wanted to make.  Caveat emptor.

Even if you can get the DCB address that way and COBOL lets you change it as 
you please, mucking about with the DCB may work but it is likely to be less 
maintainable as time passes and those of us who intimately understand OS 
control blocks leave the field and those left are less knowledgeable about the 
uses (and abuses) that can trip you up.

IMHO, BPXWDY2 or a full-on assembler dynamic I/O subroutine (i.e., no COBOL 
FILE usage at all) are both better solutions.  I believe CBT has at least one 
version of the assembler solution out there somewhere.

Peter

-----Original Message-----
From: IBM Mainframe Discussion List <IBM-MAIN@LISTSERV.UA.EDU> On Behalf Of 
Charles Hardee
Sent: Friday, April 28, 2023 4: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.
--

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

Reply via email to