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

Calling a Method of Interface by using Object

bpawanchand
Active Contributor
0 Likes
623

Hi All,

I want to use a method of a class which will be IF_ABC_XYZ~ <amethod> ( ). how can i use this method in my program , I have the instance of the class which have the above mentioned method?

Thanks & Regards

Pavan

1 ACCEPTED SOLUTION
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
598

Hi,

If you have the instance of the class then you need to use

CALL METHOD instance->if_interface~method_name (

EXPORTING

IMPORTING ).

Regards,

Sesh

4 REPLIES 4
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
599

Hi,

If you have the instance of the class then you need to use

CALL METHOD instance->if_interface~method_name (

EXPORTING

IMPORTING ).

Regards,

Sesh

Read only

0 Likes
598

thanks

here the case is like this

data :

lv_type TYPE REF TO IF_some xyz.

now by using a static class method i am able to get the return type equal to lv_type i.e

CALL METHOD cl_someclassname=> amethod ( )

IMPORTING

type = lv_type.

now when i debug and see lv_type is having a class name inside it. I want to use a method of this class.

How can I call the method which Iam able to see in the lv_type when i debug.

Read only

0 Likes
598

Hello

You need to cast your interface object to the corresponding class object:

data :
lv_type TYPE REF TO IF_some xyz,
lo_class TYPE REF TO cl_xyz_class.  " implements interface IF_SOME_XYZ

now by using a static class method i am able to get the return type equal to lv_type i.e

CALL METHOD cl_someclassname=> amethod ( )
IMPORTING
type = lv_type.

lo_class ?= lv_type.
CALL METHOD lo_class->name_of_method.

Regards

Uwe

Read only

0 Likes
598

Thanks I already resolved the issue, as you said in the exmaple, I also approched the same way , Thanks