Posted: Sat Jan 26, 2008 5:20 pm Post subject: HTML Control: SAP HTML viewer to browse the internet
Code:
REPORT z_html_viewer.
*---------------------------------------------------------------------*
* This program is an adaptation of the program SAPMZ_HF_HTML_CONTROL *
* available on the site : http://www.henrikfrank.dk *
*---------------------------------------------------------------------*
* This example uses the SAP HTML viewer to browse the internet. 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. *
*---------------------------------------------------------------------*
* - Create the screen 0100 and place a container named *
* HTML_CONTAINER for the HTML viewer. *
* - Create a container named TOOLBAR_CONTAINER for the toolbar. *
* - Create a dynpro button named GOTO_URL and functioncode GOTOURL. *
* - Create a dynpro output field named G_SCREEN100_URL_TEXT. *
* This field is used to key in the url. *
* - Create a dynpro input/output field named G_SCREEN100_DISPLAY_URL. *
* This field is used to show the current url *
* - Flow logic of screen 100 *
* * PROCESS BEFORE OUTPUT. *
* MODULE status_0100. *
* * PROCESS AFTER INPUT. *
* MODULE user_command_0100. *
*---------------------------------------------------------------------*
* The Dynpro 0100 can be uploaded *
* (SE51/Change/utilities/More utilities/Upload-Download/Upload) *
* at this URL : Z_HTML_VIEWER_DYN_0100.html *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : [email protected] HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
TYPE-POOLS: icon.
CLASS cls_event_handler DEFINITION DEFERRED.
DATA:
* Push button
goto_url(20) VALUE 'Go To Url',
okcode LIKE sy-ucomm,
* Container for html viewer
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,
* Table for button group
gt_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.
gt_events TYPE cntl_simple_events,
* Workspace for table gt_events
gs_event TYPE cntl_simple_event.
*---------------------------------------------------------------------*
* 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
*---------------------------------------------------------------------*
CLASS cls_event_handler IMPLEMENTATION.
* Handles method function_selected for the toolbar control
METHOD on_function_selected.
CASE fcode.
WHEN 'BACK'.
CALL METHOD go_htmlviewer->go_back
EXCEPTIONS cntl_error = 1.
WHEN 'FORWARD'.
CALL METHOD go_htmlviewer->go_forward
EXCEPTIONS cntl_error = 1.
WHEN 'STOP'.
CALL METHOD go_htmlviewer->stop
EXCEPTIONS cntl_error = 1.
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.
* Handles method navigate_complete for the HTML viewer control
METHOD on_navigate_complete.
* Display current URL in a textfield on the screen
g_screen100_display_url = url.
ENDMETHOD.
CHECK go_html_container IS INITIAL.
* Create container for HTML viewer
CREATE OBJECT go_html_container
EXPORTING container_name = 'HTML_CONTAINER'
EXCEPTIONS cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.
MESSAGE e208(00)
WITH 'The control HTML_CONTAINER could not be created'.
ENDIF.
* Create container for toolbar
CREATE OBJECT go_toolbar_container
EXPORTING container_name = 'TOOLBAR_CONTAINER'
EXCEPTIONS cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.
MESSAGE e208(00)
WITH 'The control TOOLBAR_CONTAINER could not be created'.
ENDIF.
* Add buttons to the toolbar
PERFORM add_button_group.
* Create event table. The event ID must be found in the
* documentation of the specific control
CLEAR gs_event.
REFRESH gt_events.
gs_event-eventid = go_toolbar->m_id_function_selected.
gs_event-appl_event = 'X'. " This is an application event
APPEND gs_event TO gt_events.
gs_event-eventid = go_htmlviewer->m_id_navigate_complete.
APPEND gs_event TO gt_events.
* Use the events table to register events for the control
CALL METHOD go_toolbar->set_registered_events
EXPORTING events = gt_events.
* Handles the pushbutton for goto url
CASE okcode.
WHEN 'GOTOURL'.
PERFORM goto_url.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*---------------------------------------------------------------------*
* Form add_button_group
*---------------------------------------------------------------------*
* Adds a button group to the toolbar
*---------------------------------------------------------------------*
FORM add_button_group.
* Add button group to toolbar
CALL METHOD go_toolbar->add_button_group
EXPORTING data_table = gt_button_group.
ENDFORM. " ADD_BUTTON_GROUP
*---------------------------------------------------------------------*
* Form goto_url
*---------------------------------------------------------------------*
* Calls method SHOW_URL to navigate to an URL
*---------------------------------------------------------------------*
FORM goto_url.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.