Working storage of called program.

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

Topic author
Sankar Sabari
New Member
Posts: 4
Joined: Thu Mar 17, 2016 9:54 pm
Has thanked: 2 times

Working storage of called program.

Postby 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: 544
Joined: Wed Apr 23, 2014 8:45 pm
Been thanked: 11 times

Re: Wroking storage of called program.

Postby 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

Online
User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1275
Joined: Fri Jun 28, 2013 1:22 am
Location: East Dubuque Illinois
Has thanked: 2 times
Been thanked: 90 times

Re: Wroking storage of called program.

Postby 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
Has thanked: 1 time
Been thanked: 25 times

Re: Working storage of called program.

Postby 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
Has thanked: 2 times

Re: Working storage of called program.

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

Thank you so much William.




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

Who is online

Users browsing this forum: CommonCrawl [Bot] and 2 guests