HP 3000 Manuals

Parameter Passing [ HP COBOL II/XL Programmer's Guide ] MPE/iX 5.0 Documentation


HP COBOL II/XL Programmer's Guide

Parameter Passing 

Your program can pass an actual parameter to a subprogram by reference,
by content, or by value.

Passing Parameters by Reference 

By default, your program passes an actual parameter by reference.  This
means that your program passes the address of the actual parameter to the
subprogram.  If the subprogram changes the value of its formal parameter,
it also changes the value of your program's actual parameter.

Passing Parameters by Content 

When your program passes an actual parameter by content, the compiler
copies the actual parameter and passes the address of the copy to the
subprogram.  If the subprogram changes the value of its formal parameter,
it changes the value of the copy, but it does not change the value of
your program's actual parameter.  Pass parameters by content to ensure
that the subprogram does not change the value of data items.

Passing Parameters by Value 

When your program passes an actual parameter by value, it only passes its
value to the subprogram.  If the subprogram changes the value of its
formal parameter, it does not change the value of your program's actual
parameter.  To pass a parameter by value, enclose it in backslashes (\)
in the CALL statement.  Pass parameters by value to intrinsics and
non-COBOL subprograms.  Do not pass parameters by value to COBOL
subprograms.  Only numeric items can be passed by value.


NOTE Passing a parameter by content is not the same as passing it by value. The copy is passed by reference, and the called subprogram cannot tell that it has received a copy (the call is indistinguishable from a call by reference).
Parameter Alignment On MPE XL, the HP COBOL II/XL compiler assumes that all data items in the LINKAGE SECTION are byte-aligned unless the subprogram is compiled with the control option OPTFEATURES=LINKALIGNED or OPTFEATURES=LINKALIGNED16. In the first case, it assumes that they are word-aligned. In the second case, it assumes that they are halfword-aligned. If the subprogram is compiled with the control option BOUNDS, the compiler will trap parameter misalignment. Otherwise, you must be sure that your program's actual parameters are aligned the same[REV BEG] or more restrictively[REV END] as the subprogram's formal parameters.[REV BEG] You can check the alignment of actual parameters by compiling the calling program with the control option OPTFEATURES=CALLALIGNED (or OPTFEATURES=CALLALIGNED16). Passing and Retrieving a Return Value You can return a value from a COBOL subprogram using the RETURN-CODE special register in the subprogram and the GIVING phrase in the calling program. The RETURN-CODE is used to pass a value back to the calling program.[REV END] Working with the Link Editor The COBOL compiler does not inform the Link Editor of the formal parameter types for a COBOL subprogram. You must be sure that your program's actual parameters are of the same types and lengths as their formal counterparts. The COBOL compiler generates an argument descriptor field for each parameter in the USING and GIVING clauses of the CALL statement. The Link Editor uses the argument descriptor fields to match and check parameters. You can specify the level of checking by specifying PARMCHECK in the Link Editor command LINK. Level of checking determines how many argument descriptor fields the Link Editor ignores. Table 4-1 gives the values of the argument descriptor fields that the COBOL compiler sets for the Link Editor. Table 4-1. Argument Descriptor Fields --------------------------------------------------------------------------------------------- | | | | | Argument Descriptor Fields | | Entity | | | | | --------------------------------------------------------------------------------------------- | | | | | | | Mode | Type | Alignment | | | | | | --------------------------------------------------------------------------------------------- | | | | | | Function | 6 (function return) | Type that the | Alignment of function | | | | function returns. | return type. | | | | | | --------------------------------------------------------------------------------------------- | | | | | | Reference | 2 (reference parameter) | Matches anything. | Alignment of type of | | parameter | | | parameter. | | | | | | --------------------------------------------------------------------------------------------- | | | | | | Value parameter | 1 (value parameter) | Type of | Alignment of type of | | | | parameter. | parameter. | | | | | | ---------------------------------------------------------------------------------------------


MPE/iX 5.0 Documentation