ABAP Keyword Documentation → ABAP - Reference → User Dialogs → Screens → Screen and Screen Elements → Screen Elements - Examples
Screens, 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 html_str TYPE string.
DATA title TYPE cl_abap_browser=>title.
DATA ext_data TYPE cl_abap_browser=>load_tab.
DATA ext_line TYPE cl_abap_browser=>load_tab_line.
DATA error_list TYPE cl_abap_browser=>html_table.
FIELD-SYMBOLS <error> LIKE LINE OF error_list.
title = 'HTML Browser Demo'.
SET HANDLER handle_sapevent.
get_pict_tab(
EXPORTING
mime_url = '/SAP/PUBLIC/BC/ABAP/Sources/ABAP_Docu_Logo.gif'
IMPORTING
pict_tab = pict ).
ext_line-name = 'PICT.GIF'.
ext_line-type = 'image'.
GET REFERENCE OF pict INTO ext_line-dref.
APPEND ext_line TO ext_data.
html_str =
'<html>' &&
'<body>' &&
'<H1><font SIZE=5 color="#000080">HTML</font></H1>' &&
'<A HREF="http://help.sap.com/">Weblink</A>' &&
'
<A HREF=SAPEVENT:"ActionCode">SAPevent</A>' &&
'
External Picture:' &&
'
<img src="PICT.GIF" >' &&
'</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 <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 '<html>'
IN html_str
WITH '<html lang="EN">' &&
'<head>' &&
'<meta name="Demo" content="Test">' &&
'<style type="text/css">' &&
'span.h1 {font-size: 150%; color:#000080; ' &&
'font-weight:bold;}' &&
'</style>' &&
'</head>'.
REPLACE '<H1><font SIZE=5 color="#000080">HTML</font></H1>'
IN html_str
WITH '<p><span class="h1">HTML</span></p>'.
REPLACE 'src="PICT.GIF"'
IN html_str
WITH 'src="PICT.GIF" alt="An example figure"'.
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 first HTML file passed has errors since it does not meet the criteria for accessibility. For
this reason, an error list is returned in the parameter
html_errors
. In SAP's internal systems, a corresponding message is always displayed in these cases to inform users of the class that the corresponding product standard has been violated.
- The error list is also represented using SHOW_HTML, where the accessibility check for this simple purpose is disabled by passing a blank character to the appropriate parameter.
- The errors found are corrected in the HTML file and passed again, with the accessibility check enabled this time.