‎2011 Oct 10 3:47 PM
Hi Experts,
I am using CL_BCS to send the mail with PDF attachment.
Mail is being delivered to the recipent but in some cases PDF is not opening.
It giving error "File is damaged or could not be opened".
I am not getting why this happening with some PDF attachments. I am using the following code to convert data into binary form.
LOOP AT data_bin INTO ls_raw.
ASSIGN ls_raw-line TO <fs_converter> CASTING.
CONCATENATE l_xtr <fs_converter> INTO l_xtr IN BYTE MODE.
ENDLOOP.
IF l_xtr IS NOT INITIAL.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = l_xtr
TABLES
binary_tab = lt_att_content_hex1.
Thanks.
‎2011 Oct 10 4:03 PM
Hi
I think it depends on the table DATA_BI has, how do you fill it?
Max
‎2011 Oct 11 11:15 AM
I am fetting thr data from FM 'SCMS_R3DB_GET' in table DATA_BIN.
CALL FUNCTION 'SCMS_R3DB_GET'
EXPORTING
crep_id = crepid "'SOFFDB'
doc_id = docid
mandt = sy-mandt
comp_id = comp_id
IMPORTING
binary_flg = binary_flg
comp_size = size
mimetype = mimetype
TABLES
data_txt = data_txt
data_bin = data_bin
EXCEPTIONS
error_import = 1
error_config = 2
OTHERS = 3.
Thanks.
‎2011 Oct 11 11:22 AM
Hi,
You can try below code.
TRY.
lr_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_bodytext
i_length = ln_textlength
i_subject = l_subject ).
attdoctype = 'pdf'.
attsize = XSTRLEN( l_pdf ).
pdftab = cl_document_bcs=>xstring_to_solix( ip_xstring = l_pdf ).
lr_document->add_attachment( EXPORTING i_attachment_type = attdoctype
i_attachment_subject = atttitle
i_attachment_size = attsize
i_attachment_language = sy-langu
i_att_content_hex = pdftab ).
send_request = cl_bcs=>create_persistent( ).
send_request->set_document( lr_document ).
Get sender object
sender = cl_sapuser_bcs=>create( sy-uname ).
send_request->set_sender( i_sender = sender ).
recipient = cl_cam_address_bcs=>create_internet_address( ic_email_address ).
send_request->add_recipient( EXPORTING i_recipient = recipient ).
send_request->set_send_immediately( 'X' ).
send_request->send( ).
CATCH cx_bcs INTO lr_bcs_exception.
lc_text = lr_bcs_exception->get_text( ).
MESSAGE lc_text TYPE 'E'.
ENDTRY.
Let me know if this works for you.
Regards,
Rahul Wagh
‎2011 Oct 11 12:55 PM
Hi,
Thanks Rahul. But I had done the required changes that you have written but still some of the pdf attachment is not opening, giving the same error that file is damaged and could not be repaired.
Thanks.
‎2011 Oct 11 1:28 PM
Hi,
Please check the parameter
i_attachment_size = attsize... If the attachment size or file size is small when compared to the actual then the reported error would turn up. Try increasing the file size and check. Although i have not used OO for sending mails....some hint for overcoming this error, hope this helps you.
‎2011 Oct 11 3:01 PM
Hi
Hope this below link will helps you.
http://www.sapdev.co.uk/reporting/rep_spooltopdf.htm
Thanks
kishore