Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  User Dialogs →  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
        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 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
          title      = 'HTML Validation Errors'
          check_html = abap_false
          printing   = abap_true ).
    ENDIF.

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

    cl_abap_browser=>show_html(
      EXPORTING
        html_string = html_str
        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 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 SHOW_HTML method can be used to display a HTML file in a dialog box. 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 character to the appropriate parameter.
  • The error in question is corrected in the HTML file and passed again, with the error check enabled this time.