Skip to Content
avatar image
Former Member

Export to Excel and email the file

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Apr 21, 2010 at 01:57 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • avatar image
    Former Member
    Apr 21, 2010 at 09:58 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.