Page 1 of 1

Share a file between program and sub-program.

Posted: Sun Feb 16, 2014 8:50 pm
by Akshya Chopra
Hi,

If program A CALLs B, is it possible a file "some-file" is opened in Program A and data is written in to B? And is it even a good design?

Thanks ,

Re: Share a file between program and sub-program.

Posted: Sun Feb 16, 2014 9:27 pm
by zprogrammer
Forget the design for the moment

But what is the purpose and what is getting achieved?

Re: Share a file between program and sub-program.

Posted: Sun Feb 16, 2014 11:14 pm
by Robert Sample
COBOL allows use of the EXTERNAL clause in the FD to permit files to be defined in one program and used in a subprogram.

However, in general this is a VERY BAD design to implement. It violates the principles of structured programming (particularly modular design), and ties the two programs together so much that what is then the point of having a subprogram? Maintenance becomes much tougher, since any file changes have to be reflected in BOTH programs instead of just one.

Re: Share a file between program and sub-program.

Posted: Thu Feb 20, 2014 11:43 am
by Akshya Chopra
Thanks Robert. I read about EXTERNAL clause and it gives hint to do what I was thiking like a "global" variable in language C. I'll work out on your advice.

Re: Share a file between program and sub-program.

Posted: Thu Feb 20, 2014 1:10 pm
by William Collins
The advice was not to try to do it that way... yes? Good.

If you need to make file accesses from more than one program, put all the io for a file into one sub-program and use that, Use a parameter to indicate required function, a second one to indicate success/failure of IO (along with diagnostic information from FILE STATUS (and extended file status for VSAM( and a third one to indicate record-area.