Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Excel Sheet with 2 sheets using XML -- Large size

Hi All,

I had a requirement to send an excel file having 2 sheets as an attachment in background mode.

I have converted the data to XML  using IXML and  ixml_stream_factory classes  and created 2 sheets as required.

The mail is being sent using  SO_NEW_DOCUMENT_ATT_SEND_API1. However the email attachment is of size 30MB as the Excel file is of type XML DATA ( *.xml).

  • When I open the file in MS Excel and do save as .XLS / .XLSX --> the same file is saved with a size of around 3 -4 MB.

  • Below changes / options have been tried to reduce mail size:
  1. Removing the formatting of cells for data -- > This reduced the size but not significantly.
  2. Converting the XML data in L_XML_TABLE to binary  and the using CL_ABAP_ZIP => compress_binary . This was giving garbled data .It may be possible i am not doing this compression in correct way.

Below is the code for sending mail:

*--Creating a Stream Factory

   l_streamfactory = l_ixml->create_stream_factory( ).

*--Connect Internal XML Table to Stream Factory

   l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ).

*--Rendering the Document

   l_renderer = l_ixml->create_renderer( ostream  = l_ostream  document = l_document ).

   l_rc = l_renderer->render( ).

*--Saving the XML Document

   l_xml_size = l_ostream->get_num_written_raw( ).

   ls_doc_chng-obj_descr = text-060.

*--Creation of the Document Attachment

*--  L_XML_TABLE is the converted XML data in RAW format.

*--TYPES: BEGIN OF xml_line,

*--        data(255) TYPE x,

*--    END OF xml_line.

   LOOP AT l_xml_table INTO wa_xml.

     CLEAR ls_objbin.

     ls_objbin-line = wa_xml-data.

     APPEND ls_objbin TO lt_objbin.


   DESCRIBE TABLE lt_objbin LINES tab_lines.

   ls_objhead-line = text-060.

   APPEND ls_objhead TO lt_objhead.

*--Packing List For the E-mail Attachment

   ls_objpack-transf_bin = 'X'.

   ls_objpack-head_start = 1.

   ls_objpack-head_num   = 0.

   ls_objpack-body_start = 1.

   ls_objpack-body_num = tab_lines.


   ls_objpack-doc_type = 'XLS'.

   ls_objpack-doc_size = tab_lines * 255.

   APPEND ls_objpack TO lt_objpack.

*--Target Recipent

   lv_email = gv_high.

   CLEAR ls_reclist.

   ls_reclist-receiver = lv_email.

   ls_reclist-rec_type = 'U'.

   ls_reclist-express = 'X'.

   APPEND ls_reclist TO lt_reclist.

*--Sending the document



       document_data              = ls_doc_chng

       put_in_outbox              = 'X'

       commit_work                = 'X'


       packing_list               = lt_objpack

       object_header              = lt_objhead

       contents_txt               = lt_objtxt

       contents_hex               = lt_objbin

       receivers                  = lt_reclist


       too_many_receivers         = 1

       document_not_sent          = 2

       operation_no_authorization = 4

       OTHERS                     = 99.

Any pointers on how to reduce the mail size will be helpful.


Not what you were looking for? View more on this topic or Ask a question