Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  SAP GUI User Dialogs →  General Dynpros →  Screen and Screen Elements →  Screen Elements - Examples 

Dynpros, HTML Browser

This example demonstrates the encapsulation of the browser controls in a class.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA error_list TYPE cl_abap_browser=>html_table.

    DATA(title) = CONV cl_abap_browser=>title( 'HTML Browser Demo' ).

    SET HANDLER handle_sapevent.

    DATA(pict_tab) = get_pict_tab(
      mime_url = '/SAP/PUBLIC/BC/ABAP/mime_demo/ABAP_Docu_Logo.gif' ).

    DATA(ext_data) =
      VALUE cl_abap_browser=>load_tab( ( name = 'PICT.GIF'
                                        type = 'image'
                                        dref = REF #( pict_tab ) ) ).

    DATA(html_str) =
      '<htm1 lang="EN">' &&
      '<head>' &&
      '<meta name="Demo" content="Test">' &&
      '<style type="text/css">' &&
      'span.h1 {font-size: 150%; color:#000080; ' &&
      'font-weight:bold;}' &&
      '</style>' &&
      '</head>' &&
      '<body>' &&
      '<p><span class="h1">HTML</span></p>' &&
      '<A HREF="http://help.sap.com/">Weblink</A>' &&
      '

<A href=sapevent:"ActionCode">SAPevent</A>' &&
      '

External Picture:' &&
      '

<img src="PICT.GIF" alt="An example figure" >' &&
      '</body>' &&
      '</html>'.

    cl_abap_browser=>show_html(
      EXPORTING
        html_string = html_str
        modal       = modal
        dialog      = COND #( WHEN no_box = abap_false
                                  THEN abap_true )
        title       = title
        buttons     = cl_abap_browser=>navigate_html
        format      = cl_abap_browser=>landscape
        size        = cl_abap_browser=>medium
        data_table  = ext_data
      IMPORTING
         html_errors = error_list ).

    IF modal IS INITIAL AND no_box IS INITIAL.
      MESSAGE 'First call of browser' TYPE 'I'.
    ENDIF.

    IF error_list IS NOT INITIAL.
      LOOP AT error_list ASSIGNING FIELD-SYMBOL(<error>).
        <error> = escape( val    = <error>
                          format = cl_abap_format=>e_html_text ).
        <error> = <error> && '
'.
      ENDLOOP.
      INSERT '<html><body>' INTO error_list INDEX 1.
      APPEND '</body></html>' TO error_list.
      cl_abap_browser=>show_html(
        EXPORTING
          html       = error_list
          modal       = modal
          dialog      = COND #( WHEN no_box = abap_false
                                    THEN abap_true )
          title      = 'HTML Validation Errors'
          check_html = abap_false
          printing   = abap_true ).

      IF modal IS INITIAL AND no_box IS INITIAL.
        MESSAGE 'Second call of browser' TYPE 'I'.
      ENDIF.

    ENDIF.

    REPLACE '<htm1'  IN html_str WITH  '<html'.

    cl_abap_browser=>show_html(
      EXPORTING
        html_string = html_str
        modal       = modal
        dialog      = COND #( WHEN no_box = abap_false
                                  THEN abap_true )
        title      = title
        buttons    = cl_abap_browser=>navigate_html
        format     = cl_abap_browser=>landscape
        size       = cl_abap_browser=>medium
        data_table = ext_data
        check_html = abap_true
      IMPORTING
         html_errors = error_list ).

    IF modal IS INITIAL AND no_box IS INITIAL.
      MESSAGE 'Third call of browser' TYPE 'I'.
    ENDIF.

    IF error_list IS INITIAL.
      MESSAGE 'No errors in HTML' TYPE 'S'.
    ENDIF.

Description

The class CL_ABAP_BROWSER encapsulates the use of the class CL_GUI_HTML_VIEWER. The static method SHOW_HTML can be used to display a HTML file in a modal or modeless dialog box or in the same window as the current dynpro. External data, in this case a picture loaded from the MIME Repository, can be passed and displayed. The SAPEVENT events are still passed on and can be handled by the user.

  • The HTML file passed first has errors, since the <html> tag is written incorrectly. In SAP systems, this case always produces an appropriate message.
  • The error list is also represented using SHOW_HTML, where the error check for this simple purpose is disabled by passing a blank to the appropriate parameter.
  • The error in question is corrected in the HTML file and passed again, with the error check enabled this time.

When the program starts, the file can be display in a modal window, a modeless window, or without a dialog box. If a modeless dialog box is chosen, container dynpros and information messages must be used to keep the dialog box alive. If no messages were sent, the modeless dialog box would not be visible.