LOOP AT o_class_desc->methods ASSIGNING FIELD-SYMBOL().
LOOP AT -parameters ASSIGNING FIELD-SYMBOL().
cl_demo_output=>write_data( -name ).
ENDLOOP.
cl_demo_output=>write( -name ).
ENDLOOP.
cl_demo_output=>display( ).
Assistant
In ABAP, when you use cl_abap_classdescr to retrieve class descriptions, you get structural information about the class, such as the names of methods and attributes. However, this class does not provide access to the documentation texts (descriptions) of the class, its methods, or attributes.
To retrieve the descriptions or documentation associated with a class, methods, or attributes, you need to access the ABAP Repository Information System. You can achieve this by using specific function modules or classes designed for this purpose.
Here's how you can get the descriptions of attributes, methods, and the class itself:
1. Retrieve Class Documentation
You can use the function module RS_DOCU_LOAD to load the documentation text for a given class. Here's how:
abap
DATA: lv_class_docu TYPE string.
CALL FUNCTION 'RS_DOCU_LOAD'
EXPORTING
type = 'CL' " Object type 'CL' for class
name = 'ZBC_UML_SCANNER' " Your class name
IMPORTING
text = lv_class_docu
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
cl_demo_output=>write_text( lv_class_docu ).
ELSE.
cl_demo_output=>write_text( 'Class documentation not found.' ).
ENDIF.
2. Retrieve Method Descriptions
To get the descriptions of the methods, you can use the function module SEO_CLASS_READ_COMPLETE to read the complete class information, including method descriptions:
abap
DATA: ls_clskey TYPE seoclskey,
lt_clsdescr TYPE seoclsdescr.
ls_clskey-name = 'ZBC_UML_SCANNER'. " Your class name
CALL FUNCTION 'SEO_CLASS_READ_COMPLETE'
EXPORTING
clskey = ls_clskey
IMPORTING
clsdescr = lt_clsdescr
EXCEPTIONS
class_not_existing = 1
OTHERS = 2.
IF sy-subrc = 0.
DATA: ls_method TYPE seometpublic,
lt_methods TYPE seometpublic_tab.
lt_methods = lt_clsdescr-mep. " Public methods
LOOP AT lt_methods INTO ls_method.
cl_demo_output=>write( |Method Name: { ls_method-cmpname }| ).
cl_demo_output=>write_text( |Description: { ls_method-descript }| ).
ENDLOOP.
ELSE.
cl_demo_output=>write_text( 'Class not found.' ).
ENDIF.
3. Retrieve Attribute Descriptions
Similarly, you can retrieve attribute descriptions using the data obtained from SEO_CLASS_READ_COMPLETE:
abap
DATA: ls_attribute TYPE seoattpublic,
lt_attributes TYPE seoattpublic_tab.
lt_attributes = lt_clsdescr-atp. " Public attributes
LOOP AT lt_attributes INTO ls_attribute.
cl_demo_output=>write( |Attribute Name: { ls_attribute-compname }| ).
cl_demo_output=>write_text( |Description: { ls_attribute-descript }| ).
ENDLOOP.
4. Display the Output
Finally, don't forget to display the collected output:
abap
cl_demo_output=>display( ).
Explanation:
RS_DOCU_LOAD Function Module: This function module is used to load documentation texts for various repository objects like classes (type = 'CL'), programs, function modules, etc.
SEO_CLASS_READ_COMPLETE Function Module: This function reads the complete metadata of a class, including descriptions of methods (mep for public methods, mei for instance methods, etc.) and attributes (atp for public attributes).
Accessing Method and Attribute Descriptions: The descriptions are available in the descript field of the method and attribute structures returned by SEO_CLASS_READ_COMPLETE.
Notes:
Authorization: Ensure that the user executing this code has the necessary authorization to access class information in the ABAP Repository.
Class Names: Replace 'ZBC_UML_SCANNER' with the actual name of your class.
Additional Information: If you need to access private or protected methods and attributes, you can retrieve them from lt_clsdescr-mep (public methods), lt_clsdescr-mei (instance methods), lt_clsdescr-atp (public attributes), lt_clsdescr-ati (instance attributes), etc.
By using these function modules, you can programmatically access not only the structural information of classes, methods, and attributes but also their associated descriptions or documentation texts.