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

All sort of Mainframes Interview Questions.
Post Reply
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 »

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: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

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

Post 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.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

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

Post 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.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Interview Questions.”