[ABAP] Infos zu ABAP-Objekten lesen

Variante 1 (CL_OO_CLASS)

* Pakete:
*   SEOE
*   SEDI

* Klassen Introspektion
PARAMETERS: p_cls TYPE seoclsname DEFAULT 'CL_GUI_ALV_GRID'.

TRY.
    DATA(o_cls) = NEW cl_oo_class( clsname                   = p_cls
                                   with_inherited_components = abap_true
                                   with_interface_components = abap_true
                                 ).

    WRITE: / 'Public:', o_cls->is_public( ).
    WRITE: / 'Final:', o_cls->is_final( ).
    WRITE: / 'Abstract:', o_cls->is_abstract( ).

    WRITE: / 'Super:', o_cls->get_superclass( ).

    LOOP AT o_cls->get_methods( ) ASSIGNING FIELD-SYMBOL(<m>).
      WRITE: / 'Method:', <m>-cmpname.
    ENDLOOP.

    LOOP AT o_cls->get_events( ) ASSIGNING FIELD-SYMBOL(<e>).
      WRITE: / 'Event:', <e>-cmpname.
    ENDLOOP.
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

Variante 2 (CL_OO_OBJECT)

* Objektinformationen
PARAMETERS: p_cls TYPE seoclsname DEFAULT 'CL_GUI_ALV_GRID'.

TRY.
    DATA(o_cls) = cl_oo_object=>get_instance( p_cls ).

    LOOP AT o_cls->get_methods( ) ASSIGNING FIELD-SYMBOL(<m>).
      WRITE: / 'Method:', <m>-cmpname.
    ENDLOOP.

    LOOP AT o_cls->get_events( ) ASSIGNING FIELD-SYMBOL(<e>).
      WRITE: / 'Event:', <e>-cmpname.
    ENDLOOP.

  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

Variante 3 (CL_OO_CLASSNAME_SERVICE)

* Service für Includenamen im Klassenumfeld
PARAMETERS: p_cls TYPE seoclsname DEFAULT 'CL_GUI_ALV_GRID'.

TRY.
    LOOP AT cl_oo_classname_service=>get_all_class_includes( p_cls ) ASSIGNING FIELD-SYMBOL(<ci>).
      WRITE: / 'Include:', <ci>.
    ENDLOOP.

  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

Kommentare sind geschlossen.