In one of my earlier blogs ALV Fast Display Class I had explained how the SAP standard document class
cl_dd_document
can be used along with the ALV class
cl_gui_alv_grid
for displaying ALV headers and footers in any report.In this blog I would like to go a little further and explain how the document class can be used to display the contents of any internal table dynamically.
Part 1 : Class ZCL_DOCUMENT_DISPLAY
Methods
METHOD constructor.
DATA :
wa_buttons TYPE stb_button."Work area for custom buttons
*Add the button to display document to the ALV Toolbar
CLEAR : wa_buttons,gt_buttons.
MOVE 3 TO wa_buttons-butn_type.
APPEND wa_buttons TO gt_buttons.
CLEAR wa_buttons.
MOVE 'DOC' TO wa_buttons-function.
MOVE icon_document TO wa_buttons-icon.
MOVE 'Document View' TO wa_buttons-quickinfo.
MOVE ' ' TO wa_buttons-disabled.
APPEND wa_buttons TO gt_buttons.
*Set the handler for toolbar
SET HANDLER me->handle_toolbar FOR i_alv.
*Set the handle for user command
SET HANDLER me->handle_user_command FOR i_alv.
*Assign the output table and alv object to private attributes
GET REFERENCE OF it_outtab INTO mt_outtab.
ref_alv ?= i_alv.
at_doc_title = doc_title.
at_width = width.
at_height = height.
at_top = top.
at_left = left.
at_caption = caption.
ENDMETHOD.
METHOD handle_toolbar.
DATA :
lwa_buttons TYPE stb_button,
wa_toolbar TYPE stb_button.
LOOP AT gt_buttons INTO lwa_buttons.
MOVE-CORRESPONDING lwa_buttons TO wa_toolbar.
APPEND wa_toolbar TO e_object->mt_toolbar.
CLEAR wa_toolbar.
ENDLOOP.
ENDMETHOD.
METHOD handle_user_command.
IF e_ucomm = 'DOC'.
*Display the document
CALL METHOD me->display_document.
ENDIF.
ENDMETHOD.
method HANDLE_CLOSE.
call method sender->free.
endmethod.
METHOD display_document.
DATA :
lt_fieldcatalog TYPE lvc_t_fcat,
lwa_fieldcatalog TYPE lvc_s_fcat,
ref_dd TYPE REF TO cl_dd_document,
ref_dd_table TYPE REF TO cl_dd_table_element,
ref_column TYPE REF TO cl_dd_area,
ref_form TYPE REF TO cl_dd_form_area,
v_heading TYPE sdydo_text_element,
v_text TYPE sdydo_text_element,
v_column_count TYPE i,
ref_html TYPE REF TO cl_gui_html_viewer,
ref_doc_container TYPE REF TO cl_gui_container.
FIELD-SYMBOLS: html_control = ref_html.
CALL METHOD ref_dd->display_document
EXPORTING
reuse_control = 'X'
parent = ref_dialog
EXCEPTIONS
html_display_error = 1.
ENDIF.
ENDMETHOD.
Part 2: Test Program
Note :
In this example I have merged the document class with the ALV class to display the result.But it is also possible to use the document class independantly within a separate custom container.