create an abap report that collects all the abapdoc comments for classes, attributes and…
- User
create an abap report that collects all the abapdoc comments for classes, attributes and method params
- Assistant
create an abap report that collects all the abapdoc comments for classes, attributes and method params
Certainly! Below is an ABAP report that collects ABAP Doc (abapdoc) comments for classes, their attributes, and method parameters. This report uses Run Time Type Information (RTTI) to introspect classes and retrieve their documentation. It leverages standard ABAP classes such as CL_ABAP_CLASSDESCR to access metadata and associated documentation.
REPORT z_collect_abapdoc_comments.
*---------------------------------------------------------------------*
* Report: Z_COLLECT_ABAPDOC_COMMENTS
* Purpose: Collect ABAP Doc comments for classes, attributes, and method parameters
* Author: Your Name
*---------------------------------------------------------------------*
TABLES: cl02.
TYPE-POOLS: abap.
" Define structures to hold documentation data
TYPES: BEGIN OF ty_param_doc,
class_name TYPE string,
method_name TYPE string,
param_name TYPE string,
param_doc TYPE string,
END OF ty_param_doc.
TYPES: BEGIN OF ty_method_doc,
class_name TYPE string,
method_name TYPE string,
method_doc TYPE string,
END OF ty_method_doc.
TYPES: BEGIN OF ty_attribute_doc,
class_name TYPE string,
attribute_name TYPE string,
attribute_doc TYPE string,
END OF ty_attribute_doc.
TYPES: BEGIN OF ty_class_doc,
class_name TYPE string,
class_doc TYPE string,
END OF ty_class_doc.
" Internal tables to store documentation
DATA: it_class_doc TYPE TABLE OF ty_class_doc,
it_attribute_doc TYPE TABLE OF ty_attribute_doc,
it_method_doc TYPE TABLE OF ty_method_doc,
it_param_doc TYPE TABLE OF ty_param_doc.
" RTTI variables
DATA: lo_descr TYPE REF TO cl_abap_classdescr,
lt_attr_descr TYPE cl_abap_classdescr=>table_of_attributes,
lt_method_descr TYPE cl_abap_classdescr=>table_of_methods,
lt_param_descr TYPE cl_abap_classdescr=>table_of_parameters.
START-OF-SELECTION.
" Retrieve all global classes
SELECT DISTINCT clname
FROM seocls
INTO TABLE @DATA(lt_classes).
LOOP AT lt_classes INTO DATA(ls_class).
" Get class description using RTTI
TRY.
lo_descr = cl_abap_classdescr=>describe_by_name( ls_class-clname ).
" Get class documentation
DATA(lv_class_doc) = lo_descr->get_docu_long_description( ).
" Append to class documentation table
APPEND VALUE ty_class_doc(
class_name = ls_class-clname
class_doc = lv_class_doc
) TO it_class_doc.
" Get attributes documentation
lt_attr_descr = lo_descr->get_attributes( ).
LOOP AT lt_attr_descr INTO DATA(lo_attr).
DATA(lv_attr_doc) = lo_attr->get_docu_long_description( ).
APPEND VALUE ty_attribute_doc(
class_name = ls_class-clname
attribute_name = lo_attr->get_name( )
attribute_doc = lv_attr_doc
) TO it_attribute_doc.
ENDLOOP.
" Get methods documentation
lt_method_descr = lo_descr->get_methods( ).
LOOP AT lt_method_descr INTO DATA(lo_method).
DATA(lv_method_doc) = lo_method->get_docu_long_description( ).
APPEND VALUE ty_method_doc(
class_name = ls_class-clname
method_name = lo_method->get_name( )
method_doc = lv_method_doc
) TO it_method_doc.
" Get parameters documentation for each method
lt_param_descr = lo_method->get_parameters( ).
LOOP AT lt_param_descr INTO DATA(lo_param).
DATA(lv_param_doc) = lo_param->get_docu_long_description( ).
APPEND VALUE ty_param_doc(
class_name = ls_class-clname
method_name = lo_method->get_name( )
param_name = lo_param->get_name( )
param_doc = lv_param_doc
) TO it_param_doc.
ENDLOOP.
ENDLOOP.
CATCH cx_abap_classdescr_error INTO DATA(lx_error).
" Handle exceptions (e.g., class not found)
WRITE: / 'Error describing class:', ls_class-clname, lx_error->get_text( ).
ENDTRY.
ENDLOOP.
" Display the collected documentation using ALV
PERFORM display_results.
*&-----------------------------------------------------------------*
*& Form DISPLAY_RESULTS
*&-----------------------------------------------------------------*
FORM display_results.
DATA: lo_alv TYPE REF TO cl_salv_table.
" Display Class Documentation
IF it_class_doc IS NOT INITIAL.
cl_salv_table=>factory( IMPORTING r_salv_table = lo_alv
CHANGING t_table = it_class_doc ).
lo_alv->set_screen_status(
pfstatus = 'STANDARD'
report = sy-repid
set_functions = abap_false
).
lo_alv->display( ).
ENDIF.
" Display Attribute Documentation
IF it_attribute_doc IS NOT INITIAL.
cl_salv_table=>factory( IMPORTING r_salv_table = lo_alv
CHANGING t_table = it_attribute_doc ).
lo_alv->set_screen_status(
pfstatus = 'STANDARD'
report = sy-repid
set_functions = abap_false
).
lo_alv->display( ).
ENDIF.
" Display Method Documentation
IF it_method_doc IS NOT INITIAL.
cl_salv_table=>factory( IMPORTING r_salv_table = lo_alv
CHANGING t_table = it_method_doc ).
lo_alv->set_screen_status(
pfstatus = 'STANDARD'
report = sy-repid
set_functions = abap_false
).
lo_alv->display( ).
ENDIF.
" Display Parameter Documentation
IF it_param_doc IS NOT INITIAL.
cl_salv_table=>factory( IMPORTING r_salv_table = lo_alv
CHANGING t_table = it_param_doc ).
lo_alv->set_screen_status(
pfstatus = 'STANDARD'
report = sy-repid
set_functions = abap_false
).
lo_alv->display( ).
ENDIF.
ENDFORM.
Type Definitions: Defines various structures to hold documentation for classes, attributes, methods, and parameters.
Data Declarations: Declares internal tables to store the extracted documentation.
Class Retrieval:
SEOCLS table to retrieve all global class names.RTTI and Documentation Extraction:
CL_ABAP_CLASSDESCR) to get the class description.get_docu_long_description.Error Handling:
TRY...CATCH block to handle any exceptions, such as classes that cannot be described.Displaying Results:
CL_SALV_TABLE to display the collected documentation tables.Enhancements:
This ABAP report provides a foundational approach to extracting ABAP Doc comments for classes, attributes, and method parameters. Depending on your specific requirements, you can further enhance and customize the report to fit into your development and documentation workflows.
Not yet included in a published release.