Page 1 of 1

Value of the varaible depending on static or dynamic call in COBOL.

Posted: Mon Sep 12, 2016 2:44 pm
by TetraTop
Hi,

Program-A CALLs another Program-B statically. Program-B has variable B1 defined as

B1=0
B1=B1+1

After 4th CALL what is the value of the B1?

If the Program-B was CALLed dynemically, what will be the value of B1?

I said, it will be 4 in both the cases. But I was told I am wrong. Interviewer refused to explain why I am wrong. Can anyone onf you please share your thoughts on the answer for the question.

Re: Value of the varaible depending on static or dynamic call in COBOL.

Posted: Mon Sep 12, 2016 5:27 pm
by Robert Sample
The interviewer was looking for 4 and 1, most likely. With static calls, the subprogram is linked as part of the calling program and hence WORKING-STORAGE remains as it was from invocation to invocation (unless other things happen). With dynamic calls, the subprogram is independent of the calling program and hence WORKING-STORAGE should be initialized each time (according to the interviewer). However, unless the subprogram has the INITIAL attribute or the calling program uses the CANCEL verb, WORKING-STORAGE won't be re-initialized each time and hence you should get 4 for both types of CALL.

Re: Value of the varaible depending on static or dynamic call in COBOL.

Posted: Mon Sep 12, 2016 6:57 pm
by Robert Sample
Update: I have confirmed that Enterprise COBOL 5.1.1 CALL <variable> produces a value of 4 (without INITIAL or CANCEL) even with DYNAM as the compile option.