2020 Jan 15 4:21 AM
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.
2020 Jan 15 5:09 AM
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:
By altering the security settings of your excel, you can get rid of this pop-up.
GK
2020 Jan 15 5:27 AM
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
http://office.microsoft.com/en-001/excel-help/repair-a-corrupted-workbook-HA102749554.aspx
2020 Jan 15 7:18 AM
Did you know that there are several formats supported by Excel? Choose the right extension based on how you created your Excel file.
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
2020 Jan 17 8:55 AM
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
2020 Jan 17 12:11 PM
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.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |