Page 1 of 1

Working storage of called program.

Posted: Sun Feb 05, 2017 11:48 am
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.

Re: Wroking storage of called program.

Posted: Sun Feb 05, 2017 4:55 pm
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.

Re: Wroking storage of called program.

Posted: Sun Feb 05, 2017 8:02 pm
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.

Re: Working storage of called program.

Posted: Sun Feb 05, 2017 10:56 pm
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.

Re: Working storage of called program.

Posted: Wed Feb 08, 2017 3:47 pm
by Sankar Sabari
Thank you so much William.