Page 1 of 1

Impact of calling sub-program twice in the calling program

PostPosted: Mon Jan 17, 2011 6:48 am
by premv12
If a cobol program is called 2nd time from the same callng program, called program remains in the last used state. Is this true for Static call or for both static and dynamic call?

Re: Impact of calling sub-program twice in the calling progr

PostPosted: Mon Jan 17, 2011 7:23 am
by Robert Sample
The Programming Guide manual tells you the answer in chapter 4.1.2:
A subprogram is usually left in its last-used state when it terminates with EXIT PROGRAM or GOBACK. The next time the subprogram is called in the run unit, its internal values are as they were left, except that return values for PERFORM statements are reset to their initial values. (In contrast, a main program is initialized each time it is called.)

There are some cases where programs will be in their initial state:


A subprogram that is dynamically called and then canceled will be in the initial state the next time it is called.

A program that has the INITIAL attribute will be in the initial state each time it is called.

Data items defined in the LOCAL-STORAGE SECTION will be reset to the initial state specified by their VALUE clauses each time the program is called.
Learning to use the manuals will allow you to answer this type of question yourself, much faster than a forum could.