cancel
Showing results for 
Search instead for 
Did you mean: 

Export to Excel and email the file

Former Member
0 Kudos

Hello Everyone,

My requirement is to Email an internal table as an Excel sheet. I had a look on SDN for quite a while and am giving up now. There are so many questions about exporting to Excel. But, I need to email the internal table as an excel sheet. Would anyone be able to help me to resolve this issue. I would greatly appreciate your help.

Regards,

Gopal.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Alternatively you can use the standard ABAP class cl_bcs (Business Communication services) to send the email with attachment. Attachment can be added using the below code-

CALL METHOD document->add_attachment
            EXPORTING
              i_attachment_type    = ls_attachments-file_type
              i_attachment_subject = ls_attachments-file_name
              i_att_content_hex    = ls_attachments-attachx[].

As excel file is a BINARY document, you need to pass the binary data. Refer to the my article below for more details:

http://divulgesap.com/blog.php?p=ODI=

Regards,

Ravikiran

Former Member
0 Kudos

Hi Ravikiran,

Thanks a lot for your reply. I managed to get it working by using the above suggested FM. Now, I have another requirement, where I need to pass headings for the columns of the Excel sheet that I am emailing. Would you be able to suggest me of how to acheive this. i would greatly appreciate your help.

Regards,

Gopal.

Former Member
0 Kudos

Hi Gopal,

You can get the components in your internal table using the below code-

lo_struc_descr ?= cl_abap_typedescr=>describe_by_data( <fs_line> ).
    lt_components = lo_struc_descr->get_components( ).
* Insert the component names in the start of the file
    LOOP AT lt_components INTO ls_components.
      IF lv_string IS INITIAL.
        lv_string = ls_components-name.
      ELSE.
        CONCATENATE lv_string ls_components-name INTO lv_string
        SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
      ENDIF.
    ENDLOOP.

Here <fs_line> is a work area. Basically we are getting all the fields in the internal table and writing their names in the start of the file.

Hope it helps.

Regards,

Ravi

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Please follow these steps :

1. Get the data into an internal table.

2. Use this FM to convert the data into Xstring :

'SCMS_STRING_TO_XSTRING'

3. Finally attach the Xstring Format of the Excel with the method to send mail as an attachment:

cl_hrrcf_services_mail=>send_web_mail.

i hope it helps.

Former Member
0 Kudos

Hi Saurav,

Thanks a lot for your reply. I tried to use the class "cl_hrrcf_services_mail=>send_web_mail". But, when I attach the attachment which is of type "XSTRING" to "PT_ATTA_HEX" which is of type "RCF_T_ATT4MAIL_HEX" it is giving a "type incompatible error" message. Could you please help me in resolving this error. I would greatly appreciate your help.

Regards,

Gopal.

Former Member
0 Kudos

Hi,

Please pass the extension of the file also with the rcf_s_att4mail_hex like :

DATA : at TYPE rcf_s_att4mail_hex,
         at_t TYPE TABLE OF rcf_s_att4mail_hex.
at-content = Xstring Data .
at-extension  = file Extension.
  APPEND at TO at_t.

Now pass at_t to the FM.