sapdev logo background
sapdev logo sapdev logo
Comments

ABAP CALL METHOD STATIC CHAIN Statement syntax, information and example SAP source code



Return to Statement index



... meth1( ... )- meth2( ... )- ... - Method Chaining

ABAP Syntax ... {
static_meth ( ... )- meth1( ... )- meth2( ... )- ...- meth( ... ) }
| { static_meth ( ... )- meth1( ... )- meth2( ... )- ...- attr } ...

ABAP_ALTERNATIVES:
1 static_meth( ... )->meth1( ... )->meth2( ... )->...->meth( ... )

2 static_meth( ... )- meth1( ... )- meth2( ... )- ...- attr

What does it do? 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 .

ABAP_ALTERNATIVE_1 static_meth( ... )->meth1( ... )->meth2( ... )- ...- meth( ... )

What does it do? 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.
Latest 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 operator NEW or CAST for oref not only in a functional call, but also in standalone statements.
Example ABAP Coding 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 ).

ABAP_ALTERNATIVE_2 static_meth( ... )->meth1( ... )->meth2( ... )- ...- attr

What does it do? 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.
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 ABAP Coding See Method Chaining .
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




CALL_METHOD_STATIC
CALL_METHOD_STATIC_SHORT




comments powered by Disqus