HTML preview in SAP GUI

Problem: requirement is to show HTML page in CRM, in the SAP GUI.

Solution: There is a neat class available in SAP CRM which will do exactly what we want. Class is called CL_GUI_HTML_VIEWER.

First we need to create a screen with a Customer Container on it. In this example container is called CTR_MAIN. Below is the code which needs to be put in the PBO event of the screen.

  data: lo_container TYPE REF TO cl_gui_custom_container,
        lo_viewer TYPE REF TO cl_gui_html_viewer,
        lv_text TYPE char255,
        lt_text TYPE TABLE OF char255,
        lv_url TYPE char255.
 
  CREATE OBJECT lo_container
    EXPORTING
      container_name = 'CTR_MAIN'
    EXCEPTIONS
      OTHERS         = 1.
  IF sy-subrc IS NOT INITIAL.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    RETURN.
  ENDIF.
 
  CREATE OBJECT lo_viewer
    EXPORTING
      parent             = lo_container
    EXCEPTIONS
      cntl_error         = 1
      cntl_install_error = 2
      dp_install_error   = 3
      dp_error           = 4
      OTHERS             = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    RETURN.
  ENDIF. 
 
  lv_text = '<html><head></head><body bgcolor="green">Hello world!</body></html>'.
  APPEND lv_text TO lt_text.
 
  CALL METHOD lo_viewer->load_data
    IMPORTING
      assigned_url         = lv_url
    CHANGING
      data_table           = lt_text
    EXCEPTIONS
      dp_invalid_parameter = 1
      dp_error_general     = 2
      cntl_error           = 3
      OTHERS               = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
 
  CALL METHOD lo_viewer->show_data
    EXPORTING
      url = lv_url.
  data: lo_container TYPE REF TO cl_gui_custom_container,
        lo_viewer TYPE REF TO cl_gui_html_viewer,
        lv_text TYPE char255,
        lt_text TYPE TABLE OF char255,
        lv_url TYPE char255.

  CREATE OBJECT lo_container
    EXPORTING
      container_name = 'CTR_MAIN'
    EXCEPTIONS
      OTHERS         = 1.
  IF sy-subrc IS NOT INITIAL.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    RETURN.
  ENDIF.

  CREATE OBJECT lo_viewer
    EXPORTING
      parent             = lo_container
    EXCEPTIONS
      cntl_error         = 1
      cntl_install_error = 2
      dp_install_error   = 3
      dp_error           = 4
      OTHERS             = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    RETURN.
  ENDIF. 

  lv_text = '<html><head></head><body bgcolor="green">Hello world!</body></html>'.
  APPEND lv_text TO lt_text.

  CALL METHOD lo_viewer->load_data
    IMPORTING
      assigned_url         = lv_url
    CHANGING
      data_table           = lt_text
    EXCEPTIONS
      dp_invalid_parameter = 1
      dp_error_general     = 2
      cntl_error           = 3
      OTHERS               = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CALL METHOD lo_viewer->show_data
    EXPORTING
      url = lv_url.

After implementing this code, there will be a nice green page with a „Hello world!” text right in the middle of our new screen.

Komentowanie jest zakończone.