Working storage of called program.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Previous topicNext topic

Topic Author
Sankar Sabari
New Member
Posts: 4
Joined: Thu Mar 17, 2016 9:54 pm

Working storage of called program.

Post by Sankar Sabari » Sun Feb 05, 2017 11:48 am

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: 578
Joined: Wed Apr 23, 2014 8:45 pm

Re: Wroking storage of called program.

Post by nicc » Sun Feb 05, 2017 4:55 pm

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: 1328
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
Zodiac: Virgo

Re: Wroking storage of called program.

Post by Robert Sample » Sun Feb 05, 2017 8:02 pm

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: 499
Joined: Sun Aug 25, 2013 7:24 pm

Re: Working storage of called program.

Post by William Collins » Sun Feb 05, 2017 10:56 pm

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.




Topic Author
Sankar Sabari
New Member
Posts: 4
Joined: Thu Mar 17, 2016 9:54 pm

Re: Working storage of called program.

Post by Sankar Sabari » Wed Feb 08, 2017 3:47 pm

Thank you so much William.



Previous topicNext topic

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