Working storage of called program.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Sankar Sabari
Registered Member
Posts: 22
Joined: Thu Mar 17, 2016 9:54 pm

Working storage of called program.

Post by Sankar Sabari »

Hi,

If a program is dynamically linked, are values retained in working storage if this sub-program is called multiple times from the same source program? Can someone please guide me on this.

Thanks.
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Wroking storage of called program.

Post by nicc »

I believe that this information is in one of the COBOL manuals - Language Reference or User Guide both of which you should have referred to before posting. Once you have referred to them come back with any questions that you may have about that information. Manuals can be a bit tricky to understand especially if they are not in your first language.
Regards
Nic
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1886
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Wroking storage of called program.

Post by Robert Sample »

Have you looked at the CANCEL statement in the Language Reference manual? Have you looked at the definition of run unit ? If not, you have some reading to do.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Working storage of called program.

Post by William Collins »

Wherever your sub-program is CALLed from, its previous WORKING-STORAGE values will be retained.

If you don't want that behaviour (for all or some of your fields) define the fields in the LOCAL-STORAGE SECTION. Fields in LOCAL-STORAGE are reallocated on each CALL. If they are defined with a VALUE clause, they are reset to that value. If they have no VALUE clause, their content is undefined.

IS INITIAL on the PROGRAM-ID makes the WORKING-STORAGE behave like LOCAL-STORAGE.

CANCEL (indicating an appropriate name) remove the sub-program from storage (assuming it is there) such that the next time it is CALLed, its WORKING-STORAGE has initial values. Remembering, again, those items with no VALUE clause have no pre-determined value.

The "no pre-determined value" is not strictly true, as the behaviour can me modified by a Language Environment (LE) run-time option. But, hopefully you are not using that option. For the saving of the effort of using the word VALUE with a literal is a run-time overhead for each initial CALL. So a losing, not a saving.
Sankar Sabari
Registered Member
Posts: 22
Joined: Thu Mar 17, 2016 9:54 pm

Re: Working storage of called program.

Post by Sankar Sabari »

Thank you so much William.
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.”