Confusion between call in cobol.



Confusion between call in cobol.

Postby Deepak kumar25 » Fri Jul 07, 2017 6:34 pm

Hi Folks,

I have confusion in call verb in cobol.How we decide whether we need to use by call by value, call by reference and call by content.

I know call by reference is default and shares the same memory locations but in call by value memory locations are different.

But how we decide ?

Please provide suggestions.
Deepak kumar25
 
Posts: 34
Joined: Mon Jan 10, 2011 10:51 am
Has thanked: 0 time
Been thanked: 0 time

Re: Confusion between call in cobol.

Postby Robert Sample » Fri Jul 07, 2017 6:48 pm

Use BY REFERENCE (the default) unless you have a specific reason not to. The Enterprise COBOL Language Reference manual explicitly tells you that BY VALUE is primarily intended for communicating with non-COBOL programs (such as C). The Programming Guide manual gives you, in the chapter on Shared Data, examples of each CALL and how they differ.

The bottom line is that you should use the default unless you are calling a non-COBOL subprogram. The times it matters which you use are generally quite rare and you would know these times from the way you get bad results when using the default CALL.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Confusion between call in cobol.

Postby SarahBishop » Tue Aug 15, 2017 11:57 am

BY reference means that any changes made by the sub program to the variables it received are visible by the calling program.
BY content means that the calling program is passing only the contents of the literal or identifier. With a CALL…BY CONTENT, the called program cannot change the value of the literal or identifier in the calling program, even if it modifies the parameters it received.
BY value means that the calling program is passing the value of the literal, or identifier, not a reference to the sending item. The called program can change the parameter in the called program. However, because the sub program has access only to a temporary copy of the sending item, those changes don't affect the argument in the calling program
The major difference between call by value and call by reference is that in the call by value a copy of actual arguments is passed to respective formal arguments. While, in call by reference the location (address) of actual arguments is passed to formal arguments, hence any change made to formal arguments will also reflect in actual arguments.
SarahBishop
 
Posts: 1
Joined: Tue Aug 15, 2017 11:51 am
Has thanked: 0 time
Been thanked: 0 time


Return to Interview Questions

 


  • Related topics
    Replies
    Views
    Last post