Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

ray_mannion
Participant
0 Kudos
186

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?

1 ACCEPTED SOLUTION

former_member183045
Contributor
0 Kudos
82

Hi!

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

1 REPLY 1

former_member183045
Contributor
0 Kudos
83

Hi!

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