Sap HTML Viewer Abap Objects
Sap HTML Viewer Abap Objects
The navigation
buttons are placed on a SAP Toolbar control. The Goto URL button and field are
normal dynpro elements, and so is the Show URL field.
Steps:
The screen:
The code
SAPMZ_HF_HTML_CONTROL
REPORT sapmz_hf_html_control .
TYPE-POOLS: icon.
*-------------------------------------------------------------------
* G L O B A L V A R I A B L E S
*-------------------------------------------------------------------
DATA:
ok_code LIKE sy-ucomm,
* Container for html vieaer
go_html_container TYPE REF TO cl_gui_custom_container,
* HTML viewer
go_htmlviewer TYPE REF TO cl_gui_html_viewer,
* Container for toolbar
go_toolbar_container TYPE REF TO cl_gui_custom_container,
* SAP Toolbar
go_toolbar TYPE REF TO cl_gui_toolbar,
* Event handler for toolbar
go_event_handler TYPE REF TO cls_event_handler,
* Variable for URL text field on screen 100
g_screen100_url_text(255) TYPE c,
g_screen100_display_url(255) TYPE c.
*-------------------------------------------------------------------
* I N T E R N A L T A B L E S
*-------------------------------------------------------------------
DATA:
* Table for button group
gi_button_group TYPE ttb_button,
* Table for registration of events. Note that a TYPE REF
* to cls_event_handler must be created before you can
* reference types cntl_simple_events and cntl_simple_event.
gi_events TYPE cntl_simple_events,
* Workspace for table gi_events
g_event TYPE cntl_simple_event.
START-OF-SELECTION.
SET SCREEN '100'.
*-------------------------------------------------------------------
--*
* CLASS cls_event_handler DEFINITION
*-------------------------------------------------------------------
--
* Handles events for the toolbar an the HTML viewer
*-------------------------------------------------------------------
--*
CLASS cls_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
* Handles method function_selected for the toolbar control
on_function_selected
FOR EVENT function_selected OF cl_gui_toolbar
IMPORTING fcode,
* Handles method navigate_complete for the HTML viewer control
on_navigate_complete
FOR EVENT navigate_complete OF cl_gui_html_viewer
IMPORTING url.
ENDCLASS.
CLASS cls_event_handler IMPLEMENTATION.
WHEN 'REFRESH'.
CALL METHOD go_htmlviewer->do_refresh
EXCEPTIONS cntl_error = 1.
WHEN 'HOME'.
CALL METHOD go_htmlviewer->go_home
EXCEPTIONS cntl_error = 1.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMETHOD.
ENDCLASS.
*&------------------------------------------------------------------
---*
*& Module STATUS_0100 OUTPUT
*&------------------------------------------------------------------
---*
MODULE status_0100 OUTPUT.
IF go_html_container IS INITIAL.
* Create container for HTML viewer
CREATE OBJECT go_html_container
EXPORTING
container_name = 'HTML_CONTAINER'.
* Create toolbar
CREATE OBJECT go_toolbar
EXPORTING
parent = go_toolbar_container.
g_event-eventid = go_htmlviewer->m_id_navigate_complete.
APPEND g_event TO gi_events.
ENDIF.
* BACK botton
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'BACK'
icon = icon_arrow_left
butn_type = cntb_btype_button
text = ''
quickinfo = 'Go back'
CHANGING
data_table = gi_button_group.
* FORWARD botton
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'FORWARD'
icon = icon_arrow_right
butn_type = cntb_btype_button
text = ''
quickinfo = 'Go forward'
CHANGING
data_table = gi_button_group.
* STOP button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'STOP'
icon = icon_breakpoint
butn_type = cntb_btype_button
text = ''
quickinfo = 'Stop'
CHANGING
data_table = gi_button_group.
* REFRESH button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'REFRESH'
icon = icon_refresh
butn_type = cntb_btype_button
text = ''
quickinfo = 'Refresh'
CHANGING
data_table = gi_button_group.
* Home button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'HOME'
icon = ''
butn_type = cntb_btype_button
text = 'Home'
quickinfo = 'Home'
CHANGING
data_table = gi_button_group.
* Separator
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'SEP1'
icon = ' '
butn_type = cntb_btype_sep
CHANGING
data_table = gi_button_group.
* EXIT button
CALL METHOD cl_gui_toolbar=>fill_buttons_data_table
EXPORTING
fcode = 'EXIT'
icon = icon_close
butn_type = cntb_btype_button
text = ''
quickinfo = 'Close porgram'
CHANGING
data_table = gi_button_group.