Search code examples
cobolcalling-convention

What is the difference between BY CONTENT and BY VALUE in a CALL statement?


What is the difference between BY CONTENT and BY VALUE in a CALL statement in COBOL?


Solution

  • BY CONTENT on a CALL will copy the content of the identifier to a compiler-managed area of storage, which will then be passed to the CALLed program "by reference" implicitly.

    This means the CALLed program can change the data, but no change made in the CALLed program will affect the original data in the CALLing program.

    Any identifier, of any size valid for the compiler, can be used BY CONTENT (subject to any limits, if existing, which are documented for the specific compiler - you never know).

    Although you can change the value in a CALLed program, it would seem a bit obscure to do so, at best.

    BY VALUE is an entirely different beast. It is very limited, in that the value "passed" can be either an "integer" or a one-byte alphanumeric value. It can also be a literal.

    The PROCEDURE DIVISION USING ... has to know, in the case of BY VALUE, that is is so, by specifying it in an equivalent manner to the CALL. BY REFERENCE and BY CONTENT on the CALL are both BY REFERENCE on the PROCEDURE DIVISION USING.

    How this is implemented is down to the specific compiler. IBM Enterprise COBOL puts the value itself in the "parameter list".