11-01-2007 1:29 AM
Hi SAP Guru,
I executed a report and I wanted the report to be send according to the respective User immediately thru SAP email as attachment automatically.
No intervention required.
How should I proceed? what FM to use? report is abap list.
11-01-2007 1:36 AM
Hi,
use FM SO_NEW_DOCUMENT_ATT_SEND_API1. it has detailed documentation as how to use and also a sample code.
Regards,
Atish
11-01-2007 3:10 AM
FORM CALL_STAD.
SUBMIT RSSTAT20 WITH RUSER = USER
WITH RDAY = date
WITH RENDTI = '240000'
exporting list to memory
AND RETURN.
call function 'LIST_FROM_MEMORY'
TABLES
listobject = itab
EXCEPTIONS
not_found = 1.
IF SY-SUBRC NE 0.
LEAVE PROGRAM.
ENDIF.
Convert to HTML
data: htmllines type table of w3html with header line.
call function 'WWW_HTML_FROM_LISTOBJECT'
tables
html = htmllines
listobject = ITAB.
loop at htmllines.
objbin = htmllines.
append objbin.
endloop.
*CALL FUNCTION 'TABLE_COMPRESS'
*TABLES
*in = itab
*out = objbin
*EXCEPTIONS
*compress_error = 1
*OTHERS = 2.
ENDFORM. "CALL_STAD
&----
*& FORM SEND_EMAIL
&----
FORM SEND_EMAIL.
PERFORM SET_TABLES_PARAMETERS. " for setting the parameters for the
" function
PERFORM CALL_SEND_EMAIL. " calling the function for sending email
ENDFORM. "SEND_EMAIL
&----
*& FORM SET_TABLES_PARAMETERS
&----
FORM SET_TABLES_PARAMETERS.
body of the email
OBJTXT = 'Hi'.
APPEND OBJTXT.
OBJTXT = 'Attached is the document showing the output for the transaction stad' .
CONCATENATE OBJTXT ' for the user EMERGENCY date ' INTO objtxt.
CONCATENATE OBJTXT date ' start time 00:00:00 and the read time 24 hrs ' INTO OBJTXT
SEPARATED BY SPACE.
APPEND OBJTXT .
OBJTXT = 'Do not reply to this email as this was generated from SAP.'.
APPEND OBJTXT.
DESCRIBE TABLE OBJTXT LINES TAB_LINES.
READ TABLE OBJTXT INDEX TAB_LINES .
storing attributes of the document to be sent
DOC_CHNG-OBJ_NAME = 'OFFER'.
DOC_CHNG-OBJ_DESCR = 'Statistics for user EMERGENCY'.
DOC_CHNG-DOC_SIZE = ( TAB_LINES ) * 255 + STRLEN( OBJTXT ).
creating the entry for the compressed document
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
Storing the name of the attachment
OBJHEAD = 'STAD.HTM' . " <-----CHANGE THIS
APPEND OBJHEAD.
creating the entry for the compressed document
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 = 'ATTACHMENT'.
OBJPACK-OBJ_DESCR = 'HTM'. " <-----CHANGE THIS
OBJPACK-DOC_SIZE = TAB_LINES * 255.
APPEND OBJPACK.
for storing the receivers list in the table
LOOP AT S_EMAIL.
RECLIST-RECEIVER = S_EMAIL-LOW.
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
CLEAR RECLIST.
CLEAR S_EMAIL.
ENDLOOP.
ENDFORM. "SET_TABLES_PARAMETERS
&----
*& FORM CALL_SEND_EMAIL
&----
FORM CALL_SEND_EMAIL.
Calling the function for Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
put_in_outbox = 'X'
commit_work = '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.
WAIT UP TO 2 SECONDS.
SUBMIT RSCONN01 WITH MODE = 'INT'
WITH OUTPUT = 'X' AND RETURN.
ENDFORM. "CALL_SEND_EMAIL
You might want to write a small program that retrieves your spool information, and send the corresponding ALV (internal table) by converting it and sending it via SAP Connect. Here is a sample of hos to attach and send your internal table:
FORM send_file .
DATA: send_request TYPE REF TO cl_bcs,
text TYPE bcsy_text,
document TYPE REF TO cl_document_bcs,
recipient TYPE REF TO if_recipient_bcs,
copy TYPE ad_smtpadr,
bcs_exception TYPE REF TO cx_bcs,
sent_to_all TYPE os_boolean,
att_name TYPE sood-objdes,
subject TYPE so_obj_des.
Get attachment name
CONCATENATE g_ret_id '_' sy-datum sy-uzeit '_' g_fileid '.CSV' INTO
att_name.
TRY.
Create the send request
send_request = cl_bcs=>create_persistent( ).
Create the document with attachments
Main document
APPEND 'Attachment test' TO text.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = text
i_subject = subject ).
Add text attachment to document
document->add_attachment( i_attachment_type = 'CSV'
i_attachment_subject = att_name
i_att_content_text = itab_file ).
send_request->set_document( document ).
Create recipient and add to send request
LOOP AT itab_recipients INTO wa_recipients.
IF wa_recipients-copy IS INITIAL.
"To recipient
MOVE wa_recipients-address TO g_rec_send.
recipient = cl_cam_address_bcs=>create_internet_address(
g_rec_send ).
send_request->add_recipient( i_recipient = recipient ).
CLEAR g_rec_send.
ELSE.
"CC
MOVE wa_recipients-address TO g_rec_send.
recipient = cl_cam_address_bcs=>create_internet_address(
g_rec_send ).
send_request->add_recipient( i_recipient = recipient
i_copy = 'X' ).
CLEAR g_rec_send.
ENDIF.
ENDLOOP.
Send
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
IF sent_to_all = 'X'.
MESSAGE s022.
ENDIF.
CATCH cx_bcs INTO bcs_exception.
MESSAGE e865 WITH bcs_exception->error_type.
ENDTRY.
ENDFORM. " send_file
REPORT TO EMAIL
Check the code...on http://sap4.com/wiki/index.php?title=ZOUTLOOK
Rewards if useful.......................
Minal