Skip to Content

Can I call a method of a object that is an attribute of another object?

Feb 15, 2017 at 09:26 PM


avatar image
Former Member

Is it possible to chain objects together in a call in the following manner?

I have a class cl_msg with a static method construct_bapiret2.

I have an object cl_salesdoc with an attribute mo_msg which is type ref cl_msg.

In the constructor of cl_salesdoc, I:

create object mo_msg.

Sometimes, I can do this:

data: lo_salesdoc type ref to cl_salesdoc.

lo_salesdoc->mo_msg=>construct_bapiret2( )

and sometimes, I get an error.

I feel like I'm not supposed to chain objects together like this?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Andreas Gautsch Feb 15, 2017 at 09:48 PM


A static method is always called on the class itself. So in your case cl_msg=>construct_bapiret2( ) will work but your atttribute mo_msg is an object and therefore a static method can not be used.

Regarding method chaining. You can apply an instance method after a static method but not vice versa.

hope it helps, Andreas

10 |10000 characters needed characters left characters exceeded