Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem in excel format while sending mail with excel attachment using FM SO_DOCUMENT_SEND_API1.

Former Member
0 Likes
5,553

Hi, I am sending a email with Excel attachment using FM SO_DOCUMENT_SEND_API1.

I am able to send a mail with excel attachment.

But the problem is when I am trying to open the attachment is showing pop of as '' File format and extension of 'orders.xls' don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway"

if i click Yes button in excel then i can able to view my out put.

Can you please guide me why pop of message in showing when open excel attachment.

  PERFORM send_email TABLES lt_message
                            it_attach
                            lt_receivers
                     USING 'Budget Vs Actual' "" Subject
                           'XLS'
                           'Budget Vs Actual Attach' "" Attach file name
                           'INT'
                     CHANGING gd_error.

FORM send_email  TABLES pit_message
                        pit_attach
                        plt_receivers
                 USING  p_mtitle
                        p_format
                        p_filename
                        p_sender_addres_type
                 CHANGING p_error.

  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attfilename         = p_filename.
  ld_sender_address_type = p_sender_addres_type.

* Fill the document data and get size of attachment
  CLEAR : w_doc_data,w_cnt.
  DESCRIBE TABLE pit_attach LINES w_cnt.
  w_doc_data-doc_size = ( w_cnt - 1 ) * 255 + strlen( pit_attach ).

  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-obj_name   = 'SAPRPT'.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = 'F'.

  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = pit_attach[].

  CLEAR w_t_packing_list.
  REFRESH t_packing_list.
  w_t_packing_list-transf_bin = space.
  w_t_packing_list-head_start = 1.
  w_t_packing_list-head_num = 0.
  w_t_packing_list-body_start = 1.

  DESCRIBE TABLE pit_message LINES w_t_packing_list-body_num.
  w_t_packing_list-doc_type = 'RAW'.
  APPEND w_t_packing_list TO t_packing_list.

  w_t_packing_list-transf_bin = 'X'.
  w_t_packing_list-head_start = 1.
  w_t_packing_list-head_num   = 1.
  w_t_packing_list-body_start = 1.
  DESCRIBE TABLE t_attachment LINES w_t_packing_list-body_num.

  w_t_packing_list-doc_type   =  ld_format.
  w_t_packing_list-obj_descr  =  sy-datum."ld_attdescription.
  w_t_packing_list-obj_name   =  ld_attfilename.
  w_t_packing_list-doc_size   =  w_t_packing_list-body_num * 255.
  APPEND w_t_packing_list TO t_packing_list.

  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = w_doc_data
      put_in_outbox              = 'X'
      sender_address             = ld_sender_address
      sender_address_type        = ld_sender_address_type
      commit_work                = 'X'
    IMPORTING
      sent_to_all                = w_sent_all
    TABLES
      packing_list               = t_packing_list
      object_header              = objhead
      contents_bin               = t_attachment
      contents_txt               = pit_message
      receivers                  = plt_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.

  ld_error = sy-subrc.

Hi, I am sending a email with Excel attachment using FM SO_DOCUMENT_SEND_API1.

I am able to send a mail with excel attachment.

But the problem is when I am trying to open the attachment is showing pop of as '' File format and extension of 'orders.xls' don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway"

if i click Yes button in excel then i can able to view my out put.

Can you please guide me why pop of message in showing when open excel attachment.

  PERFORM send_email TABLES lt_message
                            it_attach
                            lt_receivers
                     USING 'Budget Vs Actual' "" Subject
                           'XLS'
                           'Budget Vs Actual Attach' "" Attach file name
                           'INT'
                     CHANGING gd_error.

FORM send_email  TABLES pit_message
                        pit_attach
                        plt_receivers
                 USING  p_mtitle
                        p_format
                        p_filename
                        p_sender_addres_type
                 CHANGING p_error.

  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attfilename         = p_filename.
  ld_sender_address_type = p_sender_addres_type.

* Fill the document data and get size of attachment
  CLEAR : w_doc_data,w_cnt.
  DESCRIBE TABLE pit_attach LINES w_cnt.
  w_doc_data-doc_size = ( w_cnt - 1 ) * 255 + strlen( pit_attach ).

  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-obj_name   = 'SAPRPT'.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = 'F'.

  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = pit_attach[].

  CLEAR w_t_packing_list.
  REFRESH t_packing_list.
  w_t_packing_list-transf_bin = space.
  w_t_packing_list-head_start = 1.
  w_t_packing_list-head_num = 0.
  w_t_packing_list-body_start = 1.

  DESCRIBE TABLE pit_message LINES w_t_packing_list-body_num.
  w_t_packing_list-doc_type = 'RAW'.
  APPEND w_t_packing_list TO t_packing_list.

  w_t_packing_list-transf_bin = 'X'.
  w_t_packing_list-head_start = 1.
  w_t_packing_list-head_num   = 1.
  w_t_packing_list-body_start = 1.
  DESCRIBE TABLE t_attachment LINES w_t_packing_list-body_num.

  w_t_packing_list-doc_type   =  ld_format.
  w_t_packing_list-obj_descr  =  sy-datum."ld_attdescription.
  w_t_packing_list-obj_name   =  ld_attfilename.
  w_t_packing_list-doc_size   =  w_t_packing_list-body_num * 255.
  APPEND w_t_packing_list TO t_packing_list.

  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = w_doc_data
      put_in_outbox              = 'X'
      sender_address             = ld_sender_address
      sender_address_type        = ld_sender_address_type
      commit_work                = 'X'
    IMPORTING
      sent_to_all                = w_sent_all
    TABLES
      packing_list               = t_packing_list
      object_header              = objhead
      contents_bin               = t_attachment
      contents_txt               = pit_message
      receivers                  = plt_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.

  ld_error = sy-subrc.

5 REPLIES 5
Read only

GK817
Active Contributor
0 Likes
3,525

Hi Sunil,

Problem is not really with your code but trust settings with your excel file. Whenever you try to open a excel file from a untrusted location, it will give this pop-up. You can get rid of this pop-up using some alternatives. Here is the detailed answer:

https://social.technet.microsoft.com/Forums/office/en-US/4a15e472-a265-4058-b439-7d79c2670817/xls-fi...

By altering the security settings of your excel, you can get rid of this pop-up.

GK

Read only

Former Member
0 Likes
3,525

Hi Sunil,

1. Change file extension to end in .xlsx or .xlsm

Test.

Message can be generated when .xlsx or .xlsm file was renamed to .xls

2. Copy file to higher level folder, see if solves error. Excel has 218 characters limit for file path. Test.

3. Add trusted location:

a. Click File > Options

b. Click Trust Center > Trust Center Settings > Trusted Locations

c. Click Add new location

d. Click Browse to find folder, select a folder, OK. Test.

References

https://answers.microsoft.com/en-us/msoffice/forum/all/file-corrupted-or-unsafe-how-to-recoverfix/1b...

http://office.microsoft.com/en-001/excel-help/repair-a-corrupted-workbook-HA102749554.aspx

https://answers.microsoft.com/en-us/msoffice/forum/all/the-file-format-and-extension-of-dont-match-e...

Read only

Sandra_Rossi
Active Contributor
3,525

Did you know that there are several formats supported by Excel? Choose the right extension based on how you created your Excel file.

  • "xls" : Excel 97-2003, also known as Binary File Format, you may create it only by using OLE; this extension should also work with the XMLSS format (see below)
  • "csv" : text file containing values separated by commas
  • "xlsx" : since Excel 2007, zipped file containing files mainly in XML format
  • "xml" : Excel 2002/2003, XML file, also known as XMLSS (XML spreadsheet)

Now, you should better understand why Excel sends the following message and how to remedy.

File format and extension of 'orders.xls' don't match. The file could be corrupted or 
unsafe. Unless you trust its source, don't open it. Do you want to open it anyway?

If you want to send an attachment with an extension of more than 3 characters (xlsx), you should transmit the following line in the parameter OBJECT_HEADER of function module SO_DOCUMENT_SEND_API1 (and edit accordingly HEAD_START and HEAD_NUM in parameter PACKING_LIST to indicate where is the line in OBJECT_HEADER):

&SO_FILENAME=yourfilename.xlsx
Read only

Former Member
0 Likes
3,525

Hi I am trying to generate xlsx or .xlsm in place of .xls but it not change extension .

  w_t_packing_list-transf_bin = 'X'.
  w_t_packing_list-head_start = 1.
  w_t_packing_list-head_num   = 1.
  w_t_packing_list-body_start = 1.
  DESCRIBE TABLE t_attachment LINES w_t_packing_list-body_num.
  w_t_packing_list-doc_type   =  'XLSX'.
  w_t_packing_list-obj_descr  =  sy-datum."ld_attdescription.

  w_t_packing_list-obj_name   =  ld_attfilename.
  w_t_packing_list-doc_size   =  w_t_packing_list-body_num * 255.
  APPEND w_t_packing_list TO t_packing_list.


  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = w_doc_data
      put_in_outbox              = 'X'
      sender_address             = ld_sender_address
      sender_address_type        = ld_sender_address_type
      commit_work                = 'X'
    IMPORTING
      sent_to_all                = w_sent_all
    TABLES
      packing_list               = t_packing_list
      object_header              = objhead
      contents_bin               = t_attachment
      contents_txt               = pit_message
      receivers                  = plt_receivers
    EXCEPTIONS
Read only

gayathri_jayajeevan2
Participant
0 Likes
3,525

Hi,

try converting the data to hex representation to eliminate the issue.

In FM SO_NEW_DOCUMENT_ATT_SEND_API, pass it to the CONTENTS_HEX table parameter instead of CONTENTS_BIN.

It may work.