메뉴 건너뛰기

SAP 한국 커뮤니티



REPORT z_html_viewer

노름마치 2007.11.05 22:02 조회 수 : 5305

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 : mpioud@yahoo.fr  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.


*---------------------------------------------------------------------*
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
*---------------------------------------------------------------------*
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.


ENDCLASS.
*---------------------------------------------------------------------*
*       Module  STATUS_0100  OUTPUT
*---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.


  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 HTML viewer
  CREATE OBJECT go_htmlviewer
      EXPORTING parent = go_html_container.


* 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.


* Create toolbar
  CREATE OBJECT go_toolbar
      EXPORTING parent = go_toolbar_container.


* 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.


  CALL METHOD go_htmlviewer->set_registered_events
    EXPORTING events = gt_events.


* Create event handlers
  CREATE OBJECT go_event_handler.


  SET HANDLER go_event_handler->on_function_selected
          FOR go_toolbar.


  SET HANDLER go_event_handler->on_navigate_complete
          FOR go_htmlviewer.


  g_screen100_url_text = 'www.google.com'.
  PERFORM goto_url.


ENDMODULE.                             " STATUS_0100  OUTPUT
*---------------------------------------------------------------------*
*       Module  USER_COMMAND_0100  INPUT
*---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.


* 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.


  DEFINE m_add_button.
    call method cl_gui_toolbar=>fill_buttons_data_table
      exporting
        fcode              = &1
        icon               = &2
        butn_type          = cntb_btype_button
        text               = &3
        quickinfo          = &4
      changing
        data_table         = gt_button_group.
  END-OF-DEFINITION.


  m_add_button 'BACK'    icon_arrow_left  ''     'Go back'.
  m_add_button 'FORWARD' icon_arrow_right ''     'Go forward'.
  m_add_button 'STOP'    icon_breakpoint  ''     'Stop'.
  m_add_button 'REFRESH' icon_Refresh     ''     'Refresh'.
  m_add_button 'HOME'    ''               'Home' 'Home'.
  m_add_button 'EXIT'    icon_close       ''     'Close program'.


* 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.


  CHECK NOT g_screen100_url_text IS INITIAL.


  CALL METHOD go_htmlviewer->show_url
    EXPORTING url = g_screen100_url_text.


ENDFORM.                               " GOTO_URL
**************** END OF PROGRAM Z_HTML_VIEWER *************************