Skip to Content

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

image

METHOD constructor.

  DATA :

  wa_buttons TYPE stb_button.”Work area for custom buttons

*Add the button to display document to the ALV Toolbar

  • append a separator to normal toolbar

  CLEAR : wa_buttons,gt_buttons.

  MOVE 3 TO wa_buttons-butn_type.

  APPEND wa_buttons TO gt_buttons.

  •   append create assets button

  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.

  • Display document

    CALL METHOD ref_dd->display_document

      EXPORTING

        reuse_control      = ‘X’

        parent             = ref_dialog

      EXCEPTIONS

        html_display_error = 1.

  ENDIF.

ENDMETHOD.

Part 2: Test Program

image

image

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.

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Raju Venkateswara
    Hi
    Could you please tell me how to get the  “save variant” and choose variant” icons also in the toolbar. Now only the “change variant” icon can be seen in the toolbar.
    (0) 
    1. Ravi Shankar Rajan Post author
      You can do something like this :
      CALL METHOD ob_grid->set_table_for_first_display
          EXPORTING
            it_toolbar_excluding = lt_exclude
            is_layout            = gv_layout
            is_variant           = wa_layout
            i_save               = c_save    “set as “A” : all layouts can be saved
            i_default            = c_default “Set as “X”
          CHANGING
            it_fieldcatalog      = gt_fieldcat
            it_outtab            = gt_asset[].

      use the i_save and i_default properties.

      (0) 

Leave a Reply