ABAP Keyword Documentation → ABAP - Reference → Calling and leaving program units → Calling Processing Blocks → Calling Procedures → Method Calls → Static Method Calls
... meth1( ... )->meth2( ... )->... - Method Chaining
Other versions: 7.31 | 7.40 | 7.54
Syntax
... { static_meth( ... )->meth1( ... )->meth2( ... )->...->meth( ... ) }
| { static_meth( ... )->meth1( ... )->meth2( ... )->...->attr } ...
Alternatives
1. static_meth( ... )->meth1( ... )->meth2( ... )->...->meth( ... )
2. static_meth( ... )->meth1( ... )->meth2( ... )->...->attr
Effect
Chains static method calls to a chained method call or a chained attribute access.
static_meth
, meth1
, meth2
, ... , expect
functional methods whose return values are
reference variables pointing to objects of the next method along. All methods that follow static_meth
must be called using the object component selector.
The parameters are passed to the functional methods static_meth
, meth1
, meth2
, ... using the syntax valid for
functional method calls.
Alternative 1
static_meth( ... )->meth1( ... )->meth2( ... )->...->meth( ... )
Effect
Chained method call. Calls the instance method meth
in an object. The reference variable for the object is the return value of the preceding method chaining.
A chained method call be specified as a standalone statement or as a
functional method call in a suitable
operand position. When passing parameters to meth
, the appropriate rules apply.
If the return value method of the last method has a structured data type, the chained method call can, like a structure, be specified in front of the
structure component selector -
to access a component of the structure.
Notes
-
The obsolete statement
CALL METHOD
cannot be used as a prefix in a standalone statement in this form of the static method call. -
In
static_meth
, a constructor expression can be specified with a constructor operatorNEW
orCAST
fororef
not only in a functional call, but also in standalone statements.
Example
Calls the method m3
in an object of the class c3
, addressed using method chaining.
CLASS c3 DEFINITION.
PUBLIC SECTION.
METHODS m3 CHANGING c3 TYPE string.
ENDCLASS.
CLASS c2 DEFINITION.
PUBLIC SECTION.
METHODS m2 IMPORTING i2 TYPE string
RETURNING value(r2) TYPE REF TO c3.
ENDCLASS.
CLASS c1 DEFINITION.
PUBLIC SECTION.
CLASS-METHODS m1 IMPORTING i1 TYPE string
RETURNING value(r1) TYPE REF TO c2.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD m1.
CREATE OBJECT r1.
ENDMETHOD.
ENDCLASS.
CLASS c2 IMPLEMENTATION.
METHOD m2.
CREATE OBJECT r2.
ENDMETHOD.
ENDCLASS.
CLASS c3 IMPLEMENTATION.
METHOD m3.
c3 = 'New text'.
MESSAGE c3 TYPE 'I'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA txt TYPE string VALUE `test`.
c1=>m1(
i1 = `p1` )->m2(
i2 = `p2` )->m3(
CHANGING c3 = txt ).
Alternative 2
static_meth( ... )->meth1( ... )->meth2( ... )->...->attr
Effect
Chained attribute access. Accesses the instance attribute attr
in an object. The reference variable for the object is the return value of the preceding method chaining.
If the attribute has a structured data type, the chained attribute access can, like a structure, be specified in front of the
structure component selector -
to access a component of the structure.
A chained attribute access can currently only be specified in suitable reader positions. Writes to an attribute addressed using method chaining are not yet possible.
Example
See Method Chaining.