cancel
Showing results for 
Search instead for 
Did you mean: 

Error while trying to open Office 2007 documents from WDA

former_member182374
Active Contributor
0 Kudos

Hello Experts,

I'm trying to open Office 2007 documents by using Web Dynpro ABAP.

I'm using CL_WD_RUNTIME_SERVICES=>attach_file_to_response and I'm sending the correct mime type by using 'SDOK_MIMETYPE_GET' function.

The document is opened but I always get "file is corrupted" error message for docx, xlsx and pptx files (I confirm the message and then I can see that the file is OK).

Note 1485231 is not relevant because the file extension is correct (4 characters).

SAP_BASIS version is 7.31 SP4.

Office version is 2007.

How can I solve this issue?

Regards,

Omri

Accepted Solutions (1)

Accepted Solutions (1)

former_member182374
Active Contributor

Solved it on my own by using the following code:

method open_attachment .


data lv_mime_type type string.
data lv_file_name type string.

data lt_gos_content_bin type table of solix.
data lo_conv_class type ref to cl_abap_conv_out_ce.
data lo_off_class type ref to cl_abap_view_offlen.
data ls_gos_content_bin type solix.

data lv_content_xstring type xstring.
data ev_content_hex type  xstring.
data ls_gos_document_data type sofolenti1.

call function 'SO_DOCUMENT_READ_API1'
exporting
document_id               
= doc_id
importing
document_data             
= ls_gos_document_data
tables
contents_hex              
= lt_gos_content_bin
exceptions
document_id_not_exist     
= 1
operation_no_authorization
= 2
x_error                   
= 3
others                     = 4.

if sy-subrc = 0.
lo_conv_class
= cl_abap_conv_out_ce=>create( ).
lo_off_class 
= cl_abap_view_offlen=>create_legacy_view( ls_gos_content_bin ).

loop at lt_gos_content_bin into ls_gos_content_bin.
lo_conv_class
->write(
data = ls_gos_content_bin
view
= lo_off_class ).
endloop.

lv_content_xstring
= lo_conv_class->get_buffer( ).
ev_content_hex    
= lv_content_xstring(ls_gos_document_data-doc_size).

lv_mime_type
= wd_this->get_mimetype_by_file_ext( docuclass = docuclass ).
concatenate 'file_' sy-datum '_' sy-uzeit '.' docuclass into lv_file_name.

cl_wd_runtime_services
=>attach_file_to_response(
i_filename
= lv_file_name
i_content
= ev_content_hex
i_mime_type
= lv_mime_type
i_in_new_window
= 'X'
i_inplace
= space ).
endif.
endmethod.

Omri

Former Member
0 Kudos

Omri, Thanks for your code. it is an amazing solution. Thanks a TON.


Answers (1)

Answers (1)

alegarciamacedo
Explorer
0 Kudos

Thank you, Omri! I had the same issue. It was solved with your tip.