Skip to Content
author's profile photo Former Member
Former Member

Send Formatted Excel as attachment to email from ABAP

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:


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.



Edited by: Mansi Maskeri on Jul 22, 2010 1:01 PM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Jul 22, 2010 at 11:27 AM

    Hi Mansi,

    Please check the example program "BCS_EXAMPLE_7" in SAP.


    Ankur Parab

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 22, 2010 at 08:58 PM

    See SDN wiki [Sending mails - Home page|].

    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).

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 23, 2016 at 08:32 AM

    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.


    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'.



    * ---------- 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 ).



    buffer = lwa_zhr_planning_att-file_contents


    binary_tab = lt_solix[].

    * add the spread sheet as attachment to document object


    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 = '' ).

    * 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).


    * ---------- explicit 'commit work' is mandatory! ----------------


    * ------------------------------------------------------------------

    * * 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.





    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.