Dynamic file allocation in a COBOL subroutine

10 pts.
Tags:
COBOL
Dynamic file allocation
Mainframe programming
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • InfosysMgmt
    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 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following