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

Excel Format Unrecognized

Former Member
0 Likes
986

I've managed to download data from internal table to excel using SO_NEW_DOCUMENT_ATT_SEND_API1 but once I open the file it prompted a message saying that the file is not recognizable. What did I do wrong?

5 REPLIES 5
Read only

Former Member
0 Likes
640

HI,

Check these links

Thanks

mahesh

Read only

0 Likes
640

When I open the excel file the "unrecognized" message prompted out, I clicked 'OK' and data in the file turns out fine. How do I get rid of the message from popping out?

Read only

Former Member
0 Likes
640

can anyone help?

Read only

0 Likes
640

Hi,

I have the same problem and until now I don't know how to solve it.

When I open the original attachment I get the same error message "The file is not in a recognizable format" from excel.

When I save the attachment in a new file within excel the message disapears when reopening this xls-file.

Comparing both excel files one can see the difference with a hex editor.

In the original attachment every sign is separated by hex null.

E.g. the word 'Document':

The original attachment has the hex code as it is created from a unicode system:

44 00 6F 00 63 00 75 00 6D 00 65 00 6E 00 74 00

whereas the saved excel file has the the hex code:

44 6F 63 75 6D 65 6E 74

How can I 'delete' the unicode hex 00 between every sign before sending the attachment?

Regards,

Georg

My coding:

TOP-Include

  • Mail

data: gt_message type table of solisti1,

gs_message type solisti1,

gs_doc_data type sodocchgi1,

gt_packing_list type table of sopcklsti1,

gs_packing_list type sopcklsti1,

gt_attachment type table of solisti1,

gs_attachment type solisti1,

gt_receivers type table of somlreci1,

gs_receivers type somlreci1.

*&----


*

*& Form build_xls_data_table

*&----


*

form build_xls_data_table .

class cl_abap_char_utilities definition load.

constants:

con_line type c value cl_abap_char_utilities=>newline, "Hex '0A'

con_tab type c value cl_abap_char_utilities=>horizontal_tab,"Hex '09'

con_cret type c value cl_abap_char_utilities=>cr_lf. "Hex '0D'

  • Get data for attachment

perform build_exdn_data tables gt_xls.

  • Table header

concatenate 'Document-ID' 'barcode' 'fieldname' 'old value' 'new value'

into gs_attachment separated by con_tab.

condense gs_attachment.

append gs_attachment to gt_attachment.

clear: gs_attachment.

concatenate con_cret gs_attachment into gs_attachment.

append gs_attachment to gt_attachment.

  • get table data

clear: gs_attachment.

loop at gt_xls into gs_xls.

concatenate gs_xls-documentid

gs_xls-barcode

gs_xls-fieldname

gs_xls-value_old

gs_xls-value_new

into gs_attachment separated by con_tab.

concatenate con_cret con_line gs_attachment into gs_attachment.

condense gs_attachment.

append gs_attachment to gt_attachment.

endloop.

endform. " build_xls_data_table

form send_file_as_email_attachment .

data: lv_tablines type p,

lv_fieldlen type p,

lv_attachlines type p,

lv_attachlen type p,

lv_sent_all(1) type c.

clear: lv_tablines, lv_fieldlen, lv_attachlines, lv_attachlen, lv_sent_all.

  • Message has been writen in gt_message.

  • Fill docment data

gs_doc_data-obj_name = 'EMAIL'.

concatenate 'Message' gv_datum gv_zeit

into gs_doc_data-obj_descr separated by space.

gs_doc_data-obj_langu = sy-langu.

gs_doc_data-obj_expdat = sy-datum.

gs_doc_data-sensitivty = 'F'.

gs_doc_data-no_change = 'X'.

describe field gs_message-line length lv_fieldlen in byte mode.

describe table gt_message lines lv_tablines.

multiply lv_fieldlen by lv_tablines.

gs_doc_data-doc_size = lv_fieldlen.

  • Fill packing list for message text

clear: gt_packing_list[].

gs_packing_list-transf_bin = space.

gs_packing_list-head_start = 1.

gs_packing_list-head_num = 0.

gs_packing_list-body_start = 1.

describe table gt_message lines gs_packing_list-body_num.

gs_packing_list-doc_type = 'RAW'.

append gs_packing_list to gt_packing_list.

  • Fill packing list for attachment

  • attachment is in table gt_attachment

gs_packing_list-transf_bin = 'X'.

gs_packing_list-head_start = 1.

gs_packing_list-head_num = 1.

gs_packing_list-body_start = 1.

describe field gs_attachment-line length lv_attachlen in byte mode.

describe table gt_attachment lines lv_attachlines.

gs_packing_list-body_num = lv_attachlines.

gs_packing_list-doc_type = 'XLS'.

gs_packing_list-obj_name = 'attchement'.

concatenate 'File_' gv_datum '_' gv_zeit '.xls'

into gs_packing_list-obj_descr.

multiply lv_attachlen by lv_attachlines.

gs_packing_list-doc_size = lv_attachlen.

append gs_packing_list to gt_packing_list.

  • Hinzufügen der Empfänger-e-Mail-Adresse

clear: gt_receivers[], gs_receivers.

gs_receivers-receiver = p_addr.

gs_receivers-rec_type = 'U'.

append gs_receivers to gt_receivers.

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = gs_doc_data

put_in_outbox = 'X'

  • sender_address = 'WF-BATCH'

  • sender_address_type = 'B'

commit_work = 'X'

importing

sent_to_all = lv_sent_all

tables

packing_list = gt_packing_list

contents_bin = gt_attachment

contents_txt = gt_message

receivers = gt_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 <> 0.

endif.

endform. " send_file_as_email_attachment

Read only

0 Likes
640

Hi *

I finaly found a solution.

Instead of transfering the attachment as text-table to the FM SO_NEW_DOCUMENT_ATT_SEND_API1 just convert the table before to a hex-table and pass this over to the FM.

For the conversion use FM 'SCMS_STRING_TO_XSTRING' and use as mime type 'APPLICATION/MSEXCEL; charset=UTF-8', Important is UTF-8 as charset!

Find below the coding.

Regards,

Georg-Stefan

TOP-Include

  • Mail

data: gt_message type table of solisti1,

gs_message type solisti1,

gs_doc_data type sodocchgi1,

gt_packing_list type table of sopcklsti1,

gs_packing_list type sopcklsti1,

gt_attachment type table of solisti1,

gs_attachment type solisti1,

gt_x_attachment type table of solix,

gs_x_attachment type solix,

gt_receivers type table of somlreci1,

gs_receivers type somlreci1.

data: lv_mime_type type c value 'APPLICATION/MSEXCEL; charset=UTF-8',

lv_row_text type string,

lv_row_hex type xstring.

clear: gs_attachment.

loop at gt_attachment into gs_attachment.

move gs_attachment to lv_row_text.

call function 'SCMS_STRING_TO_XSTRING'

exporting

text = lv_row_text

mimetype = lv_mime_type

importing

buffer = lv_row_hex.

move lv_row_hex to gs_x_attachment-line.

append gs_x_attachment to gt_x_attachment.

endloop.

….

form send_file_as_email_attachment .

data: lv_tablines type p,

lv_fieldlen type p,

lv_attachlines type p,

lv_attachlen type p,

lv_sent_all(1) type c.

clear: lv_tablines, lv_fieldlen, lv_attachlines, lv_attachlen, lv_sent_all.

  • Mainmessage is in gt_message.

  • Fill docment data

gs_doc_data-obj_name = 'EMAIL'.

concatenate 'Report from ' gv_datum gv_zeit

into gs_doc_data-obj_descr separated by space.

gs_doc_data-obj_langu = sy-langu.

gs_doc_data-obj_expdat = sy-datum.

gs_doc_data-sensitivty = 'F'.

gs_doc_data-no_change = 'X'.

describe field gs_message-line length lv_fieldlen in byte mode.

describe table gt_message lines lv_tablines.

multiply lv_fieldlen by lv_tablines.

gs_doc_data-doc_size = lv_fieldlen.

  • Fill packing list for message

clear: gt_packing_list[].

gs_packing_list-transf_bin = space.

gs_packing_list-head_start = 1.

gs_packing_list-head_num = 0.

gs_packing_list-body_start = 1.

describe table gt_message lines gs_packing_list-body_num.

gs_packing_list-doc_type = 'RAW'.

append gs_packing_list to gt_packing_list.

  • Fill packing list for attachment

  • The attachment is in table gt_x_attachment

gs_packing_list-transf_bin = 'X'.

gs_packing_list-head_start = 1.

gs_packing_list-head_num = 1.

gs_packing_list-body_start = 1.

describe field gs_attachment-line length lv_attachlen in byte mode.

describe table gt_attachment lines lv_attachlines.

gs_packing_list-body_num = lv_attachlines.

gs_packing_list-doc_type = 'XLS'.

gs_packing_list-obj_name = 'Anlage'.

concatenate 'File_' gv_datum '_' gv_zeit '.xls'

into gs_packing_list-obj_descr.

multiply lv_attachlen by lv_attachlines.

gs_packing_list-doc_size = lv_attachlen.

append gs_packing_list to gt_packing_list.

  • Fill e-mail-adresses

clear: gt_receivers[], gs_receivers.

gs_receivers-receiver = p_addr.

gs_receivers-rec_type = 'U'.

append gs_receivers to gt_receivers.

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = gs_doc_data

put_in_outbox = 'X'

commit_work = 'X'

importing

sent_to_all = lv_sent_all

tables

packing_list = gt_packing_list

contents_txt = gt_message

contents_hex = gt_x_attachment

receivers = gt_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.