10 pts.
 Dynamic file allocation in a COBOL subroutine
I have successfully coded dynamic file allocation in a COBOL program.  My problem is this: I need to dynamically allocate the file in a central subroutine and then be able to open and close that file from the program that calls the subroutine to allocate the file.  Is this possible and if so, how?

Software/Hardware used:
COBOL Z/OS Enterprise Mainframe
ASKED: February 22, 2010  5:11 PM
UPDATED: July 28, 2010  4:40 PM

Answer Wiki:
first to clarify - "mainframe" is z/OS. If not, then the following may not apply. Dynamic allocation aside, the module (called or main) that defines the file and opens it and closes it really needs to be the one that reads it. In order to have 2 different modules operating on the file will require that the DCB (or in COBOL terms the "FD") be passed as a parm between the 2 different modules. ( I am sure you are away that when I say "passed as a parm" what is really happening is that the ADDRESS of the parm is passed and made available to the called module.) Passing the address of "FD" is the only way the two modules will be able to operate on it. Different versions of COBOL (especially OLD ones) can pass all sorts of things as parms in a call. (I remember one COBOL module that actually passed COBOL paragraph names to the called module and the called module could return to different locations in the calling module. WOW. But I think that went away when we moved off of COBOL 74.) All you can do is try to pass the required information from module to module. But I think I would try to find a way to put it all in one module.
Last Wiki Answer Submitted:  February 22, 2010  6:29 pm  by  Meandyou   5,205 pts.
All Answer Wiki Contributors:  Meandyou   5,205 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

In your first sentence you stated you have successfully coded dynamic file allocation in a COBOL program. Then you would only have to call that module, passing the necessary parameters i.e. file name, disposition, etc. The called module would return a return-code indicating success or failure. In case of success you would proceed as normal in opening, reading, closing your file. Call the module again to deallocate – free – the file allocation. At least I remember thats the way I used to do, although the dynamic allocaiton routine was an assembler module.

 105 pts.