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: 

Find classes implementing an interface

Former Member
0 Kudos

Does anyone know how to code a check to find which ABAP classes implement a given interface?

Thaks,

Jim

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

In ABAP the general convention for classes and interfaces is like this...

if the interface is IF_BSP_SERVER the implemented class is CL_BSP_SERVER.

So for Interface IF_XXXXX check for the implemented class as CL_XXXXX.

Regards,

Azaz Ali.

9 REPLIES 9

Former Member
0 Kudos

Hi,

In ABAP the general convention for classes and interfaces is like this...

if the interface is IF_BSP_SERVER the implemented class is CL_BSP_SERVER.

So for Interface IF_XXXXX check for the implemented class as CL_XXXXX.

Regards,

Azaz Ali.

0 Kudos

Thanks Azaz, but I'm looking for something I can use in a program to find all classes that implement the interface. I thought there might be a method of CL_ABAPINTFDESCR or something where I could just request the list of implementing classes. There must be such a method or function out there, since you can do a where-used list from the ABAP Workbench on an interface.

Jim

0 Kudos

I've just been messing with the CL_ABAPINTFDESCR class. I was looking at the method APPLIES_TO_CLASS. I had my program get all of the classes and I looped at my class table running this method over each class. I could not get the program to tell me the classes where the interface is used successfully.

I would suggest exploring this class a little further.

Regards,

Rich Heilman

0 Kudos

Hi Rich,

I was thinking I might do this, but was just worried about the large number of classes to process. My only idea so far is to select all classes found in table SEOCLASS and check every one (69,000 in the system I'm looking at right now). I tried to debug how the workbench does the where-used list for interfaces, but missed it somehow during a long debugger session!

Jim

0 Kudos

Well, here is what I have so far.



report zrich_0001 .

data: l_dref  type ref to cl_abap_typedescr.
data: l_ifref  type ref to cl_abap_intfdescr.

data: iclass type table of seoclass with header line.

data: answer type abap_bool.

select-options: s_class for iclass-clsname.

constants: query_intf type seoclsname value 'IF_DRAGDROP'.

call method cl_abap_intfdescr=>describe_by_name
  exporting
    p_name         = query_intf
  receiving
      p_descr_ref = l_dref
  exceptions
    type_not_found = 1
    others         = 2.
if sy-subrc <> 0.
  exit.
endif.

l_ifref ?= l_dref.

select * into table iclass
          from seoclass
                  where clsname in s_class.

loop at iclass.

  call method l_ifref->applies_to_class
    exporting
      p_classname = iclass-clsname
    receiving
      p_bool      = answer.

  if answer = 'X'.
    write:/ iclass-clsname, answer.
  endif.

endloop.


I hate when you miss something after a long debug session.

Regards,

Rich Heilman

0 Kudos

Hi Rich,

Thanks for this, but what I really need is something that doesn't require a starting point like the select-options.

Jim

0 Kudos

I understand, this was just for a proof-of-concept.

Regards,

Rich Heilman

Former Member
0 Kudos

Hello Jim,

what you are actually looking for might be function module 'SEO_INTERFACE_IMPLEM_GET_ALL' (from package SEOK "ABAP Object Class Builder Services"). It takes the name of an interface as input and returns the class names of all implementing classes.

However, there is one caveat, it seems to work for DDIC interfaces only. So you are not able to use interfaces defined in your local programm.

Regards,

Daniel

0 Kudos

Pay attention, that this will only return the direct implementations of an interface!