08-02-2007 6:52 AM
Hi All.
May you please help me out on this one, i am trying to send an ABAP report to Microsoft Outlook? I am not even sure where to start so please help me out i know you can help me...
Kind Regards,
Fred.
08-02-2007 7:02 AM
Hi,
Here is the example program
&----
*& Report ZSENDEMAIL *
*& *
&----
*& Example of sending external email via SAPCONNECT *
*& *
&----
REPORT zsendemail .
PARAMETERS: psubject(40) type c default 'Hello',
p_email(40) type c default 'test@sapdev.co.uk' .
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.
Append 'Email line 1' to it_message.
Append 'Email line 2' to it_message.
Append 'Email line 3' to it_message.
Append 'Email line 4' to it_message.
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.
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
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 = p_email.
it_receivers-rec_type = 'U'.
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
Regards
Sudheer
08-02-2007 7:02 AM
Hi,
Here is the example program
&----
*& Report ZSENDEMAIL *
*& *
&----
*& Example of sending external email via SAPCONNECT *
*& *
&----
REPORT zsendemail .
PARAMETERS: psubject(40) type c default 'Hello',
p_email(40) type c default 'test@sapdev.co.uk' .
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.
Append 'Email line 1' to it_message.
Append 'Email line 2' to it_message.
Append 'Email line 3' to it_message.
Append 'Email line 4' to it_message.
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.
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
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 = p_email.
it_receivers-rec_type = 'U'.
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
Regards
Sudheer
08-02-2007 7:06 AM
08-02-2007 7:40 AM
Hi ,
Please see this sample code.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
commit_work = 'X'
put_in_outbox = 'X'
IMPORTING
sent_to_all = sent_to_all
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.
COMMIT WORK.
IF sent_to_all = 'X'.
MESSAGE s000 WITH 'Fax queued sucessfully !!'.
ENDIF.
Other wise by using where used list we can find the programs where this FM was used and check the sample code from your end.
Hope this helps you. Reply for queries, shall post the updates.
Regards.
Kumar.
08-02-2007 9:13 AM
Have a look at:
<a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/ae/16193ce8fac413e10000000a114084/content.htm">http://help.sap.com/saphelp_nw2004s/helpdata/en/ae/16193ce8fac413e10000000a114084/content.htm</a>
where it describes how you can set up a print destination that will allow you / your user to direct any report output to an email address. This uses SPAD to define an output device that does all the hard work for you.
08-02-2007 9:18 AM
Hi Fred,
Try this code ..it might help you/.........
report zemail.
data : w_name type sos04-l_adr_name.
tables: pa0001.
select-options :
Recipient address
s_name for w_name default sy-uname no intervals.
----
start-of-selection.
E-mail Abap report
perform f_send_mail.
----
Form f_send_mail
----
form f_send_mail.
Data Declaration
data:
l_datum(10),
ls_docdata type sodocchgi1,
lt_objpack type table of sopcklsti1 with header line,
lt_objhead type table of solisti1 with header line,
lt_objtxt type table of solisti1 with header line,
lt_objbin type table of solisti1 with header line,
lt_reclist type table of somlreci1 with header line,
lt_listobject type table of abaplist with header line,
l_tab_lines type i,
l_att_type like soodk-objtp.
write sy-datum to l_datum.
NOTE: Create ALI/OTF Document in Spool
SUBMIT ZHRRPT0003 WITH S_AEDTM BETWEEN '20050101' AND '20060101' SIGN
'I' EXPORTING LIST TO MEMORY AND RETURN.
Read list from memory into table
call function 'LIST_FROM_MEMORY'
tables
listobject = lt_listobject
exceptions
not_found = 1
others = 2.
if sy-subrc <> 0.
Error in function module &1
message id '61' type 'E' number '731'
with 'LIST_FROM_MEMORY'.
endif.
Because listobject is of size RAW(1000)
and objbin is of size CHAR(255) we make this table copy
call function 'TABLE_COMPRESS'
tables
in = lt_listobject
out = lt_objbin
exceptions
compress_error = 1
others = 2.
if sy-subrc <> 0.
Error in function module &1
message id '61' type 'E' number '731'
with 'TABLE_COMPRESS'.
endif.
NOTE: Creation of attachment is finished yet.
For your report, the attachment should be placed into table
objtxt for plain text or
objbin for binary content.
Now create the message and send the document.
Create Message Body
Title and Description
ls_docdata-obj_name = 'HR Changes'.
concatenate 'List of HR Changes'
into ls_docdata-obj_descr separated by space.
Main Text
lt_objtxt = ' List of HR Changes'
append lt_objtxt.
Write Packing List (Main)
describe table lt_objtxt lines l_tab_lines.
read table lt_objtxt index l_tab_lines.
ls_docdata-doc_size = ( l_tab_lines - 1 ) * 255 + strlen( lt_objtxt ).
clear lt_objpack-transf_bin.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = 'RAW'.
append lt_objpack.
Create Message Attachment
Write Packing List (Attachment)
l_att_type = 'ALI'.
describe table lt_objbin lines l_tab_lines.
read table lt_objbin index l_tab_lines.
lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255 + strlen( lt_objbin ).
lt_objpack-transf_bin = 'X'.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = l_att_type.
lt_objpack-obj_name = 'ATTACHMENT'.
lt_objpack-obj_descr = 'List_of_HR_Changes'. "#EC *
append lt_objpack.
Create receiver list
loop at s_name.
lt_reclist-receiver = s_name-low.
lt_reclist-rec_type = 'U'.
append lt_reclist.
endloop.
Send Message
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = ls_docdata
put_in_outbox = 'X'
tables
packing_list = lt_objpack
object_header = lt_objhead
contents_bin = lt_objbin
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.
if sy-subrc = 0.
Document sent
message id 'SO' type 'S' number '022'.
else.
Document <&> could not be sent
message id 'SO' type 'S' number '023'
with ls_docdata-obj_name.
endif.
Plz reward points if answer is useful...
Regards,
Mandeep.