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

query regarding interface

Former Member
0 Likes
782

Hi All,

I have one interface with method XYZ... i am implementing that method with the help of classes ZCL and ZCL1 ...suppose when i am implemetig interface with class ZCL then its output is 123 and with class ZCL1 output is 456 ...when i call the instance of that interface in report with the help of class method get_instance of class cl_exithandler and run the report i am getting output as 123456.... i want to know how both the instances of both classes are called when we call one interface?

Thanks..

6 REPLIES 6
Read only

former_member195383
Active Contributor
0 Likes
753

When you call the method, both the implementations will get called .

To call a single implementation's method you have to use the filter criterias in

the badi, or you have write logic in the respective methods to suite your requirement.

Read only

0 Likes
753

Hi,

I agree with your single implementations method but when you call interface how 2 instances get called at a time for both the classes ??

Read only

0 Likes
753

That is the basic feature of badis . All the implemntations of the badi are called when we call the method the interface using the BADI class(that gets created at the time of defining the BADI)..The order in which these implementations are called, is a lso random .Also in this case the method should be static, other wise you cant call the same using the BADI Class.

Edited by: Rudra Prasanna Mohapatra on Dec 3, 2009 6:52 AM

Read only

former_member195383
Active Contributor
0 Likes
753

I hope you are calling the method using the class of badi and not using any implementations instance.

just like..

CALL METHOD ZCL_EX_BADI_SPFLI=>ZIF_EX_BADI_SPFLI~DESC

EXPORTING

i_fld = i_fld

changING

o_fld = o_fld

in the method desc of all the implementations is called. If you want to call the method of only one implementation

then create an object type ref to the class of that implementation . That will call the method desc only once .

Read only

0 Likes
753

you are right, i am calling the method of particular class as you described but i am calling interface method as below :

data exit_sub type ref to ZIF_EX_S_BADI_ADV.

call method cl_exithandler=>get_instance

changing instance = exit_sub.

CALL METHOD exit_sub->getpernr

EXPORTING zpernr = itab-pernr.

the method of this interface is implemeted by two classes ...so when i call interface like this i get combined output of both the implementations ...so you mean to say that when i call any interface like this all its implementations get called for BAdI ??...if your answer is yes then its ok ...i have one more question regarding the same

If we are not using BAdI and just implementing interface in our report then in that case also all the implementations of the interfaces will get called ??

Read only

0 Likes
753

Hi

When you are not creating BADI and just creating interface and then creating object in your program refering to the

interface , then also all the implemntationa are called. Beacuse the method

call method cl_exithandler=>get_instance

changing instance = exit_sub.

does a similar thing as creating the BADI class.. Check in debugging .

EXIT_SUB contains the BADI class name(even though you have explicitly not created the Badi)

Thats why this case is similar to the one that I have described above and hence all the implemntationa are called.