SAP CALL METHOD FUNCTIONAL ABAP Statements

Get Example source ABAP code based on a different SAP table
  



meth( ... ) - Functional Method Call


ABAP Syntax ... {
static_meth( )
| static_meth( a )
| static_meth( p1 = a1 p2 = a2 ... )
| static_meth( [ EXPORTING p1 = a1 p2 = a2 ...]
[IMPORTING p1 = a1 p2 = a2 ...]
[CHANGING p1 = a1 p2 = a2 ...] ) } ...

What does it do? Functional call of a functional method static_meth in a suitable reader position for functions and expressions. The return value 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 to pass parameters is the same as in standalone method calls. The following differences from standalone method calls exist: The return value 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 functional method has the same name as a predefined function, the functional method is always called.



Latest 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 in 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.
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 ABAP Coding
Functional call of a method. Unlike in the example for
standalone method calls, the return value 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 ABAP Coding
The functional method
factorial in this example has the return value fact of type
int8, i, used on the right side of an assignment in an expression.
RETURNING value(fact) TYPE int8. CLASS math DEFINITION.
PUBLIC SECTION.
METHODS factorial
IMPORTING n TYPE i
RETURNING value(fact) TYPE i.
ENDCLASS.

CLASS math IMPLEMENTATION.
METHOD factorial.
fact = 1.
IF n = 0.
RETURN.
ELSE.
DO n TIMES.
fact = fact * sy-index.
ENDDO.
ENDIF.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.

DATA(result) = 100 + NEW math( )->factorial( 4 ).

Return to menu