Vererbungsübersicht
Folgendes kleine Programm zeigt die Vererbungshierarchien von Klassen auf. Die Root- oder Super-Klasse wird auf der obersten Ebene angezeigt. Darunter werden die von ihr erbenden Klassen aufgelistet. Mit einem Doppelklick auf eine Klasse wird in den Class Builder (SE24) verzweigt.
Beschreibung
Die Vererbungsübersicht kann man sich normalerweise auch in der SE80 anschauen. Hier ist jedoch immer ein “Zwischenschritt” über den Punkt “Superklassen” oder “Subklassen” notwendig. Dieses Programm liefert eine direkt Übersicht:
Übersicht über alle Unterklassen von “CL_CI_TEST_ROOT” |
Features
Kundeneigene Klassen (Z- und /-Namensraum) werden hervor gehoben.
Doppelklick auf eine Klasse verzweigt in den Class Builder (Transaktion SE24).
Interessante Klassen
Folgende Klassen sind interessant, da sie eine große “Erbengemeinschaft” haben:
- IF_CI_TEST (Interface von Code Inspector Prüfungen)
- CL_GUI_OBJECT
- CL_GUI_CONTROL
- CL_GUI_CONTAINER
- CL_ABAP_TYPEDESCR
- Ausnahmeklassen
- CX_STATIC_CHECK
- CX_DYNAMIC_CHECK
- CX_NO_CHECK
Coding
*&---------------------------------------------------------------------*
*& Report Z_INHERITING_CLASSES
*&---------------------------------------------------------------------*
* displays all inheriting classes of a super class in simple tree.
* double click on class calls SE24 for this class in display mode.
*----------------------------------------------------------------------*
REPORT Z_INHERITING_CLASSES.
CLASS lcl_application DEFINITION DEFERRED.
DATA go_application TYPE REF TO lcl_application.
DATA gt_classes TYPE STANDARD TABLE OF seoclsname.
DATA gt_metarel TYPE STANDARD TABLE OF seometarel.
DATA gs_metarel TYPE seometarel.
DATA go_tree TYPE REF TO cl_gui_simple_tree.
DATA gt_nodes TYPE STANDARD TABLE OF mtreesnode.
DATA gs_node TYPE mtreesnode.
DATA gt_expand_nodes TYPE STANDARD TABLE OF lvc_nkey.
DATA gv_top_node TYPE lvc_nkey.
DATA gv_level TYPE i.
*** SELECTION SCREEN ***
*==> Super class name (root)
PARAMETERS p_class TYPE seoclsname DEFAULT 'IF_CI_TEST'.
*==> Expand up to this level
PARAMETERS p_level TYPE i DEFAULT 3.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_class.
CALL FUNCTION 'F4_DD_ALLTYPES'
EXPORTING
object = p_class
suppress_selection = 'X'
display_only = ' '
only_types_for_clifs = 'X'
IMPORTING
RESULT = p_class.
*----------------------------------------------------------------------*
* CLASS LCL_APPLICATION DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_application DEFINITION.
PUBLIC SECTION.
METHODS:
handle_node_double_click
FOR EVENT node_double_click
OF cl_gui_simple_tree
IMPORTING node_key.
ENDCLASS. "LCL_APPLICATION DEFINITION
*----------------------------------------------------------------------*
* CLASS LCL_APPLICATION IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_application IMPLEMENTATION.
METHOD handle_node_double_click. DATA lv_classname TYPE seoclsname. READ TABLE gt_classes INTO lv_classname INDEX node_key.
CALL FUNCTION 'RS_TOOL_ACCESS' EXPORTING operation = 'SHOW' object_name = lv_classname object_type = 'CLAS'.
ENDMETHOD. "HANDLE_NODE_DOUBLE_CLICK
ENDCLASS. "LCL_APPLICATION IMPLEMENTATION
START-OF-SELECTION.
PERFORM do_read USING p_class.
CHECK gt_metarel IS NOT INITIAL. cl_abap_list_layout=>suppress_toolbar( ).
WRITE 1. INSERT p_class INTO gt_classes INDEX 1. PERFORM init_tree. PERFORM add_node USING p_class space. PERFORM display_tree.
*&---------------------------------------------------------------------*
*& Form do_read
*&---------------------------------------------------------------------*
FORM do_read USING iv_classname TYPE seoclsname.
DATA lt_metarel TYPE STANDARD TABLE OF seometarel.
*** Select all inheriting classes
SELECT * FROM seometarel INTO TABLE lt_metarel
WHERE refclsname = iv_classname.
LOOP AT lt_metarel INTO gs_metarel. "collect class for having a node name later on (TABIX) COLLECT gs_metarel-clsname INTO gt_classes. "recursive call for class PERFORM do_read USING gs_metarel-clsname. ENDLOOP.
APPEND LINES OF lt_metarel TO gt_metarel.
ENDFORM. "do_read
*&---------------------------------------------------------------------*
*& Form init_tree
*&---------------------------------------------------------------------*
FORM init_tree.
DATA events TYPE cntl_simple_events. DATA event TYPE cntl_simple_event.
"Create simple tree
CREATE OBJECT go_tree
EXPORTING
parent = cl_gui_container=>screen0
node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single.
"Create application handler
CREATE OBJECT go_application.
"define event "node double_click"
event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
event-appl_event = 'X'. " process PAI if event occurs
APPEND event TO events.
"register event "Double click"
go_tree->set_registered_events( events ).
"assign event handlers in the application class
SET HANDLER go_application->handle_node_double_click FOR go_tree.
ENDFORM. "init_tree
*&---------------------------------------------------------------------*
*& Form add_node
*&---------------------------------------------------------------------*
FORM add_node
USING
iv_classname TYPE seoclsname
iv_refclass TYPE seoclsname.
ADD 1 TO gv_level. CLEAR gs_node.
"get key for node
READ TABLE gt_classes TRANSPORTING NO FIELDS WITH KEY iv_classname.
gs_node-node_key = sy-tabix.
IF iv_refclass IS INITIAL.
CLEAR gs_node-relatkey.
CLEAR gs_node-relatship.
ELSE.
"get key of related class
READ TABLE gt_classes TRANSPORTING NO FIELDS WITH KEY iv_refclass.
gs_node-relatkey = sy-tabix.
gs_node-relatship = cl_gui_simple_tree=>relat_last_child.
ENDIF.
IF gv_level <= p_level.
*** Expand this level
IF gt_expand_nodes IS INITIAL.
*** remember this node for setting the top node
gv_top_node = gs_node-node_key.
ENDIF.
*** remember this node for later expansion
APPEND gs_node-node_key TO gt_expand_nodes.
ENDIF.
*** add node "class"
gs_node-isfolder = 'X'. " a folder.
gs_node-text = iv_classname.
CASE iv_classname(1).
WHEN 'Z'.
*** highlight customer classes (Z)
gs_node-style = cl_gui_simple_tree=>style_emphasized_negative.
WHEN '/'.
*** highlight customer classes (/xyz/)
gs_node-style = cl_gui_simple_tree=>style_emphasized_positive.
ENDCASE.
APPEND gs_node TO gt_nodes.
LOOP AT gt_metarel INTO gs_metarel WHERE refclsname = iv_classname. PERFORM add_node USING gs_metarel-clsname gs_metarel-refclsname. ENDLOOP.
SUBTRACT 1 FROM gv_level.
ENDFORM. “add_node
*&---------------------------------------------------------------------*
*& Form display_tree
*&---------------------------------------------------------------------*
FORM display_tree.
"add nodes
go_tree->add_nodes(
table_structure_name = 'MTREESNODE'
node_table = gt_nodes ).
"Expand up to desired level
go_tree->expand_nodes(
EXPORTING
node_key_table = gt_expand_nodes
EXCEPTIONS
OTHERS = 5).
"set top node
go_tree->set_top_node( node_key = gv_top_node ).
ENDFORM. "display_tree
- Interview mit Björn Schulz (Software-Heroes.com) - 3. September 2024
- Daten aus ALV ermitteln - 3. September 2024
- So lange es den SAPGUI noch gibt… - 27. Juni 2024