Application Development and Automation 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: 
Read only

abap oo uing object indide method

Former Member
0 Likes
555

Hi,

Do you know how to call a method of some object inside method of different object which takes reference to this first object.

class c1 definition.

public section.

methods m1.

endclass.

class c1 implementation.

method m1.

write 'method m1'.

endmethod.

endclass.

class c2 definition.

public section.

methods m2

importing p2 type ref to c1.

endclass.

class c2 implementation.

method m2.

p2->m1.

endmethod.

endclass.

Is it possible. Because I'm getting an error.

Regards,

Wojciech

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
532

It is possible:

YOu did a small mistake:

class c1 definition.

public section.

methods m1.

endclass.

class c1 implementation.

method m1.

write 'method m1'.

endmethod.

endclass.

class c2 definition.

public section.

methods m2

importing p2 type ref to c1.

endclass.

class c2 implementation.

method m2.

<b>call method</b> p2->m1.

endmethod.

endclass.

make the highlighted change.

Regards,

ravi

3 REPLIES 3
Read only

Former Member
0 Likes
532

Its possible if you declare the method as public.

Only public methods can be called in other objects

class c2 implementation.

method m2.

p2->m1.

endmethod.

endclass.

It shouldnt be giving error.

can you give the code where you are calling the c2->m2 ?

Read only

Former Member
0 Likes
533

It is possible:

YOu did a small mistake:

class c1 definition.

public section.

methods m1.

endclass.

class c1 implementation.

method m1.

write 'method m1'.

endmethod.

endclass.

class c2 definition.

public section.

methods m2

importing p2 type ref to c1.

endclass.

class c2 implementation.

method m2.

<b>call method</b> p2->m1.

endmethod.

endclass.

make the highlighted change.

Regards,

ravi

Read only

0 Likes
532

Thanks for your prompt answer

Regards,

wojciech