09-18-2008 9:01 AM
Hii All,
I have a report to display data in ALV grid display...
now i want to send this report thru email....to other person
can any one suggest me...
thnx
Rohit
09-18-2008 1:58 PM
hi ,
i tried alll of them ...but i m not getting any mail...
do we have to do some configuration in SAP..for that...
pLz let me know....
thnx
Rohit
09-18-2008 9:05 AM
Hi Rohit,
if you dont have issues with ALV output length more than 255 columns then use this FM
SO_NEW_DOCUMENT_ATT_SEND_API1 and send the report as attachment to mail.
Thanks
Sudharshan
09-18-2008 9:10 AM
No Need to work that much just from report output screen>system>list>send>give recp address and recp type as internet user>send(Shift+F8).
if you are using alv>list>send to>reast same procedure as above.
Amit.
09-18-2008 9:11 AM
hi,
just use function module: SO_NEW_DOCUMENT_ATT_SEND_API1
and sample code for sending internal table data through mail is given below it will help you:
I had to do away with my earlier method of writing the data to spool, instead i exported the data to memory using the FM LIST_FROM_MEMORY.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = t_listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc 0.
MESSAGE e000(su) WITH text-001.
ENDIF.
then i converted it into ASCII using LIST_TO_ASCI,
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listasci = t_xlstab
listobject = t_listobject
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE e003(yuksdbfzs).
ENDIF.
This gives the data in ASCII format separated by '|' and the header has '-', dashes. If you use this internal table directly without any proccesing in SO_NEW_DOCUMENT_ATT_SEND_API1, then you will not get a good excel sheet attachment. To overcome this limitation, i used cl_abap_char_utilities=>newline and cl_abap_char_utilities=>horizontal_tab to add horizontal and vertical tabs to the internal table, replacing all occurences of '|' with
cl_abap_char_utilities=>horizontal_tab.
Set the doc_type as 'XLS', create the body and header using the packing_list and pass the data to be downloaded to SO_NEW_DOCUMENT_ATT_SEND_API1 as contents_bin.
This will create an excel attachment.
Sample code for formatting the data for the attachment in excel format.
u2022 Format the data for excel file download
LOOP AT t_xlstab INTO wa_xlstab .
DESCRIBE TABLE t_xlstab LINES lw_cnt.
CLEAR lw_sytabix.
lw_sytabix = sy-tabix.
u2022 If not new line then replace '|' by tabs
IF NOT wa_xlstab EQ cl_abap_char_utilities=>newline.
REPLACE ALL OCCURRENCES OF '|' IN wa_xlstab
WITH cl_abap_char_utilities=>horizontal_tab.
MODIFY t_xlstab FROM wa_xlstab .
CLEAR wa_xlstab.
wa_xlstab = cl_abap_char_utilities=>newline.
IF lw_cnt NE 0 .
lw_sytabix = lw_sytabix + 1.
u2022 Insert new line for the excel data
INSERT wa_xlstab INTO t_xlstab INDEX lw_sytabix.
lw_cnt = lw_cnt - 1.
ENDIF.
CLEAR wa_xlstab.
ENDIF.
ENDLOOP.
Sample code for creating attachment and sending mail:
FORM send_mail .
u2022 Define the attachment format
lw_doc_type = 'XLS'.
u2022 Create the document which is to be sent
lwa_doc_chng-obj_name = 'List'.
lwa_doc_chng-obj_descr = w_subject. "Subject
lwa_doc_chng-obj_langu = sy-langu.
u2022 Fill the document data and get size of message
LOOP AT t_message.
lt_objtxt = t_message-line.
APPEND lt_objtxt.
ENDLOOP.
DESCRIBE TABLE lt_objtxt LINES lw_tab_lines.
IF lw_tab_lines GT 0.
READ TABLE lt_objtxt INDEX lw_tab_lines.
lwa_doc_chng-doc_size = ( lw_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
lwa_doc_chng-obj_langu = sy-langu.
lwa_doc_chng-sensitivty = 'F'.
ELSE.
lwa_doc_chng-doc_size = 0.
ENDIF.
u2022 Fill Packing List For the body of e-mail
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lw_tab_lines.
lt_packing_list-doc_type = 'RAW'.
APPEND lt_packing_list.
u2022 Create the attachment (the list itself)
DESCRIBE TABLE t_xlstab LINES lw_tab_lines.
u2022 Fill the fields of the packing_list for creating the attachment:
lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lw_tab_lines.
lt_packing_list-doc_type = lw_doc_type.
lt_packing_list-obj_name = 'Attach'.
lt_packing_list-obj_descr = w_docdesc.
lt_packing_list-doc_size = lw_tab_lines * 255.
APPEND lt_packing_list.
u2022 Fill the mail recipient list
lt_reclist-rec_type = 'U'.
LOOP AT t_recipient_list.
lt_reclist-receiver = t_recipient_list-address.
APPEND lt_reclist.
ENDLOOP.
u2022 Finally send E-Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = lwa_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = lw_sent_to_all
TABLES
packing_list = lt_packing_list
object_header = lt_objhead
contents_bin = t_xlstab
contents_txt = lt_objtxt
receivers = lt_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.
regards
Rahul sharma
Edited by: RAHUL SHARMA on Sep 18, 2008 10:12 AM
09-18-2008 9:23 AM
Hi,
here the code I've used.
form build_xls_data_table.
*CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
*con_tab TYPE x VALUE '09'. "OK for non Unicode
*If you have Unicode check active in program attributes thnen you will
*need to declare constants as follows
*class cl_abap_char_utilities definition load.
constants:
con_tab type c value cl_abap_char_utilities=>horizontal_tab,
con_cret type c value cl_abap_char_utilities=>cr_lf.
concatenate
'Voce P&L'
'IDLAccount'
'Descrizione'
'Importo'
space
into it_attach separated by con_tab.
concatenate con_cret it_attach into it_attach.
append it_attach.
clear it_attach.
loop at tb_total.
write tb_total-wkgbtr to importo.
concatenate
tb_total-pl_item
tb_total-idlaccount
tb_total-description
importo
space
into it_attach separated by con_tab.
concatenate con_cret it_attach into it_attach.
append it_attach.
"Note below tow lines....
clear it_attach. "clear ini line
endloop.
endform. " BUILD_XLS_DATA_TABLE
*&----
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
*&----
send email
*----
form send_file_as_email_attachment tables pit_message
pit_attach
using
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
data: ld_error type sy-subrc,
ld_reciever type sy-subrc,
ld_mtitle like sodocchgi1-obj_descr,
ld_email like somlreci1-receiver,
ld_format type so_obj_tp ,
ld_attdescription type so_obj_nam ,
ld_attfilename type so_obj_des ,
ld_sender_address like soextreci1-receiver,
ld_sender_address_type like soextreci1-adr_typ,
ld_receiver like sy-subrc.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
fill the document data.
w_doc_data-doc_size = 1.
populate the subject/generic message attributes
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'.
fill the document data and get size of attachment
clear w_doc_data.
read table it_attach index w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + strlen( it_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[] = it_attach[].
describe the body of the message
clear t_packing_list.
refresh t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
describe table it_message lines t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
append t_packing_list.
create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
describe table t_attachment lines t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
append t_packing_list.
add the recipients email address
clear t_receivers.
refresh t_receivers.
loop at s_mail.
t_receivers-receiver = s_mail-low.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
*t_receivers-notif_del = 'X'.
*t_receivers-notif_ndel = 'X'.
append t_receivers.
endloop.
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
object_header = t_object_header
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_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.
populate zerror return code
ld_error = sy-subrc.
populate zreceiver return code
loop at t_receivers.
ld_receiver = t_receivers-retrn_code.
endloop.
endform. "f_send
09-18-2008 9:29 AM
09-18-2008 1:58 PM
hi ,
i tried alll of them ...but i m not getting any mail...
do we have to do some configuration in SAP..for that...
pLz let me know....
thnx
Rohit
09-18-2008 2:01 PM
Hi,
Ya,
You have to do some configuration in SCOT, and configure SMTP protocol.
Regards,
Arpit
09-18-2008 2:03 PM
09-19-2008 6:43 AM
Hi Arpit
i used FM ...and able to send the mail..
but once i execute the report ...i have to go to SCOT tcode for further processing...i execute there then it sends the mail...
plz help me..
09-19-2008 6:51 AM
No it should be sent by automatically.no manual work.
Just wait for a while some time it may take 3-4 minutes to send a mail.
Amit.
09-19-2008 7:30 AM
No Amit,
i tried but ....ihav eto go to SCOT....for further process...
Plz suggest me..
do i need to cofig something in SCOT
Edited by: Rohit Kumar on Sep 19, 2008 12:01 PM
09-19-2008 7:40 AM
No.
from SCOT mail should be send automatically since you have done all cofiguration for SMTP connect.just take a guide from basis.
Amit.
09-19-2008 8:04 AM
do i hav to schedule the job for sending the mail in SCOT...
because it remains there only...
if i executes "START SEND PROCESS" then only i m getting the mail...
😮
09-19-2008 8:07 AM
Rohit,
It should automatically refreshed all SEND RECIEVE process.
Why you don't ask your Basis person?
09-22-2008 7:28 AM
Hi Rohit,
After configuration in SCOT, it is a one time configuration,
and after sending mail, u have to go to SOST and send mail manually.
or u hv to call
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
after sending mail in your program.
I hope it is solved your problem.
Regards,
Arpit
09-22-2008 7:51 AM
Hi Rohit,
In SCOT go to Settings --> Send Jobs . See if a job (Internet) already exists. Set the period to about 1 minute.
The send process will be automatically carried out every 1 minute.
If no jobs are present, create one in SCOT View-> Jobs
Regards,
Rajvansh
Edited by: Rajvansh Ravi on Sep 22, 2008 8:52 AM
09-24-2008 12:24 PM
HI all,
thnx
now i m able to send the email with attachment....
now the problem is that i m getting junk charaters in the attachment....
after every row i m getting junk character....
i m using document typeas RAW...
plz suggest me .....i thing it is the length of the row(record)...
becoz when i send three fields (column) i get it correctly....but as i send more then 3 fields(column) i get the junk character....
i am able to send upto GT_OBJBIN-LINE+78(1)....
as i try to send GT_OBJBIN-LINE+79(10)..it gives junk character....
plz help me in that...
09-24-2008 2:09 PM
Hi Rohit,
If you don't want through by programming then just execute program,
after showing o/p just press ctrl + F7 or there is button for Mail recipient, click on that and add email id and send and go to sost and release and send mail.
Regards,
Arpit
11-13-2008 11:21 AM
Hi Rohit,
i have one simeler requirement is we have certain applications which are integrated
with SAP Portal.
For these applications Data sources are maintained in two different
LDAPS.
One LDAP (enterprise directory) is for USER data and the other LDAP for
Company data(in this senario company data is nothing but business
partner role oragnization).
So here the question is, Can we use SAP standard LDAP connectors to
make connectivity to the enterprise directory(LDAP)and push business
partners data from CRM to the enterprise directory.
In Standard SAP CRM system which are standard LDAP connectors support
this functionality?
Please advice me and also let me know if we have any SAP notes for this
senario.
Best Regards
Prasad