Skip to Content
0
Former Member
Mar 30, 2007 at 01:45 PM

sending the output of a program through an email

25 Views

I have to send the output of a report program through an email . I have written the code for that. The program is sending the email but with the characters in some other format . Moreover after sending the email the program is going to dump . In the function table_compress , objbin is getting some other characters than the normal data . I appreciate if some one can help me in this

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.

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.TXT'.

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 = 'TXT'.

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