abap how to also get description of attributes, method and class? When the descriptions…
- User
abap how to also get description of attributes, method and class?
When the descriptions are stored like this in eclipse: "! PlantUML diagram "! @parameter it_diagram | PlantUML diagram source code METHODS constructor IMPORTING it_diagram TYPE string_t.
Current code:
DATA(o_class) = NEW zbc_uml_scanner( ).
DATA(o_class_desc) = CAST cl_abap_classdescr( cl_abap_typedescr=>describe_by_object_ref( o_class ) ). cl_demo_output=>write_data( o_class_desc->kind ).
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
You can retrieve the descriptions (documentation) of classes, methods, and attributes in ABAP by using the function module
SEO_DOCU_GET. This function module allows you to access the documentation that you've written in your code comments (starting with"!) for classes, methods, and their components. Here's how you can do it:For Class Documentation:
DATA: ls_seoclskey TYPE seoclskey, " Class Key ls_docu TYPE seodocu. ls_seoclskey-clsname = 'ZBC_UML_SCANNER'. " Replace with your class name CALL FUNCTION 'SEO_DOCU_GET' EXPORTING seoclskey = ls_seoclskey request = 'C' " 'C' for Class documentation IMPORTING seodocu = ls_docu EXCEPTIONS not_found = 1 others = 2. IF sy-subrc = 0. " Class documentation is in ls_docu-docutext cl_demo_output=>write_text( ls_docu-docutext ). ELSE. " Handle the case where documentation is not found ENDIF.For Method Documentation:
DATA: ls_seocmpkey TYPE seocmpkey, " Component Key ls_docu TYPE seodocu. ls_seocmpkey-clsname = 'ZBC_UML_SCANNER'. " Replace with your class name ls_seocmpkey-cmpname = 'CONSTRUCTOR'. " Replace with your method name ls_seocmpkey-cmptype = 'M'. " 'M' for Method CALL FUNCTION 'SEO_DOCU_GET' EXPORTING seocmpkey = ls_seocmpkey request = 'M' " 'M' for Method documentation IMPORTING seodocu = ls_docu EXCEPTIONS not_found = 1 others = 2. IF sy-subrc = 0. " Method documentation is in ls_docu-docutext cl_demo_output=>write_text( ls_docu-docutext ). ELSE. " Handle the case where documentation is not found ENDIF.For Attribute Documentation:
DATA: ls_seocmpkey TYPE seocmpkey, " Component Key ls_docu TYPE seodocu. ls_seocmpkey-clsname = 'ZBC_UML_SCANNER'. " Replace with your class name ls_seocmpkey-cmpname = 'YOUR_ATTRIBUTE'. " Replace with your attribute name ls_seocmpkey-cmptype = 'A'. " 'A' for Attribute CALL FUNCTION 'SEO_DOCU_GET' EXPORTING seocmpkey = ls_seocmpkey request = 'A' " 'A' for Attribute documentation IMPORTING seodocu = ls_docu EXCEPTIONS not_found = 1 others = 2. IF sy-subrc = 0. " Attribute documentation is in ls_docu-docutext cl_demo_output=>write_text( ls_docu-docutext ). ELSE. " Handle the case where documentation is not found ENDIF.Explanation:
-
SEO_DOCU_GETFunction Module:- This function module retrieves the documentation for classes (
'C'), methods ('M'), and attributes ('A'). - The
seoclskeyorseocmpkeyparameter specifies the class or component (method/attribute) for which you want to get the documentation. - The
requestparameter indicates the type of documentation you want to retrieve ('C','M', or'A').
- This function module retrieves the documentation for classes (
-
Parameters:
- For Class Documentation:
seoclskey: Structure containing the class name (clsname).request: Set to'C'to indicate class documentation.
- For Method Documentation:
seocmpkey: Structure containing the class name (clsname), component name (cmpname), and component type (cmptypeset to'M').request: Set to'M'to indicate method documentation.
- For Attribute Documentation:
seocmpkey: Structure containing the class name (clsname), component name (cmpname), and component type (cmptypeset to'A').request: Set to'A'to indicate attribute documentation.
- For Class Documentation:
-
Handling the Result:
- If
sy-subrcis0, the documentation is successfully retrieved and is available inls_docu-docutext. - You can then output or process this documentation as needed.
- If
Note: The documentation retrieved includes the comments you've added in your code using the ABAP Doc syntax (comments starting with
"!). Ensure that your code includes these comments for the documentation to be accessible.Example Usage in Your Code:
Here's how you might integrate this into your existing code to display method names along with their documentation:
DATA(o_class) = NEW zbc_uml_scanner( ). DATA(o_class_desc) = CAST cl_abap_classdescr( cl_abap_typedescr=>describe_by_object_ref( o_class ) ). LOOP AT o_class_desc->methods ASSIGNING FIELD-SYMBOL(<method>). " Get method documentation DATA: ls_seocmpkey TYPE seocmpkey, ls_docu TYPE seodocu. ls_seocmpkey-clsname = 'ZBC_UML_SCANNER'. " Replace with your class name ls_seocmpkey-cmpname = <method>-name. ls_seocmpkey-cmptype = 'M'. CALL FUNCTION 'SEO_DOCU_GET' EXPORTING seocmpkey = ls_seocmpkey request = 'M' IMPORTING seodocu = ls_docu EXCEPTIONS not_found = 1 others = 2. cl_demo_output=>write_text( |Method: { <method>-name }| ). IF sy-subrc = 0. cl_demo_output=>write_text( |Documentation: { ls_docu-docutext }| ). ELSE. cl_demo_output=>write_text( 'No documentation found.' ). ENDIF. ENDLOOP. cl_demo_output=>display( ).This code loops through the methods of your class, retrieves each method's documentation, and outputs it.
Summary:
- Use
SEO_DOCU_GETto retrieve documentation for classes, methods, and attributes. - Set the appropriate keys (
seoclskeyfor classes,seocmpkeyfor components) and request types. - Handle the output or absence of documentation as needed in your application.
-