Skip to Content
author's profile photo Former Member
Former Member

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

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?

Add comment
10|10000 characters needed characters exceeded

1 Answer

  • Best Answer
    Posted on 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

    Add comment
    10|10000 characters needed characters exceeded