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

All sort of Mainframes Interview Questions.

Topic author
TetraTop
New Member
Posts: 4
Joined: Tue Sep 08, 2015 11:34 am
Been thanked: 1 time

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

Postby 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.



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: Value of the varaible depending on static or dynamic call in COBOL.

Postby 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.



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: Value of the varaible depending on static or dynamic call in COBOL.

Postby 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.




Return to “Interview Questions.”

Who is online

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