‎2006 Feb 13 7:24 AM
Hi folks,
I have a requirement like i have to send report output as an attachment to email.
I am new to this requirement.
Can any body guide how to proceed...
Plz do explain me the procedure clearly..
Thanks in advance.
Regards,
Raja.
‎2006 Feb 13 7:27 AM
Hi raja,
1. SO_NEW_DOCUMENT_ATT_SEND_API1
This is the FM.
2. Please see the documentation on this FM.
The documentation will clearly
state how to use it.
3. This FM is quite complicated to use,
hence, reading the documentation is a MUST.
regards,
amit m.
‎2006 Feb 13 7:30 AM
hi,
check this sample code..
http://www.geocities.com/mpioud/Z_EMAIL_ABAP_REPORT.html
REPORT z_email_abap_report.
*---------------------------------------------------------------------*
* E-mail an Abap report *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : mpioud@yahoo.fr HomePage : <a href="http://www.geocities.com/mpioud" TARGET="test_blank">http://www.geocities.com/mpioud</a> *
*---------------------------------------------------------------------*
DATA : w_name TYPE sos04-l_adr_name.
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.
* List of Users According to Logon Date and Password Change
* NOTE: Create ALI/OTF Document in Spool
SUBMIT rsusr200 WITH valid = 'X'
WITH notvalid = space
WITH unlocked = 'X'
WITH locked = space
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 = 'USERS_LIST'.
CONCATENATE 'List of Users' sy-sysid '-' l_datum "#EC *
INTO ls_docdata-obj_descr SEPARATED BY space.
* Main Text
lt_objtxt = 'List of Users According to Logon Date' &
' and Password Change'. "#EC *
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_Users'. "#EC *
APPEND lt_objpack.
* Create receiver list
LOOP AT s_name.
lt_reclist-receiver = s_name-low.
lt_reclist-rec_type = 'B'.
APPEND lt_reclist.
ENDLOOP.
* Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = ls_docdata
put_in_outbox = ''
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.
ENDFORM. " F_SEND_MAILregards
vijay
‎2006 Feb 13 7:31 AM
Please search the forum before posting a new question. this topic has been discussed a lot here, if you search you would find lot of code samples for this.
Regards
Raja
‎2006 Feb 13 8:23 AM
Hi,
Chk out this sample program:
*&---------------------------------------------------------------------*
*& Report ZSENDEMAIL *
*& *
*&---------------------------------------------------------------------*
*& Example of sending external email via SAPCONNECT *
*& *
*&---------------------------------------------------------------------*
REPORT zsendemail .
PARAMETERS: psubject(40) type c default 'Testing',
p_email(40) type c default 'anjali.devi@wipro.com'.
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 'Line1' to it_message.
Append 'Line2' to it_message.
Append 'Line3' to it_message.
Append 'Test- 1' 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
* 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 = p_email.
it_receivers-rec_type = 'U'.
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
*
Best Regards,
Anjali.
Please reward, and close the thread once the problem is solved.
‎2006 Apr 20 3:21 PM
I am getting an exception message 'No Messages sent '. What could be the reason ? Any initial configurations to be done ?
Thanks & Regards,
Shankar
‎2006 Feb 13 8:34 AM
Amit,
Thanks for ur valuable advice.
i am Going thru that FM..
Kindly clarify me the following things.
FM:SO_NEW_DOCUMENT_ATT_SEND_API1
DOCUMENT_DATA->Sensitivity...what does it mean?
PROC_TYPE....explain this.
TO_DO_OUT...usage?
Can u explain the above mentioned?
Raja.
‎2006 Feb 13 8:49 AM
HI again,
1. These all parameters for mainly
if the mail is SAPOFFICE MAIL.
(and not email to external address like
yahoo.com etc)
2. Basically, these parameters
are not used / not required
for practically emailing purpose.
However, what i know, is below :
3. DOCUMENT_DATA->Sensitivity...
Just like in outlook express
we have Urgent, Medium, etc.
Priority/sensitivty,
this should be so.
4. PROC_TYPE
Execute: Type (Report, Dialog Module, ...)
5. Execute: Type (Report, Dialog Module, ...)
??Not aware
regards,
amit m.
‎2006 Feb 13 9:05 AM
Amit,
thanks for the reply..
please do explain me abt PROC_type.
what is the usage?
i mean what r options mean..like report,dialog module..etc.
actually if i want to send report output as an email..then i have to mark it report??
what is for dialog module option for?? and remaining...
reply me.
Raja.