2024 Nov 12 11:51 AM - edited 2024 Nov 12 1:46 PM
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
Error found in browser control
I attach code
Thanks
*&---------------------------------------------------------------------*
*& Report ZVIEW_ALLEGATI
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zview_allegati.
DATA: okcode 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 1 = 2. ENDIF.
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.
DATA: tb_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 1 ASSIGNING FIELD-SYMBOL(<r_l_files>).
IF sy-subrc = 0 AND <r_l_files> IS ASSIGNED.
p_nomefile = <r_l_files>.
ENDIF.
CLEAR: sy-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.
2024 Nov 12 12:24 PM
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?
2024 Nov 12 1:18 PM
2024 Nov 12 1:29 PM
Thanks. I suggest that you edit the question instead of a comment (that maybe nobody will see).
2024 Nov 12 1:30 PM
2024 Nov 12 12:38 PM
AFAIK (and if I remember correctly) there are limitations to Webgui HTML Viewer
2024 Nov 12 1:30 PM
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
2024 Nov 12 1:55 PM - edited 2024 Nov 12 3:02 PM
Start with a simple report as SAPHTML_DEMO1 before testing DEMO_PICTURE_IN_HTML, SAP_PDF_VIEWER_DEMO and other similar programs.
2024 Nov 12 2:34 PM
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)