2012 Jul 24 11:51 AM
Hi,
I am getting corrupted *.xlsx file if i follow the Note 1459896 to send it as an attachment through CL_BCS and CL_DOCUMENT_BCS. Could someone help in this and tell me how to send *.xlsx file as an attachment in emails. I have searched for this in the following posts but unsuccessful
http://scn.sap.com/thread/2111909
http://scn.sap.com/thread/1828791
http://wiki.sdn.sap.com/wiki/display/ABAP/Sending+Mails+-+Home+Page
Thanks
Srikanth.
2012 Jul 28 7:42 PM
2012 Jul 31 6:45 AM
Hi Clemens,
Here is the code
<code>
FORM send_email USING iv_xml TYPE xstring
iv_mailto TYPE ad_smtpadr
CHANGING cv_sent TYPE os_boolean.
DATA: lv_isize TYPE i,
lv_size TYPE c LENGTH 12,
lv_name TYPE TDOBNAME,
lv_subject TYPE so_obj_des,
lv_subject_att TYPE so_obj_des,
lv_string TYPE string,
ld_line TYPE REF TO tline,
lt_lines TYPE TABLE OF tline,
lt_text TYPE soli_tab,
ls_text like line of lt_text,
lt_att_head type soli_tab,
lv_filename type string,
lt_solix TYPE solix_tab.
DATA: lo_send_request TYPE REF TO cl_bcs,
lo_document TYPE REF TO cl_document_bcs,
lo_recipient TYPE REF TO if_recipient_bcs,
lx_error TYPE REF TO cx_root.
lv_subject = sy-cprog.
lv_name = sy-cprog.
TRY.
lo_send_request = cl_bcs=>create_persistent( ).
clear ls_text.
ls_text-line = 'Test text'.
APPEND ls_text to lt_text.
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_text[]
i_subject = lv_subject ).
lv_isize = XSTRLEN( iv_xml ).
lt_solix[] = cl_document_bcs=>xstring_to_solix( iv_xml ).
* as per note 1459896
* four character file extension '.text' is set
lv_filename = 'AttachmentFilename.text'.
concatenate '&SO_FILENAME='
lv_filename into lv_text_line.
append lv_text_line to lt_att_head.
* add the spread sheet as attachment to document object
lv_size = lv_isize.
lo_document->add_attachment(
i_attachment_type = 'XLS' "#EC NOTEXT
i_attachment_subject = lv_subject_att
i_attachment_size = lv_size
i_att_content_hex = lt_solix[]
i_attachment_header = lt_att_head ).
* add document object to send request
lo_send_request->set_document( lo_document ).
lo_recipient = cl_cam_address_bcs=>create_internet_address( iv_mailto ).
lo_send_request->add_recipient( lo_recipient ).
cv_sent = lo_send_request->send( ).
CATCH cx_root INTO lx_error.
lv_string = lx_error->get_text( ).
MESSAGE lv_string TYPE 'E'.
ENDTRY.
COMMIT WORK.
ENDFORM. "send_email
</code>
I am trying to incorporate the changes described in the Note 1459896 for attaching the files in *.xlsx format in the above code.
Thanks
Srikanth
2012 Jul 31 8:06 AM
you can provide code as follows:
* Add Attachment
CALL METHOD lo_document->add_attachment
EXPORTING
i_attachment_type = 'BIN'
* i_attachment_subject = lv_attach_subject
* i_attachment_size = lv_attach_size
i_attachment_language = 'E'
i_att_content_hex = lt_stream.
if you want just provide its size also.
This may help you...
complete code as follows::
TRY.
* Create persistent send request
lo_send_request = cl_bcs=>create_persistent( ).
lo_send_request->set_message_subject( ip_subject = lv_long_subject ).
* Create the content document
lv_short_subject = lv_long_subject.
lv_email_length = ( lv_email_lines - 1 ) * 255 + STRLEN( ls_email_txt ).
lo_sender = cl_cam_address_bcs=>create_internet_address( lv_sender ).
lo_document = cl_document_bcs=>create_document(
i_type = 'HTM'
i_text = lt_email_txt
i_length = lv_email_length
i_subject = lv_short_subject
i_language = 'E'
i_importance = '5' ).
lo_send_request->set_sender( i_sender = lo_sender ).
* Add document object to send request
lo_send_request->set_document( lo_document ).
* Add recipients
lv_receipient = "recipient email id.
lo_recipient = cl_cam_address_bcs=>create_internet_address( lv_receipient ).
* Add recipient with its respective attributes to send request
CALL METHOD lo_send_request->add_recipient
EXPORTING
i_recipient = lo_recipient
i_express = 'X'.
DATA:
l_length TYPE i,
lt_stream TYPE solix_tab. " etxml_xline_tabtype,
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = pv_xstring
IMPORTING
output_length = l_length
TABLES
binary_tab = lt_stream.
lv_attach_size = l_length.
* Add Attachment
CALL METHOD lo_document->add_attachment
EXPORTING
i_attachment_type = 'BIN'
* i_attachment_subject = lv_attach_subject
* i_attachment_size = lv_attach_size
i_attachment_language = 'E'
i_att_content_hex = lt_stream.
* Set that you don't need a Return Status E-mail
lv_status_mail = lv_requested_status = 'N'. " No Status
CALL METHOD lo_send_request->set_status_attributes
EXPORTING
i_requested_status = lv_requested_status
i_status_mail = lv_status_mail.
* Set send immediately flag
lo_send_request->set_send_immediately( 'X' ).
* Send document
lv_sent_to_all = lo_send_request->send( i_with_error_screen = 'X' ).
IF lv_sent_to_all IS INITIAL. "#EC NEEDED
ENDIF.
* Catch Exception if any
CATCH cx_bcs INTO lx_bcs_exception.
IF lx_bcs_exception IS NOT INITIAL.
ENDIF.
ENDTRY.
IF lv_sent_to_all = 'X'.
COMMIT WORK.
ENDIF.
Thanx,
2012 Oct 12 5:09 AM
Make use of next one http://www.recoverytoolbox.com/excel.html it will restore *.xls, *,xlt, *.xlsx, xlsm, *.xltm, *.xltx, *.xlam file formats