ABAP – Get all sub-classes of a super-class

If you ever need to get a super class or all (global) sub-classes of a given ABAP (global) class, you can use the following approach
Using the following code you can get all details about a global class you need during runtime

DATA:
  go_instance   TYPE REF TO cl_oo_class.
CONSTANTS:
  co_class_name TYPE seoclsname VALUE 'CL_OO_CLASS'.

go_instance ?= cl_oo_class=>get_instance( co_class_name ).

DATA(lt_subclasses) = go_instance->get_subclasses( ).
LOOP AT lt_subclasses ASSIGNING FIELD-SYMBOL(<ls_subclass>).
  WRITE:/ <ls_subclass>-refclsname, AT 35 <ls_subclass>-clsname.
ENDLOOP.

Program result

Using this awesome CL_OO_CLASS class you can get also much more detailed info about a specific class:

Methods of CL_OO_CLASS

Leave a Reply