IBM AS/400 Frozen Dessert Maker User Manual


 
Passing Prototyped Parameters
Passing by Value
With a prototyped procedure, you can pass a parameter by value instead of by
reference. When a parameter is passed by value, the compiler passes the actual
value to the called procedure.
Note: OS/400 program calls require that parameters be passed by reference.
Consequently, you cannot pass a parameter by value to a program.
Passing by value allows you to:
Pass literals and expressions as parameters.
Pass parameters that do not match exactly the type and length that are
expected.
Pass a variable that, from the caller's perspective, will not be modified.
When a parameter is passed by value, the called program or procedure can
change the value of the parameter, but the caller will never see the changed value.
One primary use for passing by value is that you can allow less stringent matching
of the attributes of the passed parameter. For example, if the definition is for a
numeric field of type packed-decimal and length 5 with 2 decimal positions, you
must pass a numeric value, but it can be:
A packed, zoned or binary constant or variable, with any number of digits and
number of decimal positions
A built-in function returning a numeric value
A procedure returning a numeric value
A complex numeric expression such as
2 * (Min(Length(First) + Length(Last) + 1): %size(Name))
If the prototype requires an array of 4 elements, the passed parameter can be:
An array with fewer than 4 elements. In this case, the remaining elements in
the received parameter will contain the default value for the type.
An array with 4 elements. In this case, each element of the received parameter
will correspond to an element of the passed parameter.
An array with more than 4 elements. In this case, some of the elements of the
passed array will not be passed to the received parameter.
A non-array. In this case, each element of the received parameter will contain
the passed parameter value.
To pass a parameter by value, specify the keyword VALUE on the parameter defi-
nition in the prototype, as shown in the figures below.
136 ILE RPG for AS/400 Programmer's Guide