Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

report output to email

Former Member
0 Kudos

i need to send my report out put to email can any one give me the code for it

3 REPLIES 3

Former Member
0 Kudos

Hi,

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 

Regards

Sudheer

0 Kudos

i need full code

Former Member
0 Kudos

DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.

DATA: objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.

DATA: doc_chng LIKE sodocchgi1.

DATA: msg_lines LIKE sy-tabix,

att_lines LIKE sy-tabix,

addr_flag LIKE sy-input,

addr LIKE soos1-adr_name.

  • Creation of the document to be sent

doc_chng-obj_name = email_title.

doc_chng-obj_descr = email_title.

LOOP AT email_msg.

objtxt = email_msg.

APPEND objtxt.

ENDLOOP.

DESCRIBE TABLE objtxt LINES msg_lines.

READ TABLE objtxt INDEX msg_lines.

doc_chng-doc_size = ( msg_lines - 1 ) * 255 + STRLEN( objtxt ).

  • Creation of the entry for the compressed document

objpack-transf_bin = ' '.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = msg_lines.

objpack-doc_type = 'RAW'.

APPEND objpack.

  • Creation of the document attachment

DESCRIBE TABLE attachment LINES att_lines.

IF att_lines <> 0. "Don't create attachment if no data is present

LOOP AT attachment.

objtxt = attachment.

APPEND objtxt.

ENDLOOP.

objhead = file_name.

APPEND objhead.

  • Creation of the entry for the compressed attachment

objpack-transf_bin = ' '.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = msg_lines + 1.

objpack-body_num = att_lines.

*objpack-body_num = tab_lines.

IF excel_flag = 'X'.

objpack-doc_type = 'CSV'.

ENDIF.

objpack-obj_name = file_name.

objpack-obj_descr = file_name.

objpack-doc_size = att_lines * 255. " + STRLEN( attachment ).

APPEND objpack.

ENDIF.

  • Completing the recipient list

LOOP AT email_receiver.

reclist-receiver = email_receiver-addr.

reclist-rec_type = 'U'.

reclist-express = 'X'.

APPEND reclist.

ENDLOOP.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = doc_chng

put_in_outbox = 'X'

commit_work = commit_work

TABLES

packing_list = objpack

object_header = objhead

contents_txt = objtxt

receivers = reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

IF sy-subrc <> 0.

RAISE email_not_sent.

ENDIF.