Using BYVALUE and BYADDR

Unless an argument is passed by value (BYVALUE), a reference to an argument, not its value, is generally passed to a subroutine or function. This is known as passing arguments by reference, or BYADDR.

A reference to a parameter in a procedure is a reference to the corresponding argument. Any change to the value of a parameter is actually a change to the value of the corresponding argument. However, this is not always possible or desirable. Constants, for example, should not be altered by an invoked procedure. For arguments that should not change, a dummy argument containing the value of the original argument is passed. Any reference to the parameter then is a reference to the dummy argument and not to the original argument.

When you specify BYADDR, the compiler puts the address of the corresponding argument in the parameter list. When you specify BYVALUE, puts the value of the argument in the parameter list.

When you specify BYVALUE, a dummy argument is not created; however, as is also true for dummy arguments, any change to the corresponding parameter in the called routine will not be visible in the calling routine.

BYVALUE is invalid with AREA, PICTURE, WIDEPIC, VARYING, and VARYINGZ. BYVALUE is also invalid with ENTRY unless the ENTRY has the LIMITED attribute.

A BYVALUE argument should be one that could reasonably be passed in a register. Hence its type should be one in the following list:

  • REAL FIXED BIN
  • REAL FLOAT
  • POINTER
  • OFFSET
  • HANDLE
  • LIMITED ENTRY
  • FILE
  • ORDINAL
  • CHAR(1)
  • WCHAR(1)
  • ALIGNED BIT(n) with n less than or equal to 8