Hi Experts,
I want to send a formatted excel as attachment to email from ABAP. I have used the logic given in the following link:
[http://wiki.sdn.sap.com/wiki/display/ABAP/ExportingdatatoExcel-XMLtotherescue]
Using this logic i am able to download the excel on presentation server correctly. But if i use the same internal table to send email, the attached excel file doesnt open. It gives error that Document setting not suported.
Note that i would have to use XML only, becase OLE would help me in foreground only, whereas my requirement is to run the functionality in background also.
Any suggestions to solve this issue are welcome.
Regards,
Mansi.
Edited by: Mansi Maskeri on Jul 22, 2010 1:01 PM
Hi Mansi,
Please check the example program "BCS_EXAMPLE_7" in SAP.
Regards,
Ankur Parab
See SDN wiki [Sending mails - Home page|http://wiki.sdn.sap.com/wiki/display/ABAP/SendingMails-HomePage].
Only use CL_BCS class (as in BCS_EXAMPLE_7), as recommended by SAP you'll get less problems than with old SO_* function modules.
Note: in place of XML, you could also use XLSX format (starting from Excel 2007), Ivan Femia has written an excellent and easy tool, called abap2xlsx (search the SDN blog with that name).
METHOD send_email.
DATA lwa_zhr_planning_att TYPE zhr_planning_att.
DATA send_request TYPE REF TO cl_bcs.
DATA lp_pdf_size TYPE so_obj_len.
DATA pdf_content TYPE solix_tab.
DATA document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
DATA recipient TYPE REF TO if_recipient_bcs.
DATA: bcs_exception TYPE REF TO cx_bcs.
DATA sent_to_all TYPE os_boolean.
DATA lt_solix TYPE solix_tab.
DATA subject TYPE so_obj_des.
DATA lv_attachment_type TYPE soodk-objtp.
*Send email message, although is not sent from SAP until mail send
SELECT SINGLE * FROM zhr_planning_att INTO lwa_zhr_planning_att where ZFILE_NUMBER = ZFILE_NUMBER.
IF sy-subrc = 0.
BREAK-POINT.
CASE lwa_zhr_planning_att-file_type.
WHEN 'text/plain'.
lv_attachment_type = 'TXT'.
WHEN 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'.
lv_attachment_type = 'DOC'.
WHEN 'application/pdf'.
lv_attachment_type = 'PDF'.
WHEN 'image/jpeg'.
lv_attachment_type = 'JPG'.
WHEN 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.
lv_attachment_type = 'XLS'.
ENDCASE.
TRY.
* ---------- create persistent send request ----------------------
send_request = cl_bcs=>create_persistent( ).
* Message body and subject
subject = 'HR PLANNING NOTE TB3'.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = LT_message_body
i_subject = subject ).
* ---------- add document ----------------------------------------
* get PDF xstring and convert it to BCS format
lp_pdf_size = xstrlen( lwa_zhr_planning_att-file_contents ).
pdf_content = cl_document_bcs=>xstring_to_solix(
ip_xstring = lwa_zhr_planning_att-file_contents ).
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lwa_zhr_planning_att-file_contents
TABLES
binary_tab = lt_solix[].
* add the spread sheet as attachment to document object
document->add_attachment(
i_attachment_type = lv_attachment_type "#EC NOTEXT
i_attachment_subject = 'HR PLANNING DOCUMENT' "#EC NOTEXT
i_attachment_size = lp_pdf_size
i_att_content_hex = lt_solix[] ). "pdf_content )."binary_content ).
* document = cl_document_bcs=>create_document(
* i_type = 'PDF'
* i_hex = pdf_content
* i_length = lp_pdf_size
* i_subject = 'HR PLANNING BCS WORD TEST' ).
* add document to send request
send_request->set_document( document ).
* ---------- add recipient (e-mail address) ----------------------
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = 'jitendra.yadav@company.com' ).
* add recipient to send request
send_request->add_recipient( i_recipient = recipient ).
* ---------- send document ---------------------------------------
sent_to_all = send_request->send(
i_with_error_screen = 'X' ).
IF sent_to_all = 'X'.
MESSAGE i022(so).
ENDIF.
* ---------- explicit 'commit work' is mandatory! ----------------
COMMIT WORK.
* ------------------------------------------------------------------
* * exception handling
* ------------------------------------------------------------------
* * replace this very rudimentary exception handling
* * with your own one !!!
* ------------------------------------------------------------------
CATCH cx_bcs INTO bcs_exception.
WRITE: text-001.
WRITE: text-002, bcs_exception->error_type.
EXIT.
ENDTRY.
ENDIF.
ENDMETHOD.
Add a comment