2007 Oct 12 12:24 PM
Hi Gurus ,
I am sending a email with Excel attachment using FM SO_DOCUMENT_SEND_API1 or SO_NEW_DOCUMENT_ATT_SEND_API1.
I am able to send a mail with excel attachment with a piece of code which I got from SDN itself.
But the problem is when I am trying to open the attachment, <b>A pop up comes which says that it is not in recognizable format. Would you like to open it?
and several other lines of caution.</b>
When i choose to open it, i get the correct data in one excel sheet. Certain vertical lines of the excel sheet is missing. <b>But no data is missing. </b>
I am attaching the code below. Can any one please tell me where is the problem in this code ?
Thanx in advance
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=>HORIZONTAL_TAB,
con_cret type c value cl_abap_char_utilities=>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 <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
2008 Mar 10 3:27 PM
I use this for sending HTML File and two PDF files. Where I use the file type as PDF, try using XLS.
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', " <========= Change to your 1st XLS
attach2(132) TYPE c VALUE
'\\wiicorp_fs1\sap\INTERFACES\Dev\Paul\Exhibit_B.pdf'. " <========= 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 = '[email protected]'.
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'. " <========= 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'. " <========= 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.
*&---------------------------------------------------------------------*
*& Form mail_attachments
*&---------------------------------------------------------------------*
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
*&---------------------------------------------------------------------*
*& Form mail_contents
*&---------------------------------------------------------------------*
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
I use this for sending HTML File and two PDF files. Where I use the file type as PDF, try using XLS.
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', " <========= Change to your 1st XLS
attach2(132) TYPE c VALUE
'\\wiicorp_fs1\sap\INTERFACES\Dev\Paul\Exhibit_B.pdf'. " <========= 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 = '[email protected]'.
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'. " <========= 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'. " <========= 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.
*&---------------------------------------------------------------------*
*& Form mail_attachments
*&---------------------------------------------------------------------*
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
*&---------------------------------------------------------------------*
*& Form mail_contents
*&---------------------------------------------------------------------*
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
2007 Oct 29 3:04 AM
Hi raveesh,
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.
Thanks.
2007 Dec 27 8:58 AM
hi raveesh,
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.
thanks,
jim
2007 Dec 27 9:07 AM
REPORT Zex5 LINE-SIZE 255 LINE-COUNT 255 .
class CL_ABAP_CHAR_UTILITIES definition load. "-->
TABLES : vbap.
SELECT-OPTIONS: s_vbeln FOR vbap-vbeln.
DATA : BEGIN OF itab OCCURS 1,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
END OF itab.
parameters : p_email like somlreci1-receiver
DATA: tlines type i.
DATA: itmessage LIKE solisti1 OCCURS 1 WITH HEADER LINE. "Ok
DATA: itattach LIKE solisti1 OCCURS 2 WITH HEADER LINE. "Ok
DATA: itpacklist LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
DATA: itreclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
data: itattachment like solisti1 OCCURS 2 WITH HEADER LINE.
start-of-selection.
SELECT vbeln posnr matnr
FROM vbap
INTO TABLE itab
WHERE vbeln IN s_vbeln.
**Make the internal table data to be compatible in excel format .
PERFORM BUILD_XLS_FORMAT.
**Populate message of body text.
clear itmessage.
refresh itmessage.
itmessage = 'Please find attached Excel file'.
append itmessage.
PERFORM send_mail_as_xls_attachment tables itmessage
itattach
using p_email 'Excel Attachment' 'TXT' " 'XLS'
using p_email 'TEXT Attachment' 'TXT' " 'XLS'
'TestFileName'
'SalesOrders' .
&----
*& Form BUILD_XLS_FORMAT
&----
text
----
--> p1 text
<-- p2 text
----
form BUILD_XLS_FORMAT.
previosuly we were using for unicode ..now replaced
**Declare constants for the spacing .
*Constants : con1 type x value '0D',
con2 type x value '09'.
Constants : con1 type c
value CL_ABAP_CHAR_UTILITIES=>CR_LF,
con2 type c
value CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
**For the Header descriptions.
Concatenate 'SalesORdNo'
'Item'
'Materialno' into itattach separated by con2.
Concatenate con1 itattach into itattach.
Append itattach.
**Now align the items in the itab as above .
Loop at Itab.
concatenate itab-vbeln
itab-posnr
itab-matnr into itattach separated by con2.
concatenate con1 itattach into itattach .
Append itattach.
endloop.
endform. " BUILD_XLS_FORMAT
&----
*& Form send_mail_as_xls_attachment
&----
text
----
-->P_ITMESSAGE text
-->P_ITATTACH text
-->P_P_EMAIL text
-->P_0116 text
-->P_0117 text
-->P_0118 text
-->P_0119 text
----
form send_mail_as_xls_attachment tables p_itmessage
p_itattach
using p_email
p_mtitle
p_format
p_filename
p_attdescription.
Data : xdocdata like sodocchgi1,
xcnt type i.
*Fill the document data.
xdocdata-doc_size = 1.
*Populate the subject/generic message attributes.
xdocdata-obj_name = 'SAPRPT'.
xdocdata-obj_langu = sy-langu.
xdocdata-obj_descr = p_mtitle.
*Fill the document data and fetch size of attachment.
clear xdocdata.
read table itattach index xcnt.
xdocdata-doc_size = ( xcnt - 1 ) * 255 + strlen( itattach ).
xdocdata-doc_size = ( xcnt - 1 ) * 255.
xdocdata-obj_name = 'SAPRPT'.
xdocdata-obj_langu = sy-langu.
xdocdata-obj_descr = p_mtitle.
clear itattachment. refresh itattachment.
itattachment[] = p_itattach[].
*Describe the body of the message.
clear itpacklist. refresh itpacklist.
itpacklist-transf_bin = 'X'.
itpacklist-head_start = '1'.
itpacklist-head_num = '0'.
itpacklist-body_start = '1'.
describe table itattachment lines itpacklist-body_num .
itpacklist-doc_type = 'TXT'.
itpacklist-doc_type = 'XLS'.
append itpacklist.
*Create attachment notification.
itpacklist-transf_bin = 'X'.
itpacklist-head_start = '1'.
itpacklist-head_num = '1'.
itpacklist-body_start = '1'.
describe table itattachment lines itpacklist-body_num .
itpacklist-doc_type = p_format.
itpacklist-obj_name = p_filename.
itpacklist-obj_descr = p_attdescription.
itpacklist-doc_size = itpacklist-body_num * 255 .
append itpacklist.
*FIll the receivers list.
Clear itreclist. refresh itreclist.
itreclist-receiver = p_email.
itreclist-rec_type = 'U'.
itreclist-com_type = 'INT'.
itreclist-notif_del = 'X'.
itreclist-notif_ndel = 'X'.
*itreclist-notif_read = 'X'.
append itreclist.
*CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = xdocdata
PUT_IN_OUTBOX = 'X'
commit_work = 'X'
SENDER_ADDRESS = SY-UNAME
tables
packing_list = itpacklist
CONTENTS_BIN = itattachment
CONTENTS_TXT = itmessage
receivers = itreclist
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.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = xdocdata
PUT_IN_OUTBOX = 'X'
TABLES
packing_list = itpacklist
CONTENTS_BIN = itattachment
CONTENTS_TXT = itmessage
receivers = itreclist
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.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform. " send_mail_as_xls_attachment
Just execute the above code and let me know.
What is the sap version u r using .
Vijay
2007 Dec 27 9:14 AM
hi vijay,
we are using 4.7.
i keep on encountering the error message when the attachement is opened. please advice what should be changed in my code.
super thanks!
jim
Edited by: Jim Eric Tibayan on Jan 2, 2008 4:26 PM
2007 Dec 27 9:38 AM
Hi Jim ,
Let me know if u r able to send an excel attachment with my code .
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 .
In my code u can see this in Concatenate statement as Con1 and con2 .
When a unicode check is there u need to set them from the class.
This was missing in ur code which was prompting as file attachment error .
Cause in Excel u need to drop the values by columns and u need to separate the fields .
I hope if u can change the code accordingly witrh reference to my code cause i have used this in 4.7
Just let me know if my code is working for u .
Vijay
2007 Dec 27 9:45 AM
hi vijay,
im still getting the error message. im getting desperate.
please help.
jim
Edited by: Jim Eric Tibayan on Jan 2, 2008 4:20 PM
2007 Dec 27 9:53 AM
Jim send me ur code in word document to my id as an attachment.
Send me the complete code ok.
Btw u didnt answer whether my code was working in ur system or not.
my id is
<REMOVED BY MODERATOR>
I will look into the changes..
Vijay
Edited by: Alvaro Tejada Galindo on Mar 10, 2008 1:40 PM
2007 Dec 27 10:25 AM
i created a temporary program using your code and i got the same error when i opened the attachment.
thanks.
jim
Edited by: Jim Eric Tibayan on Jan 2, 2008 4:25 PM
2007 Dec 28 4:57 AM
2007 Dec 28 8:43 AM
Hi vijay,
I have tested your code. It is giving the same error to me as mentioned in the start of the thread.
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.
Thanks,
Raveesh
2008 Mar 10 3:03 PM
2008 Mar 10 3:27 PM
I use this for sending HTML File and two PDF files. Where I use the file type as PDF, try using XLS.
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', " <========= Change to your 1st XLS
attach2(132) TYPE c VALUE
'\\wiicorp_fs1\sap\INTERFACES\Dev\Paul\Exhibit_B.pdf'. " <========= 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 = '[email protected]'.
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'. " <========= 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'. " <========= 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.
*&---------------------------------------------------------------------*
*& Form mail_attachments
*&---------------------------------------------------------------------*
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
*&---------------------------------------------------------------------*
*& Form mail_contents
*&---------------------------------------------------------------------*
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
2008 Mar 10 5:39 PM
Try passing wa_packing_list-transf_bin as space.
Hope this helps.
Thanks,
Balaji
2010 Oct 19 4:10 PM
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...'
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.
Code that creates FFFE character representation
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=>create( encoding = '4103' ).
CALL METHOD o_conv->convert
EXPORTING
input = c_hex
IMPORTING
data = v_prefix.
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.
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
.
The XSTRING is converted to BINARY. The binary internal table is the one added to the SO_NEW_DOCUMENT_ATT_SEND_API1 function module.
REFRESH it_objbin.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = l_xstring
IMPORTING
output_length = l_len
TABLES
binary_tab = it_objbin.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |