<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: problem in excel format while sending mail with excel attachment. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895977#M680809</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am encountering the same error in our program. The program is sending a text file with .XLS format and sent via email. The problem with the file when opened in Excel is that there are some Portuguese characters not displayed properly. What I did is to add encoding '4103' (UTF-16LE) to CALL FUNCTION 'SCMS_STRING_TO_XSTRING'. As a result, the Excel file now displays the Portuguese characters correctly. However the side effect is that the pop up message from Excel displays warning message 'File is not recognizable format...'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After doing research, I found one wiki telling that Excel uses prefix FFFE at the beginning of a UTF-16LE file to identify that the file is in that format. So what I did is I added FFFE at the beginning of my string before sending it in the email. As a result Excel no longer shows the warning message when opening the UTF-16LE file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code that creates FFFE character representation&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  DATA: o_conv TYPE REF TO cl_abap_conv_in_ce,
        v_prefix TYPE c.

  CONSTANTS: c_hex(2) TYPE x VALUE 'FFFE'.

  o_conv = cl_abap_conv_in_ce=&amp;gt;create( encoding = '4103' ).

  CALL METHOD o_conv-&amp;gt;convert
    EXPORTING
      input           = c_hex
    IMPORTING
      data            = v_prefix.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code that adds the FFFE prefix to the long string. Variable L_STRING containts the entire data that will be displayed in Excel. It contains carriage return and horizontal_tabs as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  CONCATENATE v_prefix
              l_string
  into l_string.

  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text           = l_string
   encoding       = '4103'
   IMPORTING
     buffer         = l_xstring
   EXCEPTIONS
     failed         = 1
     OTHERS         = 2
            .
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The XSTRING is converted to BINARY. The binary internal table is the one added to the SO_NEW_DOCUMENT_ATT_SEND_API1 function module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  REFRESH it_objbin.
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer        = l_xstring
    IMPORTING
      output_length = l_len
    TABLES
      binary_tab    = it_objbin.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 19 Oct 2010 15:10:01 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-10-19T15:10:01Z</dc:date>
    <item>
      <title>problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895963#M680795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gurus ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am sending a email with Excel attachment using FM SO_DOCUMENT_SEND_API1 or SO_NEW_DOCUMENT_ATT_SEND_API1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am able to send a mail with excel attachment with a piece of code which I got from SDN itself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But the problem is when I am trying to open the attachment, &amp;lt;b&amp;gt;A pop up comes which says that it is not in recognizable format. Would you like to open it?&lt;/P&gt;&lt;P&gt;and several other lines of caution.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When i choose to open it, i get the correct data in one excel sheet. Certain vertical lines of the excel sheet is missing. &amp;lt;b&amp;gt;But no data is missing. &amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am attaching the code below. Can any one please tell me where is the problem in this code ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanx in advance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
types: begin of t_mara,
matnr type mara-matnr,
matkl type mara-matkl,
mtart type mara-mtart,
meins type mara-meins,
end of t_mara.
 
 
data: gt_mara type table of t_mara,
wa_mara like line of gt_mara,
it_packing_list type table of SOPCKLSTI1,
wa_packing_list like line of it_packing_list,
it_receivers type table of SOMLRECI1,
wa_receivers like line of it_receivers,
it_mailbody type table of SOLISTI1,
wa_mailbody like line of it_mailbody,
it_attachment type table of SOLISTI1,
wa_attachment like line of it_attachment.
 
data: la_doc type SODOCCHGI1.
 
constants:
con_tab type c value cl_abap_char_utilities=&amp;gt;HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=&amp;gt;CR_LF.
 
* get material
select matnr matkl mtart meins
into table gt_mara
from mara
up to 25 rows.
 
 
* Populate the subject/generic message attributes
la_doc-obj_langu = sy-langu.
la_doc-obj_descr = 'Material Details' . "Mail Header
la_doc-sensitivty = 'F'.
la_doc-doc_size = 1.
 
* Add the recipients email address
CLEAR wa_receivers.
REFRESH it_receivers.
wa_receivers-receiver = 'PCSDEVL'.
wa_receivers-rec_type = 'U'.
wa_receivers-com_type = 'INT'.
wa_receivers-notif_del = 'X'.
wa_receivers-notif_ndel = 'X'.
APPEND wa_receivers to it_receivers.
 
* Mail Body
CLEAR wa_mailbody.
REFRESH it_mailbody.
wa_mailbody-line = 'Please find the attachment'.
APPEND wa_mailbody to it_mailbody.
 
* Mail attachmwnt
CLEAR wa_attachment.
REFRESH it_attachment.
 
CONCATENATE 'MATNR' 'MATKL' 'MTART' 'MEINS'
INTO wa_attachment SEPARATED BY con_tab.
CONCATENATE con_cret wa_attachment INTO wa_attachment.
APPEND wa_attachment to it_attachment.
 
LOOP AT gt_mara INTO wa_mara.
CONCATENATE wa_mara-matnr wa_mara-matkl
wa_mara-mtart wa_mara-meins
INTO wa_attachment SEPARATED BY con_tab.
CONCATENATE con_cret wa_attachment INTO wa_attachment.
APPEND wa_attachment to it_attachment.
ENDLOOP.
 
 
* Describe the body of the message
CLEAR wa_packing_list.
REFRESH it_packing_list.
wa_packing_list-transf_bin = space.
wa_packing_list-head_start = 1.
wa_packing_list-head_num = 0.
wa_packing_list-body_start = 1.
wa_packing_list-body_num = 1.
wa_packing_list-doc_type = 'RAW'.
APPEND wa_packing_list to it_packing_list.
 
* Create attachment notification
wa_packing_list-transf_bin = 'X'.
wa_packing_list-head_start = 1.
wa_packing_list-head_num = 1.
wa_packing_list-body_start = 1.
 
DESCRIBE TABLE it_attachment LINES wa_packing_list-body_num.
wa_packing_list-doc_type = 'XLS'. " To word attachment change this as 'DOC'
wa_packing_list-obj_descr = ' '.
concatenate wa_packing_list-doc_type 'file' into wa_packing_list-OBJ_DESCR
separated by space.
wa_packing_list-doc_size = wa_packing_list-body_num * 255.
APPEND wa_packing_list to it_packing_list.
 
 
 
 
 
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = la_doc
PUT_IN_OUTBOX = 'X'
* SENDER_ADDRESS = SY-UNAME
* SENDER_ADDRESS_TYPE = 'B'
COMMIT_WORK = 'X'
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
* SENDER_ID =
tables
packing_list = it_packing_list
* OBJECT_HEADER =
CONTENTS_BIN = it_attachment
CONTENTS_TXT = it_mailbody
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
receivers = it_receivers
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8
.
IF sy-subrc &amp;lt;&amp;gt; 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2007 11:24:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895963#M680795</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-12T11:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895964#M680796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi raveesh,&lt;/P&gt;&lt;P&gt;              I want to know whether your problem has been solved or not as I am facing the same problem in mail sending using excel attachment.If your probelm is solved pls write the solution.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2007 03:04:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895964#M680796</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-29T03:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895965#M680797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi raveesh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if your problem is already answered, please provide a solution. i am encountering the same error and i don't know what part of the code should be changed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;jim&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Dec 2007 08:58:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895965#M680797</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-27T08:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895966#M680798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;REPORT  Zex5 LINE-SIZE 255 LINE-COUNT 255 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;class CL_ABAP_CHAR_UTILITIES definition load. "--&amp;gt; &lt;/P&gt;&lt;P&gt;TABLES : vbap.&lt;/P&gt;&lt;P&gt;SELECT-OPTIONS: s_vbeln FOR vbap-vbeln.&lt;/P&gt;&lt;P&gt;DATA : BEGIN OF itab OCCURS 1,&lt;/P&gt;&lt;P&gt;       vbeln LIKE vbap-vbeln,&lt;/P&gt;&lt;P&gt;       posnr LIKE vbap-posnr,&lt;/P&gt;&lt;P&gt;       matnr LIKE vbap-matnr,&lt;/P&gt;&lt;P&gt;       END OF itab.&lt;/P&gt;&lt;P&gt;parameters : p_email like somlreci1-receiver&lt;/P&gt;&lt;P&gt;DATA: tlines type i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: itmessage   LIKE solisti1 OCCURS 1 WITH HEADER LINE. "Ok&lt;/P&gt;&lt;P&gt;DATA: itattach    LIKE solisti1 OCCURS 2 WITH HEADER LINE. "Ok&lt;/P&gt;&lt;P&gt;DATA: itpacklist  LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.&lt;/P&gt;&lt;P&gt;DATA: itreclist   LIKE somlreci1 OCCURS 5 WITH HEADER LINE.&lt;/P&gt;&lt;P&gt;data: itattachment like solisti1 OCCURS 2 WITH HEADER LINE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;start-of-selection.&lt;/P&gt;&lt;P&gt;  SELECT vbeln posnr matnr&lt;/P&gt;&lt;P&gt;         FROM vbap&lt;/P&gt;&lt;P&gt;         INTO TABLE itab&lt;/P&gt;&lt;P&gt;         WHERE vbeln IN s_vbeln.&lt;/P&gt;&lt;P&gt;**Make the internal table data to be compatible in excel format .&lt;/P&gt;&lt;P&gt;  PERFORM BUILD_XLS_FORMAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**Populate message of body text.&lt;/P&gt;&lt;P&gt;  clear itmessage.&lt;/P&gt;&lt;P&gt;  refresh itmessage.&lt;/P&gt;&lt;P&gt;  itmessage = 'Please find attached Excel file'.&lt;/P&gt;&lt;P&gt;  append itmessage.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  PERFORM send_mail_as_xls_attachment tables itmessage&lt;/P&gt;&lt;P&gt;                                             itattach&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;         using p_email 'Excel Attachment' 'TXT'    " 'XLS'&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;          using p_email 'TEXT Attachment' 'TXT'    " 'XLS'&lt;/P&gt;&lt;P&gt;                        'TestFileName'&lt;/P&gt;&lt;P&gt;                        'SalesOrders' .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  BUILD_XLS_FORMAT&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; --&amp;gt;  p1        text&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; &amp;lt;--  p2        text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form BUILD_XLS_FORMAT.&lt;/P&gt;&lt;P&gt;previosuly we were using for unicode ..now replaced&lt;/P&gt;&lt;P&gt;**Declare constants for the spacing .&lt;/P&gt;&lt;P&gt;*Constants : con1 type x value '0D',&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;           con2 type x value '09'.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  Constants : con1 type c&lt;/P&gt;&lt;P&gt;        value CL_ABAP_CHAR_UTILITIES=&amp;gt;CR_LF,&lt;/P&gt;&lt;P&gt;        con2 type c&lt;/P&gt;&lt;P&gt;        value CL_ABAP_CHAR_UTILITIES=&amp;gt;HORIZONTAL_TAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**For the Header descriptions.&lt;/P&gt;&lt;P&gt;  Concatenate 'SalesORdNo'&lt;/P&gt;&lt;P&gt;              'Item'&lt;/P&gt;&lt;P&gt;              'Materialno' into itattach separated by con2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Concatenate con1 itattach into itattach.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Append itattach.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**Now align the items in the itab as above .&lt;/P&gt;&lt;P&gt;  Loop at Itab.&lt;/P&gt;&lt;P&gt;    concatenate itab-vbeln&lt;/P&gt;&lt;P&gt;                itab-posnr&lt;/P&gt;&lt;P&gt;                itab-matnr into itattach separated by con2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    concatenate con1 itattach into itattach .&lt;/P&gt;&lt;P&gt;    Append itattach.&lt;/P&gt;&lt;P&gt;  endloop.&lt;/P&gt;&lt;P&gt;endform.                    " BUILD_XLS_FORMAT&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  send_mail_as_xls_attachment&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     --&amp;gt;P_ITMESSAGE  text&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     --&amp;gt;P_ITATTACH  text&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     --&amp;gt;P_P_EMAIL  text&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     --&amp;gt;P_0116   text&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     --&amp;gt;P_0117   text&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     --&amp;gt;P_0118   text&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;     --&amp;gt;P_0119   text&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form send_mail_as_xls_attachment tables   p_itmessage&lt;/P&gt;&lt;P&gt;                                          p_itattach&lt;/P&gt;&lt;P&gt;                                 using    p_email&lt;/P&gt;&lt;P&gt;                                          p_mtitle&lt;/P&gt;&lt;P&gt;                                          p_format&lt;/P&gt;&lt;P&gt;                                          p_filename&lt;/P&gt;&lt;P&gt;                                          p_attdescription.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Data : xdocdata like sodocchgi1,&lt;/P&gt;&lt;P&gt;         xcnt type i.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Fill the document data.&lt;/P&gt;&lt;P&gt;  xdocdata-doc_size = 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Populate the subject/generic message attributes.&lt;/P&gt;&lt;P&gt;  xdocdata-obj_name  = 'SAPRPT'.&lt;/P&gt;&lt;P&gt;  xdocdata-obj_langu = sy-langu.&lt;/P&gt;&lt;P&gt;  xdocdata-obj_descr = p_mtitle.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Fill the document data and fetch size of attachment.&lt;/P&gt;&lt;P&gt;  clear xdocdata.&lt;/P&gt;&lt;P&gt;  read table itattach index xcnt.&lt;/P&gt;&lt;P&gt;  xdocdata-doc_size = ( xcnt - 1 ) * 255 + strlen( itattach ).&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; xdocdata-doc_size =  ( xcnt - 1 ) * 255.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  xdocdata-obj_name  = 'SAPRPT'.&lt;/P&gt;&lt;P&gt;  xdocdata-obj_langu = sy-langu.&lt;/P&gt;&lt;P&gt;  xdocdata-obj_descr = p_mtitle.&lt;/P&gt;&lt;P&gt;  clear itattachment. refresh itattachment.&lt;/P&gt;&lt;P&gt;     itattachment[] = p_itattach[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Describe the body of the message.&lt;/P&gt;&lt;P&gt;  clear itpacklist. refresh itpacklist.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  itpacklist-transf_bin = 'X'.&lt;/P&gt;&lt;P&gt;  itpacklist-head_start = '1'.&lt;/P&gt;&lt;P&gt;  itpacklist-head_num = '0'.&lt;/P&gt;&lt;P&gt;  itpacklist-body_start = '1'.&lt;/P&gt;&lt;P&gt;  describe table itattachment lines itpacklist-body_num .&lt;/P&gt;&lt;P&gt;  itpacklist-doc_type = 'TXT'.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; itpacklist-doc_type = 'XLS'.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  append itpacklist.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Create attachment notification.&lt;/P&gt;&lt;P&gt;  itpacklist-transf_bin = 'X'.&lt;/P&gt;&lt;P&gt;  itpacklist-head_start = '1'.&lt;/P&gt;&lt;P&gt;  itpacklist-head_num = '1'.&lt;/P&gt;&lt;P&gt;  itpacklist-body_start = '1'.&lt;/P&gt;&lt;P&gt;  describe table itattachment lines itpacklist-body_num .&lt;/P&gt;&lt;P&gt;  itpacklist-doc_type = p_format.&lt;/P&gt;&lt;P&gt;  itpacklist-obj_name = p_filename.&lt;/P&gt;&lt;P&gt;  itpacklist-obj_descr = p_attdescription.&lt;/P&gt;&lt;P&gt;  itpacklist-doc_size = itpacklist-body_num * 255 .&lt;/P&gt;&lt;P&gt;  append itpacklist.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*FIll the receivers list.&lt;/P&gt;&lt;P&gt;  Clear itreclist. refresh itreclist.&lt;/P&gt;&lt;P&gt;  itreclist-receiver = p_email.&lt;/P&gt;&lt;P&gt;  itreclist-rec_type = 'U'.&lt;/P&gt;&lt;P&gt;  itreclist-com_type = 'INT'.&lt;/P&gt;&lt;P&gt;  itreclist-notif_del = 'X'.&lt;/P&gt;&lt;P&gt;  itreclist-notif_ndel = 'X'.&lt;/P&gt;&lt;P&gt;*itreclist-notif_read = 'X'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  append itreclist.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*CALL FUNCTION 'SO_DOCUMENT_SEND_API1'&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; EXPORTING&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  document_data                    = xdocdata&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  PUT_IN_OUTBOX                    = 'X'&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  commit_work    = 'X'&lt;/P&gt;&lt;/LI&gt;&lt;UL&gt;&lt;LI level="2" type="ul"&gt;&lt;P&gt;  SENDER_ADDRESS                   = SY-UNAME&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; tables&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   packing_list                    = itpacklist&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   CONTENTS_BIN                    = itattachment&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   CONTENTS_TXT                    = itmessage&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;   receivers                       = itreclist&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;EXCEPTIONS&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  TOO_MANY_RECEIVERS               = 1&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  DOCUMENT_NOT_SENT                = 2&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  DOCUMENT_TYPE_NOT_EXIST          = 3&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  OPERATION_NO_AUTHORIZATION       = 4&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  PARAMETER_ERROR                  = 5&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  X_ERROR                          = 6&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  ENQUEUE_ERROR                    = 7&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  OTHERS                           = 8&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;         .&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;*IF sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;*ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'&lt;/P&gt;&lt;P&gt;    EXPORTING&lt;/P&gt;&lt;P&gt;      document_data              = xdocdata&lt;/P&gt;&lt;P&gt;      PUT_IN_OUTBOX              = 'X'&lt;/P&gt;&lt;P&gt;    TABLES&lt;/P&gt;&lt;P&gt;      packing_list               = itpacklist&lt;/P&gt;&lt;P&gt;      CONTENTS_BIN               = itattachment&lt;/P&gt;&lt;P&gt;      CONTENTS_TXT               = itmessage&lt;/P&gt;&lt;P&gt;      receivers                  = itreclist&lt;/P&gt;&lt;P&gt;    EXCEPTIONS&lt;/P&gt;&lt;P&gt;      TOO_MANY_RECEIVERS         = 1&lt;/P&gt;&lt;P&gt;      DOCUMENT_NOT_SENT          = 2&lt;/P&gt;&lt;P&gt;      DOCUMENT_TYPE_NOT_EXIST    = 3&lt;/P&gt;&lt;P&gt;      OPERATION_NO_AUTHORIZATION = 4&lt;/P&gt;&lt;P&gt;      PARAMETER_ERROR            = 5&lt;/P&gt;&lt;P&gt;      X_ERROR                    = 6&lt;/P&gt;&lt;P&gt;      ENQUEUE_ERROR              = 7&lt;/P&gt;&lt;P&gt;      OTHERS                     = 8.&lt;/P&gt;&lt;P&gt;  IF sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO&lt;/P&gt;&lt;P&gt;            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endform.                    " send_mail_as_xls_attachment&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just execute the above code and let me know.&lt;/P&gt;&lt;P&gt;What is the sap version u r using . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vijay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Dec 2007 09:07:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895966#M680798</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-27T09:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895967#M680799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi vijay,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;we are using 4.7. &lt;/P&gt;&lt;P&gt;i keep on encountering the error message when the attachement is opened. please advice what should be changed in my code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;super thanks!&lt;/P&gt;&lt;P&gt;jim&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Jim Eric  Tibayan on Jan 2, 2008 4:26 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Dec 2007 09:14:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895967#M680799</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-27T09:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895968#M680800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jim , &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if u r able to send an excel attachment with my code . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The general problem is in excel attachement issues u need to do the coding in the itattach(of code  ) where u r populating the values by a separator .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my code u can see this in Concatenate statement as Con1 and con2 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When a unicode check is there u need to set them from the class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This was missing in ur code which was prompting as file attachment error .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cause in Excel u need to drop the values by columns and u need to separate the fields .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope if u can change the code accordingly witrh reference to my code cause i have used this in 4.7&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just let me know if my code is working for u .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vijay&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Dec 2007 09:38:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895968#M680800</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-27T09:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895969#M680801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi vijay,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; im still getting the error message. im getting desperate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please help.&lt;/P&gt;&lt;P&gt;jim&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Jim Eric  Tibayan on Jan 2, 2008 4:20 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Dec 2007 09:45:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895969#M680801</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-27T09:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895970#M680802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jim send me ur code in word document to my id as an attachment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Send me the complete code ok.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Btw u didnt answer whether my code was working in ur system or not.&lt;/P&gt;&lt;P&gt;my id is&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;lt;REMOVED BY MODERATOR&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will look into the changes..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vijay&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Alvaro Tejada Galindo on Mar 10, 2008 1:40 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Dec 2007 09:53:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895970#M680802</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-27T09:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895971#M680803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i created a temporary program using your code and i got the same error when i opened the attachment. &lt;SPAN __jive_emoticon_name="sad"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks. &lt;/P&gt;&lt;P&gt;jim&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Jim Eric  Tibayan on Jan 2, 2008 4:25 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Dec 2007 10:25:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895971#M680803</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-27T10:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895972#M680804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi vijay,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;have you received my note?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;jim&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Dec 2007 04:57:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895972#M680804</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-28T04:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895973#M680805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi vijay,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tested your code. It is giving the same error to me as mentioned in the start of the thread.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think it may be related to version of excel that we are having in our PCs. Can you please help me out on this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Raveesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 28 Dec 2007 08:43:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895973#M680805</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-28T08:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895974#M680806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So what is the final solution to this problem? &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2008 15:03:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895974#M680806</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-10T15:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895975#M680807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I use this for sending HTML File and two PDF files.  Where I use the file type as PDF, try using XLS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT yptc_send_mail4 .

CONSTANTS:
  fname(132) TYPE c VALUE
    '\\wiicorp_fs1\sap\INTERFACES\Dev\Paul\SAP_Test2.txt',
  attach1(132) TYPE c VALUE
    '\\wiicorp_fs1\sap\INTERFACES\Dev\Paul\Exhibit_A.pdf',             " &amp;lt;========= Change to your 1st XLS
  attach2(132) TYPE c VALUE
    '\\wiicorp_fs1\sap\INTERFACES\Dev\Paul\Exhibit_B.pdf'.             " &amp;lt;========= Change to your 2nd XLS
DATA:
  doc_start(15)      TYPE n,
  attach(132)        TYPE c,
  wk_rec(255)        TYPE c,
  t_error            TYPE c,
  t_mesg             LIKE t100-text.

DATA:
  i_objpack LIKE STANDARD TABLE " Packing list
    OF sopcklsti1
    INITIAL SIZE 0 WITH HEADER LINE,

  i_objbin LIKE STANDARD TABLE " Contents in binary format
          OF solisti1
        INITIAL SIZE 0
        WITH HEADER LINE,

  i_objtxt LIKE STANDARD TABLE " Contents in Text format
          OF solisti1
        INITIAL SIZE 0
        WITH HEADER LINE,

  w_objbin LIKE STANDARD TABLE " Contents in binary format
          OF solisti1
        INITIAL SIZE 0
        WITH HEADER LINE,

  i_reclist LIKE STANDARD TABLE " Recipients list
        OF somlreci1
        INITIAL SIZE 0
        WITH HEADER LINE.

DATA: w_tab_lines LIKE sy-tabix. " No. of lines


* Here Fill in the recipient list in table with I_reclist with receiver
* type as "U" (i_reclist-rec_type = 'U') for Internet addresses.

DATA: lfs_doc_chng LIKE sodocchgi1. " Mail attributes

START-OF-SELECTION.
  i_reclist-receiver = 'yada@yada.com'.
  i_reclist-rec_type = 'U'.
  APPEND i_reclist.
*
  CLEAR doc_start.
  lfs_doc_chng-obj_descr = 'Mail with attachment'.

  PERFORM mail_contents.

  i_objpack-head_start = 1.
  i_objpack-head_num = 0.
  i_objpack-body_start = 1.
  i_objpack-body_num = w_tab_lines.
  i_objpack-doc_type = 'HTM'.
  APPEND i_objpack.

  CLEAR: w_tab_lines.
*  doc_start = doc_start + w_tab_lines.

* Here Store the contents of the attachment to be sent in the table
* i_objbin.


  attach = attach1.
  PERFORM mail_attachments.

  i_objpack-transf_bin = 'X'.
  i_objpack-head_start = 1.
  i_objpack-head_num = 1.
  i_objpack-body_start = doc_start.
  i_objpack-body_num = w_tab_lines.
  i_objpack-doc_type = 'PDF'.            " &amp;lt;========= Change to XLS
  i_objpack-obj_descr = 'Exhibit A Desc'.
  i_objpack-obj_name = ' Exhibit A'.
  i_objpack-doc_size = w_tab_lines * 255.
  APPEND i_objpack.

  doc_start = doc_start + w_tab_lines.


  attach = attach2.
  PERFORM mail_attachments.

  i_objpack-transf_bin = 'X'.
  i_objpack-head_start = 1.
  i_objpack-head_num = 1.
  i_objpack-body_start = doc_start.
  i_objpack-body_num = w_tab_lines.
  i_objpack-doc_type = 'PDF'.            " &amp;lt;========= Change to XLS
  i_objpack-obj_descr = 'Exhibit B Desc'.
  i_objpack-obj_name = ' Exhibit B'.
  i_objpack-doc_size = w_tab_lines * 255.
  APPEND i_objpack.

*  EXIT.

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
       EXPORTING
            document_data              = lfs_doc_chng
            put_in_outbox              = 'X'
       TABLES
            packing_list               = i_objpack
            contents_bin               = i_objbin
            contents_txt               = i_objtxt
            receivers                  = i_reclist
       EXCEPTIONS
            too_many_receivers         = 1
            document_not_sent          = 2
            document_type_not_exist    = 3
            operation_no_authorization = 4
            parameter_error            = 5
            x_error                    = 6
            enqueue_error              = 7
            OTHERS                     = 8.

  CASE sy-subrc.
    WHEN 0.
*    MESSAGE s017 WITH 'Email sent'(053).
      WRITE:/ 'Email sent'.

      SUBMIT rsconn01 WITH mode = 'INT'
      WITH output = 'X'
      AND RETURN.

    WHEN OTHERS.
*    MESSAGE i017 WITH 'Mail delivery unsuccessful'(049).
      WRITE:/ 'Mail delivery unsuccessful'.
  ENDCASE. " CASE sy-subrc.
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  mail_attachments
*&amp;amp;---------------------------------------------------------------------*
FORM mail_attachments.
  REFRESH w_objbin.

  OPEN DATASET attach FOR INPUT IN BINARY MODE MESSAGE t_mesg.

  IF sy-subrc NE 0.
    WRITE:/ 'Attachment Dataset Open RC ',sy-subrc.
    WRITE:/ 'Message ',t_mesg.
    EXIT.
  ENDIF.

  DO.
    READ DATASET attach INTO wk_rec.
    IF sy-subrc NE 0.
      IF sy-subrc NE 4.
        WRITE:/ 'Attach Dataset Read RC ',sy-subrc.
        WRITE:/ 'Message ',t_mesg.
      ENDIF.
      EXIT.
    ENDIF.
    w_objbin-line = wk_rec.
    APPEND w_objbin.
  ENDDO.

  DESCRIBE TABLE w_objbin LINES w_tab_lines.

  LOOP AT w_objbin INTO wk_rec.
    APPEND wk_rec TO i_objbin.
  ENDLOOP.

ENDFORM.                    " mail_attachments
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  mail_contents
*&amp;amp;---------------------------------------------------------------------*
FORM mail_contents.
  DATA:
    str          TYPE p,
    len          TYPE p.

  REFRESH w_objbin.

  OPEN DATASET fname FOR INPUT IN TEXT MODE MESSAGE t_mesg.
  IF sy-subrc NE 0.
    WRITE: 'Dataset Open RC ',sy-subrc.
    EXIT.
  ENDIF.

  DO.
    READ DATASET fname INTO w_objbin-line.
    IF sy-subrc NE 0.
      IF sy-subrc NE 4.
        WRITE: 'Dataset Read RC ',sy-subrc.
      ENDIF.
      EXIT.
    ENDIF.
    APPEND w_objbin.
  ENDDO.

  DESCRIBE TABLE w_objbin LINES w_tab_lines.

  LOOP AT w_objbin INTO wk_rec.
    APPEND wk_rec TO i_objtxt.
  ENDLOOP.


ENDFORM.                    " mail_contents
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2008 15:27:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895975#M680807</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-10T15:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895976#M680808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try passing wa_packing_list-transf_bin as space.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Balaji&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Mar 2008 17:39:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895976#M680808</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-10T17:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: problem in excel format while sending mail with excel attachment.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895977#M680809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am encountering the same error in our program. The program is sending a text file with .XLS format and sent via email. The problem with the file when opened in Excel is that there are some Portuguese characters not displayed properly. What I did is to add encoding '4103' (UTF-16LE) to CALL FUNCTION 'SCMS_STRING_TO_XSTRING'. As a result, the Excel file now displays the Portuguese characters correctly. However the side effect is that the pop up message from Excel displays warning message 'File is not recognizable format...'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After doing research, I found one wiki telling that Excel uses prefix FFFE at the beginning of a UTF-16LE file to identify that the file is in that format. So what I did is I added FFFE at the beginning of my string before sending it in the email. As a result Excel no longer shows the warning message when opening the UTF-16LE file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code that creates FFFE character representation&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  DATA: o_conv TYPE REF TO cl_abap_conv_in_ce,
        v_prefix TYPE c.

  CONSTANTS: c_hex(2) TYPE x VALUE 'FFFE'.

  o_conv = cl_abap_conv_in_ce=&amp;gt;create( encoding = '4103' ).

  CALL METHOD o_conv-&amp;gt;convert
    EXPORTING
      input           = c_hex
    IMPORTING
      data            = v_prefix.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code that adds the FFFE prefix to the long string. Variable L_STRING containts the entire data that will be displayed in Excel. It contains carriage return and horizontal_tabs as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  CONCATENATE v_prefix
              l_string
  into l_string.

  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text           = l_string
   encoding       = '4103'
   IMPORTING
     buffer         = l_xstring
   EXCEPTIONS
     failed         = 1
     OTHERS         = 2
            .
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The XSTRING is converted to BINARY. The binary internal table is the one added to the SO_NEW_DOCUMENT_ATT_SEND_API1 function module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  REFRESH it_objbin.
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer        = l_xstring
    IMPORTING
      output_length = l_len
    TABLES
      binary_tab    = it_objbin.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Oct 2010 15:10:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-in-excel-format-while-sending-mail-with-excel-attachment/m-p/2895977#M680809</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-10-19T15:10:01Z</dc:date>
    </item>
  </channel>
</rss>

