on 03-28-2012 5:54 PM
Hi all,
I have a purchase order with some attachments and I want to open a new internet browser for show it.
I've tried the following but when the internet browser is open for show the document an error appears to say "The file is corrupted".
This is my code:
DATA: lv_instid TYPE sofolenti1-doc_id,
lv_guid TYPE bbp_guid.
DATA: ld_doc_data1 TYPE sofolenti1,
lt_cont_binary TYPE TABLE OF solisti1.
SELECT SINGLE guid INTO lv_guid
FROM CRMD_ORDERADM_H
WHERE object_id EQ '3200000139'.
SELECT SINGLE instid_b INTO lv_instid
FROM srgbtbrel
WHERE reltype EQ 'ATTA'
AND instid_a EQ lv_guid
AND typeid_a EQ 'BUS2201'
AND catid_a EQ 'BO'.
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
document_id = lv_instid
IMPORTING
document_data = ld_doc_data1
TABLES
object_content = lt_cont_binary
EXCEPTIONS
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
OTHERS = 4.
DATA: li_content TYPE xstring,
li_aux TYPE xstring,
ld_string TYPE string,
ld_length TYPE i.
ld_length = ld_doc_data1-doc_size.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = ld_length
* FIRST_LINE = 0
* LAST_LINE = 0
IMPORTING
buffer = li_content
TABLES
binary_tab = lt_cont_binary
EXCEPTIONS
failed = 1
OTHERS = 2.
* append the pdf to the response
cl_wd_runtime_services=>attach_file_to_response(
i_filename = 'report.PDF'
i_content = li_content
i_mime_type = 'application/pdf'
i_in_new_window = 'X'
i_inplace = 'X' ).
Thanks in advance.
Hi,
Try changing your code this way -
DATA: lt_xtab TYPE enh_version_management_hex_tb,
CALL FUNCTION 'SO_DOCUMENT_READ_API1'
EXPORTING
document_id = lv_doc_id
IMPORTING
document_data = lv_document_data
TABLES
object_header = lt_headerd
contents_hex = file_contents
EXCEPTIONS
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
OTHERS = 4.
LOOP AT file_contents INTO wa_contents.
wa_xtab = wa_contents-line .
APPEND wa_xtab TO lt_xtab.
ENDLOOP.
CALL FUNCTION 'ENH_TAB_TO_XSTRING'
EXPORTING
im_data = lt_xtab
IMPORTING
ex_xstring = lw_data-file_data.
**--- Here change file data input to the above lw_data-file_data .
cl_wd_runtime_services=>attach_file_to_response(
i_filename = 'report.PDF'
i_content = lw_data-file_data
i_mime_type = 'application/pdf'
i_in_new_window = 'X'
i_inplace = space ).
I have implemented it using above approach. This should work perfectly for you too.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to save the file to your local machine and see if it opens up. If not, then, you are missing something in the conversion to binary. If it does open fine on your computer, then you need to look into the cl_wd_runtime_services=>attach_file_to_response method and whether you are missing some of the parameters.
Another trick to see whether it is working, upload a binary file from your machine and see if it opens up using cl_wd_runtime_services=>attach_file_to_response.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The file is ok. I tried also with other files attached from my computer.
I'm using the cl_wd_runtime_services=>attach_file_to_response method in other custom components for show and smartforms and works fine, but this case is different. For smartform I need to call before to the FM 'CONVERT_OTF'. For this case I have the file in a binary table.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.