When procedure parameters are declared with DECLARE-PARAMETER, the handling of the character string passed for the procedure parameter is also determined, in the TRANSFER-TYPE parameter.
If TRANSFER-TYPE = *BY-VALUE, the character string which is passed is assigned to the corresponding procedure parameter as a value.
Example
/CALL-PROCEDURE PROC2, PROCEDURE-PARAMETERS = (MILLER, EDWARD,
/'HARPER
AVENUE', TEL = 1234567)
In this example, the procedure parameter LAST-NAME is assigned the value MILLER, the procedure parameter FIRST-NAME is assigned the value EDWARD, etc.
If TRANSFER-TYPE = *BY-REFERENCE, the characters string which is passed is evaluated as a variable container for the formal procedure parameter. Consequently, the called procedure can also return results to the caller using this procedure parameter.
Example
Calling procedure:
/DECLARE-VARIABLE LAST-NAME('MILLER',*STRING) /DECLARE-VARIABLE FIRST-NAME('EDWARD',*STRING) /DECLARE-VARIABLE STR('HARPER AVENUE',*STRING) /DECLARE-VARIABLE TELEPHONE('1234567',*STRING) /.... /CALL-PROCEDURE PROC2, PROCEDURE-PARAMETERS=(LAST-NAME,FIRST-NAME, STR,,,TEL)
Called procedure PROC2:
/SET-PROCEDURE-OPTIONS /BEGIN-PARAMETER-DECLARATION /DECLARE-PARAMETER LAST-NAME (*NONE, *STRING,- / TRANSFER-TYPE = *BY-REFERENCE) /DECLARE-PARAMETER FIRST-NAME (*NONE, *STRING,- / TRANSFER-TYPE = *BY-REFERENCE)) /DECLARE-PARAMETER STR(*NONE, *STRING,- / TRANSFER-TYPE = *BY-REFERENCE)) /DECLARE-PARAMETER CITY('CHICAGO', *STRING,- / TRANSFER-TYPE = *BY-VALUE) /DECLARE-PARAMETER AREA-CODE('312', *STRING,- / TRANSFER-TYPE = *BY-VALUE) /DECLARE-PARAMETER TEL(*NONE, *STRING,- / TRANSFER-TYPE = *BY-REFERENCE)) /END-PARAMETER-DECLARATION
Variable names are passed as procedure parameters. Since TRANSFER-TYPE = *BY-REFERENCE applies for the procedure parameters in PROC2, the transferred string is not assigned to the procedure parameter as a value; instead, the variables are linked together.
Example
Procedure P contains the following lines:
/SET-PROCEDURE-OPTIONS /BEGIN-PARAMETER-DECLARATION /DECLARE-PARAMETER TOTAL (TRANSFER-TYPE=*BY-REFERENCE) /DECLARE-PARAMETER (P1(TYPE=*INTEGER),P2(TYPE=*INTEGER)) /END-PARAMETER-DECLARATION /TOTAL = P1+P2
The following commands are entered interactively:
/DECLARE-VARIABLE S /CALL-PROCEDURE P, (S,3,5) /SHOW-VARIABLE S
This results in the output:
S = 8
Variable names are transferred as procedure parameters by means of a “container mechanism”; the procedure parameter serves as a container for the variable so that the called procedure can access this variable and evaluate its contents.
Variable names can be used as procedure parameters only if the variable and the procedure parameter are declared with the same data type (the variable with DECLARE-VARIABLE in the calling procedure and the procedure parameter with DECLARE-PARAMETER in the called procedure). For example, they must both be declared with TYPE = *INTEGER. One cannot be declared with TYPE = *INTEGER and the other with TYPE = *ANY.