ABAP Keyword Documentation → ABAP − Reference → Declarations → Typing → Checking Typing
Functions and Expressions as Actual Parameters
Functions and expressions can be specified as actual parameters in the following formal parameters:
- Writing Positions
- Reading Positions
- Input parameters of
methods in
method calls, when
objects are created, or when exceptions
are raised using
RAISE EXCEPTION or
THROW
in a condition exception
- Input parameters of
function modules in
all variants of the statement
CALL FUNCTION
.
The parameters are read from left to right (and from inside to outside) and the procedure executed. A parameter cannot be modified by the method itself or by the evaluation of a preceding expression. This applies in particular to writable expressions in result positions.
Special rules apply to typing checks, identifying the calculation type, and parameter passes.
Other versions: 7.31 | 7.40 | 7.54
Notes
- In the case of dynamic method calls, the same rules apply as to static method calls. However, the handling during runtime is time-consuming. Therefore, helper variables should be used in a dynamic call instead of functions or arithmetic expressions if possible. Function module calls are always dynamic and, compared to method calls, fewer rules apply.
Checking Typing
- A numeric function, a description function, or an arithmetic expression can
- be bound to any numeric input parameter or any input parameter typed using the type
any
in a method call.
- be bound to any appropriately typed input parameter in a function module call.
- A bit function or a bit expression can
- be bound to any byte-like or general typed input parameter in a method call.
- be passed to input parameters of the type
x
or a generic type coveringx
in function module calls.
- A string function or a string expression can
- be bound to any character-like or general typed input parameter in a method call.
- be passed to input parameters of the type
string
or a generic type coveringstring
in function module calls.
- A constructor expression can
- be passed to every input parameter that matches the specified type
type
of the constructor expression in method calls. In this case (with the exception of conversion operator CONV in the constructor expression), the#
character can only be specified fortype
if the input parameter is typed in full and this type is used.
- be passed to every input parameter that matches the specified type
type
of the constructor expression in function module calls. The character#
cannot be specified fortype
ion the constructor expression since static derivations of types are not possible in function module calls.
- A table expression can
- be passed in method calls or function calls to every input parameter that matches the type of the result.
Notes
- In function module calls, the typing is not checked until runtime.
- No arithmetic expressions, description functions, or numeric functions can be passed to formal parameters
with the generic type
data
. This restriction can be bypassed by applying the conversion operatorCONV
to the actual parameter. This restriction does not apply to the generic typeany
.
Calculation Type and Calculation Length
If calculation expressions are specified as actual parameters, the calculation type and calculation length are specified as follows:
- The calculation type of an arithmetic expression is determined
- in method calls from the operands of the expression and the typing of the input parameter, if this parameter is fully typed. If the input parameter is typed generically, only the operands of the expression are evaluated.
- in function module calls from the operands of the expression. The typing of the input parameter is ignored.
- The calculation length of a bit expression is the length of the largest operand of the expression.
Passing Parameters
When binding a function, a calculation expression, a constructor expression, or a table expression, the parameters are always passed by value, even if the formal parameter is defined as to be passed by reference.
Fully Typed
The return value of a function or the result of a calculation expression, a constructor expression, or a table expression is converted, if necessary, to the type of the input parameter and passed.
Generically Typed
- In a function, a constructor expression, or a table expression, the formal parameter takes the type of the return value or result. Only bit functions are handled like bit expressions (see below).
- With an arithmetic expression, the formal parameter takes over the calculation type determined by
the operand. If the calculation type is
p
, the length is always 16. The number of decimal places is determined by the accuracy required by the calculation and therefore depends on the values of the operands.
- In a bit expression or a bit function, the formal parameter is set to type
x
in the calculation length determined by the operands.
- In a string expression, the formal parameter is set to the type
string
in the case of fully generic typing or the generic typescsquence
clike
. In the case of the typesc
andn
with generic lengths, the length is set to the length of the result of the string expression.
Example
The functional method m1
is called twice for each assignment to result
.
The first call is executed in an arithmetical expression, which is passed as an actual parameter in
the second call. In the first call of each assignment, the formal parameter p1
has type p
of length 16. The number of decimal places is 0 in the first assignment,
14 in the second, and 1 in the third assignment. In the second call, the formal parameter p1
has the type decfloat34
in each assignment, because the calculation type of the arithmetic expression is determined by the return value of m1
.
CLASS c1 DEFINITION.
PUBLIC SECTION.
CLASS-METHODS m1 IMPORTING p1 TYPE numeric
RETURNING value(ret) TYPE decfloat34.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD m1.
ret = p1.
ENDMETHOD.
ENDCLASS.
DATA num1 TYPE p DECIMALS 2 VALUE '2.00'.
DATA num2 TYPE p DECIMALS 2 VALUE '1.00'.
DATA result TYPE decfloat34.
START-OF-SELECTION.
result = c1=>m1( sqrt( 4 ) + c1=>m1( num1 / 2 ) ).
result = c1=>m1( sqrt( 4 ) + c1=>m1( num1 / 3 ) ).
result = c1=>m1( sqrt( 4 ) + c1=>m1( num2 / 2 ) ).