Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

CL_GUI_HTML_VIEWER does not work when called in flowers app

slanzetta2
Explorer
0 Kudos
463

Hi all,
I created a report that shows attachments with cl_gui_html_viewer.
If I run the report from gui it works. If I call the report via Tcode from Fiori launchpad it doesn't display anything

slanzetta2_0-1731418390791.pngslanzetta2_1-1731418407523.png

Error found in browser control

slanzetta2_0-1731419155556.png

 

I attach code

Thanks

*&---------------------------------------------------------------------*
*& Report ZVIEW_ALLEGATI
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zview_allegati.

DATAokcode              TYPE sy-ucomm,
      va_nomefile         TYPE string,
      ca_initial_dir      TYPE string,
      g_custom_container3 TYPE REF TO cl_gui_custom_container,
      o_viewer            TYPE REF TO cl_gui_html_viewer,
      va_curr_url         TYPE url.

START-OF-SELECTION.
  IF 2ENDIF.

  CALL SCREEN 2050.

END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Module STATUS_2050 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_2050 OUTPUT.
  SET PF-STATUS 'ZSTANDARD'.
  SET TITLEBAR 'ZSTANDARD'.

  IF NOT va_nomefile IS INITIAL.
    PERFORM create_object2 .
  ENDIF.

  IF va_nomefile IS INITIAL.
    PERFORM refresh_object.
  ENDIF.

ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_2050  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_2050 INPUT.
  CASE okcode.
    WHEN '&F03' OR '&F15' OR '&F12'.
      PERFORM exit_program.
    WHEN 'BROWSE'.
      PERFORM browse_for_file USING TEXT-001 CHANGING va_nomefile.
    WHEN 'ERASE'.
      CLEAR va_nomefile.
  ENDCASE.

ENDMODULE.
*&---------------------------------------------------------------------*
*& Form exit_program
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM exit_program .

  IF NOT o_viewer IS INITIAL.
    CALL METHOD o_viewer->close_document
      EXCEPTIONS
        cntl_error 1
        OTHERS     2.
    CALL METHOD o_viewer->free
      EXCEPTIONS
        cntl_error        1
        cntl_system_error 2
        OTHERS            3.
  ENDIF.

  LEAVE TO SCREEN 0.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form browse_for_file
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> TEXT_001
*&      <-- VA_NOMEFILE
*&---------------------------------------------------------------------*
FORM browse_for_file  USING   p_text
                      CHANGING p_nomefile.

  DATAtb_l_files TYPE filetable,
        vn_l_rc    TYPE i.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            p_text
*     default_extension       =
*     default_filename        =
*     file_filter             =
*     with_encoding           =
      initial_directory       ca_initial_dir
      multiselection          ' '
    CHANGING
      file_table              tb_l_files
      rc                      vn_l_rc
*     user_action             =
*     file_encoding           =
    EXCEPTIONS
      file_open_dialog_failed 1
      cntl_error              2
      error_no_gui            3
      not_supported_by_gui    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.
  ENDIF.

  READ TABLE tb_l_files INDEX ASSIGNING FIELD-SYMBOL(<r_l_files>).
  IF sy-subrc AND <r_l_files> IS ASSIGNED.
    p_nomefile <r_l_files>.
  ENDIF.
  CLEARsy-subrc.
  UNASSIGN<r_l_files>.


ENDFORM.
*&---------------------------------------------------------------------*
*& Form create_object2
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM create_object2 .

  IF NOT va_nomefile IS INITIAL.
    IF NOT g_custom_container3 IS INITIAL.
      PERFORM refresh_object.
    ENDIF.

    CREATE OBJECT g_custom_container3
      EXPORTING
        container_name              'CONTAINER2'
*  ADD
      EXCEPTIONS
        cntl_error                  1
        cntl_system_error           2
        create_error                3
        lifetime_error              4
        lifetime_dynpro_dynpro_link 5
        OTHERS                      6.

    CREATE OBJECT o_viewer
      EXPORTING
        parent             g_custom_container3
*       saphtmlp           = 'X' ADD
      EXCEPTIONS
        cntl_error         1
        cntl_install_error 2
        dp_install_error   3
        dp_error           4
        OTHERS             5.

  ENDIF.

  IF NOT g_custom_container3 IS INITIAL.

*  ADD
    CALL METHOD o_viewer->enable_simplebrowsing
      EXPORTING
        benable    1
      EXCEPTIONS
        cntl_error 1
        others     2
            .
    IF sy-subrc <> 0.
*     Implement suitable error handling here
    ENDIF.

    va_curr_url va_nomefile.
    CALL METHOD o_viewer->show_url
      EXPORTING
        url                    va_curr_url
*       frame                  =
*       in_place               = 'X'
      EXCEPTIONS
        cntl_error             1
        cnht_error_not_allowed 2
        cnht_error_parameter   3
        dp_error_general       4
        OTHERS                 5.
  ENDIF.
*  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form refresh_object
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM refresh_object .
  IF NOT g_custom_container3 IS INITIAL.
    CALL METHOD g_custom_container3->free
      EXCEPTIONS
        cntl_error        1
        cntl_system_error 2
        OTHERS            3.

    CALL METHOD o_viewer->free
      EXCEPTIONS
        cntl_error        1
        cntl_system_error 2
        OTHERS            3.
  ENDIF.
ENDFORM.

8 REPLIES 8

Sandra_Rossi
Active Contributor
440

I won't click each of the images to display them (also, it's uncomfortable because they display separately from the text). Instead of hyperlink, could you display the images in the question please?

411

slanzetta2_0-1731417445863.pngslanzetta2_1-1731417474140.png

The program also allows me to upload and view PDF files

0 Kudos
407

Thanks. I suggest that you edit the question instead of a comment (that maybe nobody will see).

0 Kudos
406

Also check the errors in the browser console.

raymond_giuseppi
Active Contributor
431

AFAIK (and if I remember correctly) there are limitations to Webgui HTML Viewer

  • 3024355 - Webgui HTML Viewer: Restrictions compared to SAP GUI for Windows
  • 2973428 - Reverse Tabnabbing vulnerability within SAP NetWeaver Application Server ABAP (Applications based on SAP GUI for HTML)
  • 820706 - ITS HTML Viewer: Parameters of the event SAPEVENT
  • 191908 - Collective note: HTML Viewer Control

0 Kudos
407

Hi,

You are telling me that the program works fine if run in SAP GUI, but to make it work on Fiori launchpad I have to modify the program.

Can you give me an example of a report that displays images and pdf on Fiori launchpad?

Thanks

380

Start with a simple report as  SAPHTML_DEMO1 before testing DEMO_PICTURE_IN_HTML, SAP_PDF_VIEWER_DEMO and other similar programs.

Sandra_Rossi
Active Contributor
0 Kudos
289

The error is "Not allowed to load local resource" (file:///Z:/temp/A.JPG). You should include images only coming from your server (based on https). What happens if you load the image via LOAD_DATA or LOAD_MIME_OBJECT? (e.g. program RSDEMO_HTML_VIEWER)

Sandra_Rossi_0-1731421789398.png