Share a file between program and sub-program.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
User avatar
Akshya Chopra
Registered Member
Posts: 77
Joined: Mon May 20, 2013 11:32 pm
Algeria

Share a file between program and sub-program.

Post 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 ,
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

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

Post by zprogrammer »

Forget the design for the moment

But what is the purpose and what is getting achieved?
zprogrammer
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1895
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

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

Post 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.
User avatar
Akshya Chopra
Registered Member
Posts: 77
Joined: Mon May 20, 2013 11:32 pm
Algeria

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

Post 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.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

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

Post 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.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”