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

How can I call implemented method ?

Former Member
0 Likes
770

I have an interface ZIF_TEST and define a class ZCL_TEST and implement its method TEST.

I created a class ZCL_DO and implement the interface ZIF_TEST.

I wanna ZCL_DO could use the method TEST implemented in ZCL_TEST but how?

I see the SAP standard class can do this...

Edited by: kkktank on Jul 7, 2011 1:08 PM

I have an interface ZIF_TEST and define a class ZCL_TEST and implement its method TEST.

I created a class ZCL_DO and implement the interface ZIF_TEST.

I wanna ZCL_DO could use the method TEST implemented in ZCL_TEST but how?

I see the SAP standard class can do this...

Edited by: kkktank on Jul 7, 2011 1:08 PM

5 REPLIES 5
Read only

Kiran_Valluru
Active Contributor
0 Likes
719

Hi.,

Make ZCL_DO as a sub class of ZCL_TEST so that you can use its methods..

Thanks & Regards,

Kiran

Read only

Clemenss
Active Contributor
0 Likes
719

Hi kk,

it requires that TEST is a public method. If it is static method, ZCL_DO=>TEST calls the method, if it is instance method, lo_DO->TEST calls the method.

What is your code (formatted as code)?

Regards,

Clemens

Read only

Former Member
0 Likes
719

Hello,

you can also call it, if the method is private or protected using friendship relationship. If class ZCL_DO will be a friend of ZCL_TEST, it may use it's methods as they were public.

The problem is, that you cannot restrict the friendship to only one method, but if this doesn't contradict your requirements, there is your solution.


CLASS zcl_do DEFINITION.
....
ENDCLASS.

CLASS zcl_test DEFINITION FRIENDS zcl_do.
....
ENDCLASS.

CLASS zcl_do IMPLEMENTATION.
 METHOD do_someting.
  DATA lo_ref   TYPE REF TO zcl_test.
  CREATE OBEJCT lo_ref.
  CALL METHOD lo_ref->zif_test~test.
     
   ENDMETHOD.
ENDCLASS.

Read only

Former Member
0 Likes
719

use upcasting same logic as with classes. but you will get implementation specific to child class while u are only interested in the ZCL_TEST class, okay then make the other class a child class of this Test class nad then do not redefine so that when u call instance of the child class ->interface~method u will executr the implementation inside the TEST class.

Read only

Former Member
0 Likes
719

thanks piotrzym.

It solved my problem.