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

All sort of Mainframes Interview Questions.
Previous topicNext topic

Topic Author
TetraTop
New Member
Posts: 4
Joined: Tue Sep 08, 2015 11:34 am

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

Post by TetraTop » Mon Sep 12, 2016 2:44 pm

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.



User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1328
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
Zodiac: Virgo

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

Post by Robert Sample » Mon Sep 12, 2016 5:27 pm

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.



User avatar

Robert Sample
Global Moderator
Global Moderator
Posts: 1328
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
Zodiac: Virgo

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

Post by Robert Sample » Mon Sep 12, 2016 6:57 pm

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.



Previous topicNext topic

Return to “Interview Questions.”