ABAP Keyword Documentation → ABAP − Reference → Calling and leaving program units → Calling Processing Blocks → Calling Procedures → Method Calls → Static Method Calls
meth( ... ) - Functional Method Call
Other versions: 7.31 | 7.40 | 7.54
Syntax
... { meth( )
| meth( a )
| meth( p1 = a1 p2 = a2 ... )
|
meth( [EXPORTING p1 = a1 p2 = a2 ...]
[
IMPORTING p1 =a1 p2 = a2 ...]
[CHANGING
p1 =a1 p2 = a2 ...] ) } ...
Effect
Functional call of a
functional method meth
in a suitable
reading position for functions and expressions.
The return code of the method declared using
RETURNING is used as an operand and its full typing determines the data type of the operand. The actual parameters bound to
output parameters and
input/output parameters are handled in the same way as in
standalone method calls.
The semantics of the syntax used in parameter passing are the same as in standalone method calls. Functional method calls differ from standalone method calls in the following ways:
-
The return code in functional method calls cannot be assigned to an actual parameter explicitly using
RECEIVING
. - Inline declarations are not possible for actual parameters.
-
Non-class-based exceptions cannot be handled using
EXCEPTIONS
.
If the return code of the method has a structured data type, a functional method call can, like a structure, be specified in front of the
structure component selector -
and use this to access a component of the structure.
If the functional method has the same name as a built-in function, the functional method is always called.
If an exception is raised when the functional method call is used as an operand, the exception cannot always be handled, and a runtime error can occur instead (depending on the position of the operand).
Notes
-
In functional method calls, class-based exceptions propagated from the method can be handled as usual in a
TRY
control structure or propagated further. The non-class-based exceptions of a functional method, however, always produce a runtime error. - The same applies to resumable exceptions in functional method calls as to all other methods. If processing can be resumed successfully, execution of the statement called in the method can be completed.
- Method chaining is possible in the operand positions where functional methods can be specified.
-
A functional method call whose first method is an instance method can be introduced using the instance
operator
NEW
or the casting operatorCAST
. - A single functional method call can be used as a predicative method call and as a relational expression.
-
In functional calls of a functional method, an implicit temporary actual parameter is always assigned to the return value, This parameter is used as the operand of the current operand position. This means that the
predicate expression
IS SUPPLIED
is always true for the return value within a functionally called method. - Functional method calls can be nested in any way, which means that inline declarations for actual parameters can produce confusing results. For this reason, inline declarations are not allowed.
-
If successful, each method call sets the system field
sy-subrc
to 0, which means that all statements with functional method calls modify the value of this field.
Example
Functional call of a method. Unlike in the example for standalone method calls, the return code is assigned to the result. The inline declarations made in that example, however, are not possible here.
CLASS c1 DEFINITION.
PUBLIC SECTION.
CLASS-METHODS do_something IMPORTING p1 TYPE i
p2 TYPE i
EXPORTING p3 TYPE i
p4 TYPE i
RETURNING VALUE(r) TYPE i.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD do_something .
...
ENDMETHOD.
ENDCLASS.
DATA: a1 TYPE i,
a2 TYPE i.
START-OF-SELECTION.
DATA(result) =
c1=>do_something( EXPORTING p1 = 333
p2 = 444
IMPORTING p3 = a1
p4 = a2 ).
Example
The functional method
factorial
in this example has the return code fact
of type int8
, used on the right side of an assignment in an expression.
CLASS math DEFINITION.
PUBLIC SECTION.
METHODS factorial
IMPORTING n TYPE i
RETURNING VALUE(fact) TYPE int8.
ENDCLASS.
CLASS math IMPLEMENTATION.
METHOD factorial.
fact = COND int8( WHEN n < 0 THEN 0
ELSE REDUCE int8(
INIT f = CONV int8( 1 )
FOR i = 1 UNTIL i > n
NEXT f = f * i ) ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(result) = 100 + NEW math( )->factorial( 4 ).
Example
The functional method
get
in this example has a structured return code whose component carrname
is accessed.
CLASS carriers DEFINITION.
PUBLIC SECTION.
METHODS get
IMPORTING carrid TYPE scarr-carrid
RETURNING VALUE(r) TYPE scarr.
ENDCLASS.
CLASS carriers IMPLEMENTATION.
METHOD get.
SELECT SINGLE *
FROM scarr
WHERE carrid = @carrid
INTO @r.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
cl_demo_output=>display( NEW carriers( )->get( 'LH' )-carrname ).