Page 1 of 1

Confusion between call in cobol.

PostPosted: Fri Jul 07, 2017 6:34 pm
by Deepak kumar25
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.

Re: Confusion between call in cobol.

PostPosted: Fri Jul 07, 2017 6:48 pm
by Robert Sample
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.

Re: Confusion between call in cobol.

PostPosted: Tue Aug 15, 2017 11:57 am
by SarahBishop
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.