Skip to content

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:

  • Writer positions
  • Reader positions

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


Note

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

  • be bound to any numerically typed input parameter in a method call.

  • be bound to any appropriately typed input parameter in a function module call.

  • be bound to any byte-like typed input parameter in a method call.

  • be passed to input parameters of the type x or a generic type covering x in function module calls.

  • be bound to any character-like typed input parameter in a method call.

  • be passed to input parameters of the type string or a generic type covering string in function module calls.

  • be passed to every input parameter that matches the specified type type of the constructor expression in method calls. In this case, the # character can only be specified for type if the input parameter is typed in full and this type is used.

  • be used in function module calls if the function module matches the specified type type of the constructor expression. The character # cannot be specified for type ion the constructor expression since static derivations of types are not possible in function module calls.

  • be passed in method calls or function calls to every input parameter that matches the type of the result.

Note

In function module calls, the typing is not checked until runtime.

Calculation Type and Calculation Length

  • 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, then 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 inherits 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 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 types csquence clike. In the case of the types c and n 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 arithmetic 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 )  ).