BY VALUE Phrase
When the BY VALUE phrase is specified, the value of the parameter is passed, not a reference to the sending data item. The called program can modify the formal parameter corresponding to the BY VALUE parameter, but any such changes do not affect the parameter since the called program has access to a temporary copy of the sending data item.
While BY VALUE parameters are primarily intended for communication with non-COBOL programs (such as C), they can also be used for COBOL-to-COBOL invocations. In this case, BY VALUE must be specified or implied for both the parameter in the CALL USING phrase and the corresponding formal parameter in the PROCEDURE DIVISION USING phrase.
The BY CONTENT, BY VALUE and BY REFERENCE phrases apply to the parameters that follow them until another BY CONTENT, BY VALUE or BY REFERENCE phrase is encountered. If none of these phrases appear before the first parameter, BY REFERENCE is assumed.
- identifier-3
- Must be defined as a level-01, level-77, or elementary
data item in the File, Working-Storage, Local-Storage or Linkage Sections.
It can be:
- A data item of any level in the Data Division
- A pointer data item (an item defined implicitly or explicitly as USAGE IS POINTER)
- A procedure-pointer data item
- A DBCS data item
- A national data item
- A floating-point data item
- A date-time data item
- Reference modified, however, the length of the reference modified item must be known at compile time.
- ADDRESS OF special register
- For information about this special register, see page ADDRESS OF Special Register.
- ADDRESS OF a data item
- For information about this, see page ADDRESS OF.
- LENGTH OF special register
- The LENGTH OF special register contains the number of bytes used by a data item referenced by an identifier. For more information, see LENGTH OF Special Register.
- literal-3
- Can be:
- A nonnumeric literal
- A figurative constant
- A Boolean literal
- A DBCS literal
A national literal.
- float-literal-1
- A floating-point literal is passed as an 8 byte internal float (COMP-2), unless the SIZE phrase is specified. For floating-point items the size phrase can be 4 or 8.
- integer-1
- Can be a signed or unsigned integer.
Integer-1 is passed as a binary value. If integer-2 is not specified then integer-1 will be passed as a 4-byte binary value. Integer-2 specifies the size of integer-1. This can be one of 1, 2, 4 or 8.