2013 Oct 15 10:23 AM
Hello,
Similar type of questions have been raised many times, but this is with respect to Unicode system.
I am sending PDF attachment in mail and below is my sample code. I am reading PDF file from application server and sending in mail.
Please note that error is for some files not all files.
I downloaded that file in presentation server, its opening correctly in PDF, but in mail when checked in SOST I am getting below error:
"There was error opening this document. The file is damaged or could not be repaired"
OPEN DATASET FILE_NAME FOR INPUT IN BINARY MODE .
IF sy-subrc EQ 0.
DO.
ASSIGN wa_bin TO <hex_container> CASTING.
READ DATASET FILE_NAME INTO <hex_container>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
APPEND wa_bin TO lv_content_out.
ENDDO.
CLOSE DATASET FILE_NAME.
ENDIF.
* add text attachment to document
ztype = 'PDF'.
document->add_attachment( i_attachment_type = ztype
i_attachment_subject = zattname
i_att_content_hex = lv_content_out ).
As this works perfect for some files, i wonder is this anything to do with file or system which is Unicode.
Please help.
2013 Oct 15 10:50 AM
Hi gaurav,
Please check the below code
DATA: file(50) TYPE c ."VALUE './test.doc'.
data : wa_bin type xstring,
lv_ext TYPE SOODK-OBJTP,
gv_file_size TYPE zfile-zsize.
DATA: document TYPE REF TO cl_document_bcs.
open dataset file for input in binary mode.
READ DATASET file INTO wa_bin actual length gv_file_size.
binary_content = cl_document_bcs=>xstring_to_solix( wa_bin ).
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_length = '1000'
i_subject = lv_subject )."'attachment' ).
CALL FUNCTION 'TRINT_FILE_GET_EXTENSION'
EXPORTING
FILENAME = file
* UPPERCASE = 'X'
IMPORTING
EXTENSION = lv_ext.
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = lv_ext
i_attachment_subject = file "'My attachment'
i_att_content_hex = binary_content.
May be it will solve your problem ,If you get any issues still please get back to me .
Thanks,
Kumar
2013 Oct 15 10:50 AM
Hi gaurav,
Please check the below code
DATA: file(50) TYPE c ."VALUE './test.doc'.
data : wa_bin type xstring,
lv_ext TYPE SOODK-OBJTP,
gv_file_size TYPE zfile-zsize.
DATA: document TYPE REF TO cl_document_bcs.
open dataset file for input in binary mode.
READ DATASET file INTO wa_bin actual length gv_file_size.
binary_content = cl_document_bcs=>xstring_to_solix( wa_bin ).
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_length = '1000'
i_subject = lv_subject )."'attachment' ).
CALL FUNCTION 'TRINT_FILE_GET_EXTENSION'
EXPORTING
FILENAME = file
* UPPERCASE = 'X'
IMPORTING
EXTENSION = lv_ext.
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = lv_ext
i_attachment_subject = file "'My attachment'
i_att_content_hex = binary_content.
May be it will solve your problem ,If you get any issues still please get back to me .
Thanks,
Kumar
2013 Oct 15 1:10 PM
Thanks a lot. It has solved my problem.
I guess, Problem was with conversion to hex string conversion for some particular characters.
method you have given, solved my problem.