‎2008 Aug 25 5:44 AM
Hi Experts,
I have faced one problem in Mail Triggering. to the User.
Our Requirement is,
Whenever we execute one report ( ALV output) in Background , The Output should go the user thro mail ( automatic Mail trigger when the background Job is finished)
if anybody knows, plz guide me to do it.
With Regards,
Mahesh.
‎2008 Aug 25 5:48 AM
Hi,
In report u have to use for mail trigering function module...U search and use that function module.....
ISH_SEND_EMAIL
FITV_POWL_SEND_EMAIL
Regards:
Prabu
Edited by: Prabu Kannappan on Aug 25, 2008 6:51 AM
‎2008 Aug 25 5:53 AM
Hi,
Thanks for your reply. But in background job, how it is possible, let me know.
‎2008 Aug 25 5:50 AM
Hi
Check this wiki
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/sendingmailwith+attachment
Regards
Pavan
‎2008 Aug 25 5:55 AM
Hi Dude,
Execute The Following Program as it is.
U will get some Idea.
Here the Important thing is the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'.
tables
packing_list = it_packing_list
contents_txt = it_message "it gives the content list
receivers = it_receivers "it gives the Users List
Hope this Program Helps U.
&----
*& Report ZSENDMAIL
*&
&----
*&
*&
&----
report zsendmail.
parameters: psubject(40) type c default 'Testing'.
PUSH BUTTON
data: it_packing_list like sopcklsti1 occurs 0 with header line,
it_contents like solisti1 occurs 0 with header line,
it_receivers like somlreci1 occurs 0 with header line,
it_attachment like solisti1 occurs 0 with header line,
gd_cnt type i,
gd_sent_all(1) type c,
gd_doc_data like sodocchgi1,
gd_error type sy-subrc.
data: it_message type standard table of solisti1 initial size 0
with header line.
*****************************************
*START-OF-SELECTION.
start-of-selection.
perform populate_message_table.
*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
perform send_email_message.
*Instructs mail send program for SAPCONNECT to send email(rsconn01)
perform initiate_mail_execute_program.
&---------------------------------------------------------------------
*& Form POPULATE_MESSAGE_TABLE
&---------------------------------------------------------------------
adds text to email text table
----------------------------------------------------------------------
form populate_message_table.
data : itab type table of sflight with header line.
data : lv_itab(255) type c.
select carrid
connid from sflight into corresponding fields of table itab
where carrid = 'LH' and connid = '0400'.
loop at itab.
write : / itab-carrid , itab-connid.
concatenate itab-carrid itab-connid into lv_itab separated by space.
append lv_itab to it_message.
endloop.
endform. " POPULATE_MESSAGE_TABLE
*&----
**& Form SEND_EMAIL_MESSAGE
*&----
*send email message
*----
form send_email_message.
*fill the document data.
gd_doc_data-doc_size = 1.
data: tab_lines like sy-tabix.
*
describe table it_message lines tab_lines.
read table it_message index tab_lines.
gd_doc_data-doc_size = ( tab_lines - 1 ) * 255 + strlen( it_message ).
**POPULATE the SUBJECT/GENERIC message ATTRIBUTES
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
**describe the body of the message
**information about structure of data tables
clear it_packing_list.
refresh it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
describe table it_message lines it_packing_list-body_num.
it_packing_list-doc_type = 'RAW'.
append it_packing_list.
**add the recipients email address
clear it_receivers.
refresh it_receivers.
it_receivers-receiver = 'KRK'. "p_email.
it_receivers-rec_type = 'B'.
it_receivers-com_type = 'INT'.
it_receivers-notif_del = 'X'.
it_receivers-notif_ndel = 'X'.
append it_receivers.
it_receivers-receiver = 'OBT'. "p_email.
it_receivers-rec_type = 'B'.
it_receivers-com_type = 'INT'.
it_receivers-notif_del = 'X'.
it_receivers-notif_ndel = 'X'.
append it_receivers.
**CALL the fm TO post the MESSAGE to sapmail
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = gd_doc_data
put_in_outbox = 'X'
importing
sent_to_all = gd_sent_all
tables
packing_list = it_packing_list
contents_txt = it_message
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.
**store function module return code
gd_error = sy-subrc.
**GET it_receivers return code
loop at it_receivers.
endloop.
endform. " SEND_EMAIL_MESSAGE
*&----
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
*&----
**instructs mail send program for sapconnect to send email.
*----
form initiate_mail_execute_program.
wait up to 2 seconds.
if gd_error eq 0.
submit rsconn01 with mode = 'INT'
with output = 'X'
and return.
endif.
endform. " INITIATE_MAIL_EXECUTE_PROGRAM
‎2008 Aug 25 5:58 AM
Hi Mahesh ,
There is no need to write the code in the program,in transaction code sm36 when you schedule the job there is abutton with caption SPOOL LIST recipient .
you can Try that out .
Thnks
Sahil Kakkar
‎2008 Aug 25 6:26 AM
Hi Sahil Kakkar,
Thanks for your reply. But I want to convert the Output in Excel Format. Is it possible to change the Format into Excel in Application Server ( Since report will be executed in Background)
Let me know ,
With Mahesh.
‎2008 Aug 25 5:59 AM
Hi Dude,
Execute This Program as it is.UR requirement will be full filled .
Here the important Thing is the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1'
tables
packing_list = it_packing_list
contents_txt = it_message
receivers = it_receivers
Hope this Code helps U.
&----
*& Report ZSENDMAIL
*&
&----
*&
*&
&----
report zsendmail.
parameters: psubject(40) type c default 'Testing'.
PUSH BUTTON
data: it_packing_list like sopcklsti1 occurs 0 with header line,
it_contents like solisti1 occurs 0 with header line,
it_receivers like somlreci1 occurs 0 with header line,
it_attachment like solisti1 occurs 0 with header line,
gd_cnt type i,
gd_sent_all(1) type c,
gd_doc_data like sodocchgi1,
gd_error type sy-subrc.
data: it_message type standard table of solisti1 initial size 0
with header line.
*****************************************
*START-OF-SELECTION.
start-of-selection.
perform populate_message_table.
*Send email message, although is not sent from SAP until mail send
*program has been executed(rsconn01)
perform send_email_message.
*Instructs mail send program for SAPCONNECT to send email(rsconn01)
perform initiate_mail_execute_program.
&---------------------------------------------------------------------
*& Form POPULATE_MESSAGE_TABLE
&---------------------------------------------------------------------
adds text to email text table
----------------------------------------------------------------------
form populate_message_table.
data : itab type table of sflight with header line.
data : lv_itab(255) type c.
select carrid
connid from sflight into corresponding fields of table itab
where carrid = 'LH' and connid = '0400'.
loop at itab.
write : / itab-carrid , itab-connid.
concatenate itab-carrid itab-connid into lv_itab separated by space.
append lv_itab to it_message.
endloop.
endform. " POPULATE_MESSAGE_TABLE
*&----
**& Form SEND_EMAIL_MESSAGE
*&----
*send email message
*----
form send_email_message.
*fill the document data.
gd_doc_data-doc_size = 1.
data: tab_lines like sy-tabix.
*
describe table it_message lines tab_lines.
read table it_message index tab_lines.
gd_doc_data-doc_size = ( tab_lines - 1 ) * 255 + strlen( it_message ).
**POPULATE the SUBJECT/GENERIC message ATTRIBUTES
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
**describe the body of the message
**information about structure of data tables
clear it_packing_list.
refresh it_packing_list.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
describe table it_message lines it_packing_list-body_num.
it_packing_list-doc_type = 'RAW'.
append it_packing_list.
**add the recipients email address
clear it_receivers.
refresh it_receivers.
it_receivers-receiver = 'KRK'. "p_email.
it_receivers-rec_type = 'B'.
it_receivers-com_type = 'INT'.
it_receivers-notif_del = 'X'.
it_receivers-notif_ndel = 'X'.
append it_receivers.
it_receivers-receiver = 'OBT'. "p_email.
it_receivers-rec_type = 'B'.
it_receivers-com_type = 'INT'.
it_receivers-notif_del = 'X'.
it_receivers-notif_ndel = 'X'.
append it_receivers.
**CALL the fm TO post the MESSAGE to sapmail
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = gd_doc_data
put_in_outbox = 'X'
importing
sent_to_all = gd_sent_all
tables
packing_list = it_packing_list
contents_txt = it_message
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.
**store function module return code
gd_error = sy-subrc.
**GET it_receivers return code
loop at it_receivers.
endloop.
endform. " SEND_EMAIL_MESSAGE
*&----
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
*&----
**instructs mail send program for sapconnect to send email.
*----
form initiate_mail_execute_program.
wait up to 2 seconds.
if gd_error eq 0.
submit rsconn01 with mode = 'INT'
with output = 'X'
and return.
endif.
endform. " INITIATE_MAIL_EXECUTE_PROGRAM