I have a requirement where different documents are saved as a xstring on a database table.
These documents should now be displayed. For this I use the SAP Document Viewer. I got it to work with PDFs, but not with .doc files.
When I try to use it with .doc files, instead of displaying the document I get a download window like in the browser with a zip file containing the content of the word document.
In the example below I skipped the part of reading the xstring from the database and instead tried to display it directly after upload. The problem remains the same.
TYPE-POOLS: soi.
TYPES: ty_daten(2550) TYPE c.
DATA: custom_container TYPE REF TO cl_gui_custom_container,
document_viewer TYPE REF TO i_oi_document_viewer.
DATA: t_daten TYPE STANDARD TABLE OF ty_daten
WITH NON-UNIQUE DEFAULT KEY.
DATA: filesize TYPE i.
END-OF-SELECTION.
CREATE OBJECT custom_container
EXPORTING container_name = 'CONTAINER100'.
CALL METHOD c_oi_container_control_creator=>get_document_viewer
IMPORTING viewer = document_viewer.
CALL METHOD document_viewer->init_viewer
EXPORTING parent = custom_container.
CALL FUNCTION 'UPLOAD'
EXPORTING
filename = 'c:\temp\test.doc'
filetype = 'BIN'
IMPORTING
filesize = filesize
TABLES
data_tab = t_daten
EXCEPTIONS
conversion_error = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
OTHERS = 7.
IF sy-subrc <> 0.
WRITE:/ 'Fehler',sy-subrc.
STOP.
ENDIF.
CALL METHOD document_viewer->view_document_from_table
EXPORTING
type = soi_type_application
subtype = soi_doctype_word_document
size = filesize
show_inplace = 'X'
CHANGING
document_table = t_daten
EXCEPTIONS
cntl_error = 1
not_initialized = 2
dp_error_general = 3
invalid_parameter = 4
dp_invalid_parameter = 5.
CALL SCREEN 100.
CALL METHOD document_viewer->destroy_viewer.
CALL METHOD custom_container->free.
FREE: document_viewer, custom_container.
c_oi_container_control_creator=>get_container_control,init_control,get_document_proxy). The integration may be difficult, there are several SAP Notes to help troubleshooting. Because of that, I prefer the solution to start Word outside SAP GUI.