‎2007 May 05 12:25 AM
Dear all,
Is there a way of performing introspection on classes or function modules in ABAP? For example, I would need a piece of code that gets the attributes and their types of a class that was defined in the class builder.
Thanks,
Philon
‎2007 May 05 12:36 AM
Sure, check this out.
REPORT zrich_0003
LINE-SIZE 200.
DATA: l_dref TYPE REF TO cl_abap_typedescr.
DATA: l_clref TYPE REF TO cl_abap_classdescr.
DATA: x_attributes TYPE abap_attrdescr.
CONSTANTS: query_class TYPE seoclsname
VALUE 'CL_GUI_ALV_GRID'.
* check if query_class exists in the current system
CALL METHOD cl_abap_classdescr=>describe_by_name
EXPORTING
p_name = query_class
RECEIVING
p_descr_ref = l_dref
EXCEPTIONS
type_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
l_clref ?= l_dref.
LOOP AT l_clref->attributes INTO x_attributes.
WRITE:/ x_attributes-name,
x_attributes-type_kind,
x_attributes-length,
x_attributes-visibility.
ENDLOOP.
Regards,
RIch Heilman
‎2007 May 05 12:36 AM
Sure, check this out.
REPORT zrich_0003
LINE-SIZE 200.
DATA: l_dref TYPE REF TO cl_abap_typedescr.
DATA: l_clref TYPE REF TO cl_abap_classdescr.
DATA: x_attributes TYPE abap_attrdescr.
CONSTANTS: query_class TYPE seoclsname
VALUE 'CL_GUI_ALV_GRID'.
* check if query_class exists in the current system
CALL METHOD cl_abap_classdescr=>describe_by_name
EXPORTING
p_name = query_class
RECEIVING
p_descr_ref = l_dref
EXCEPTIONS
type_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
l_clref ?= l_dref.
LOOP AT l_clref->attributes INTO x_attributes.
WRITE:/ x_attributes-name,
x_attributes-type_kind,
x_attributes-length,
x_attributes-visibility.
ENDLOOP.
Regards,
RIch Heilman