12-16-2005 1:46 PM
Hi Folks,
I have an ALV report, the output of which needs to be sent as an excel attachment to an external email id. Can I use SO_NEW_DOCUMENT_ATT_SEND_API1 in this case? What about the SAP Connect settings? Any documents/help files/code samples describing the same will be useful.
/Sagar
12-16-2005 3:00 PM
Hi,
If you want to send the same report list of alv or is it ok you want to send the same data of your output to excel.
If so then populate that data into an Internal table with each column seperated by Tab delimeter.
Then Pass this Internal table as
Loop at your Internal table.
pass the values to OBJTXT.
append to OBJTXT.
endloop.
Later fill the necessary table example
Creation of the document to be sent
DOC_CHNG-OBJ_NAME = 'TEST'.
DOC_CHNG-OBJ_DESCR = 'TEST MAIL WITH XLS ATTACHMENT'. "mail subject
OBJTXT = 'Test mail with XLS attachment'.
APPEND OBJTXT.
CLEAR OBJTXT.
APPEND OBJTXT.
APPEND OBJTXT.
OBJTXT = 'Please double click the attachment to verify'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Creation of the entry for the compressed document
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'Sample XLS attachement'. "
APPEND OBJHEAD.
Creation of the entry for the compressed attachment
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'XLS'.
OBJPACK-OBJ_NAME = 'TEST'.
OBJPACK-OBJ_DESCR = 'Test.XLS'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
Completing the recipient list
For sending mail to Internet Address
RECLIST-RECEIVER = 'hajira.rehman@intelligroup.co.in'.
RECLIST-REC_TYPE = 'U'.
For sending mail to SAP user ID
RECLIST-RECEIVER = 'HREHMA'.
RECLIST-REC_TYPE = 'B'.
APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
Hope this what you want...
Rajeev
endloop
12-16-2005 1:54 PM
Hi
ok i thought you wanted to send attachment through mail..
regards
vijay
Message was edited by: Vijay Babu Dudla
12-16-2005 2:06 PM
Hi Vijay,
What I am more interested is in
1. sending Excel files
2. settings of SAP Connect
/Sagar
Hi Vijay,
I want to send Excel files as attachment.
/Sagar
Message was edited by: Sagar Acharya
12-16-2005 2:35 PM
Hi Sagar,
generally we used to convert the report output to Spool,spool to pdf , send the mail attachment..
but excel attachment i am not sure..
wait for some more responses...
vijay
12-16-2005 2:50 PM
HI,
If you want to send the ALV output as it is then you need send it to Spool and then convert it to a PDF then send it via email as an attachment,
or else, if you want to send the data of the output you can send it by the final internal table i mean by using the final Internal table you can send the data by passing this final interanl table to <b>'SO_NEW_DOCUMENT_ATT_SEND_API1'</b>
<u>example for your understanding:</u>
DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.
DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.
DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.
DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.
DATA: DOC_CHNG LIKE SODOCCHGI1.
DATA: TAB_LINES LIKE SY-TABIX.
DATA L_NUM(3).
Creation of the document to be sent
File Name
DOC_CHNG-OBJ_NAME = 'SENDFILE'.
Mail Subject
DOC_CHNG-OBJ_DESCR = 'Delivered Mail'.
Mail Contents
OBJTXT = 'Object text'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Creation of the entry for the compressed document
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
Creation of the document attachment
LOOP AT ITAB_DATA.
CONCATENATE ITAB_DATA-PRODUCTOR
ITAB_DATA-VBELN
ITAB_DATA-POSNR
ITAB_DATA-MATNR INTO OBJBIN.
APPEND OBJBIN.
ENDLOOP.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'ORDERS'.
APPEND OBJHEAD.
Creation of the entry for the compressed attachment
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'TXT'.
OBJPACK-OBJ_NAME = 'WEBSITE'.
OBJPACK-OBJ_DESCR = 'ORDERS.TXT'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
Completing the recipient list
target recipent
clear RECLIST.
RECLIST-RECEIVER = 'test@here.com'.
RECLIST-EXPRESS = 'X'.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
copy recipents
clear RECLIST.
RECLIST-RECEIVER = 'secondtest@here.com'.
RECLIST-EXPRESS = 'X'.
RECLIST-REC_TYPE = 'U'.
RECLIST-COPY = 'X'.
APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
ENDFORM. " SEND_MAIL
12-16-2005 2:58 PM
Hi,
Have a look at given link,
This below link with code sample, sending email with attachment from sap.
http://www.thespot4sap.com/Articles/SAP_Mail_UNIX_Example_ABAP.asp
Thanks,
Naga
12-16-2005 3:00 PM
Hi,
If you want to send the same report list of alv or is it ok you want to send the same data of your output to excel.
If so then populate that data into an Internal table with each column seperated by Tab delimeter.
Then Pass this Internal table as
Loop at your Internal table.
pass the values to OBJTXT.
append to OBJTXT.
endloop.
Later fill the necessary table example
Creation of the document to be sent
DOC_CHNG-OBJ_NAME = 'TEST'.
DOC_CHNG-OBJ_DESCR = 'TEST MAIL WITH XLS ATTACHMENT'. "mail subject
OBJTXT = 'Test mail with XLS attachment'.
APPEND OBJTXT.
CLEAR OBJTXT.
APPEND OBJTXT.
APPEND OBJTXT.
OBJTXT = 'Please double click the attachment to verify'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES.
DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
Creation of the entry for the compressed document
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'Sample XLS attachement'. "
APPEND OBJHEAD.
Creation of the entry for the compressed attachment
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'XLS'.
OBJPACK-OBJ_NAME = 'TEST'.
OBJPACK-OBJ_DESCR = 'Test.XLS'.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
Completing the recipient list
For sending mail to Internet Address
RECLIST-RECEIVER = 'hajira.rehman@intelligroup.co.in'.
RECLIST-REC_TYPE = 'U'.
For sending mail to SAP user ID
RECLIST-RECEIVER = 'HREHMA'.
RECLIST-REC_TYPE = 'B'.
APPEND RECLIST.
Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOC_CHNG
PUT_IN_OUTBOX = 'X'
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
OPERATION_NO_AUTHORIZATION = 4
OTHERS = 99.
Hope this what you want...
Rajeev
endloop
12-19-2005 7:18 AM
Hi Folks,
I tried with the following code. It does send a mail with Excel attachment, but the content in the Excel file is not in separate columns. Instead, 'SampleFile' appears in the first column. Any idea?
REPORT zteste_ale .
DATA:
docdata LIKE sodocchgi1,
objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,
objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
tab_lines TYPE sy-tabix.
DATA:
BEGIN OF i_data OCCURS 0,
a(20),
b(20),
END OF i_data.
Body
docdata-obj_name = 'Mail_Excel_File'.
docdata-obj_descr = 'Excel file attachment'.
objtxt = 'Attached is the sample Excel file'.
APPEND objtxt.
DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
docdata-doc_size = ( tab_lines - 1 ) * 255 + strlen( objtxt ).
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'RAW'.
APPEND objpack.
Attachment
<b> i_data-a = 'Sample'.
i_data-b = 'File'.
CONCATENATE i_data-a i_data-b INTO objbin.
APPEND objbin.</b>
DESCRIBE TABLE objbin LINES tab_lines.
objpack-doc_size = tab_lines * 255.
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 1.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'XLS'.
docdata-obj_name = 'Excel_File_Attachment'.
objpack-obj_descr = 'Excel File Attachment'.
APPEND objpack.
Create the list of recipients
reclist-receiver = 'sagar.acharya@wipro.com'.
reclist-rec_type = 'U'.
reclist-express = 'X'.
APPEND reclist.
Send the e-mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = docdata
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = objpack
contents_bin = objbin
contents_txt = objtxt
receivers = 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.
COMMIT WORK.
12-19-2005 8:00 AM
HI,SAGAR
I HAVE THE SAME PROBLEM ,WHEN I SEND A MAIL WITH THE excel attachment, THE ALL CONTENT IS ONE CELL .
I have resolved this problem with a unskillful method ,
separate the content by tab.
12-19-2005 8:23 AM
And how do you do it?
CONCATENATE i_data-a i_data-b INTO objbin SEPARATED BY ???
12-19-2005 8:55 AM
hi,sagar.
I'm chinese , my english is not well.I hope you can understand my means .
CONCATENATE i_data-a i_data-b INTO objbin SEPARATED BY TAB.
the ascii of 'tab' is '09' .
the follow is my code :
DATA XSTRING_STREAM TYPE XSTRING.
DATA UNICODE_STRING type string.
DATA U_STRING TYPE STRING.
field-symbols: <str>. " Hexa Value of input String
field-symbols: <str1>. " Hexa Value of input String
CLEAR : U_STRING,UNICODE_STRING,XSTRING_STREAM .
*===== one field ===============
ASSIGN SLS1-FKDAT TO <str1> TYPE 'X'.
U_STRING = <str1> .
*===== another field ===============
ASSIGN SLS1-WADAT_IST TO <str1> TYPE 'X'.
UNICODE_STRING = <STR1> .
CONCATENATE U_STRING '09' UNICODE_STRING INTO U_STRING .
WHEN ONE ROW END, ADD THIS :
CONCATENATE U_STRING '0D0A' INTO U_STRING .
XSTRING_STREAM = U_STRING .
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
FROM_CODEPAGE = '8400' "chinese simple
IN_XSTRING = XSTRING_STREAM
IMPORTING
OUT_STRING = UNICODE_STRING .
objbin-line = UNICODE_STRING .
append objbin.
Message was edited by: xiaoming cai
Message was edited by: xiaoming cai
01-31-2006 6:46 AM
Hi
I tried the piece of code but was not aable to send mail with attachment. Do I need to configure anything for this.
Please let me know ASAP
Regards
Cinu
08-07-2008 7:13 AM
Solved.
CONCATENATE i_data-a i_data-b INTO objbin SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.