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: 

sending the output through an email

Former Member
0 Kudos

Attached below is my code for sending the output through an email . An email is sent with an attachment but there is no data in it . I very much appreciate if someone can correct my code

TABLES : ADR6.

----


  • *

  • SELECTION SCREEN *

----


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETERS : USER LIKE SY-UNAME DEFAULT 'EMERGENCY'.

PARAMETERS : DATE LIKE SY-DATUM DEFAULT SY-DATUM.

PARAMETERS : RUNTIME LIKE SY-UZEIT DEFAULT '235900'.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

SELECTION-SCREEN SKIP 1.

PARAMETERS : EMAIL AS CHECKBOX. " to send email

SELECT-OPTIONS : S_EMAIL FOR ADR6-SMTP_ADDR. " Email address

SELECTION-SCREEN END OF BLOCK B2.

----


  • INTERNAL TABLES DECLARATION *

----


data: begin of html_tab occurs 0.

include structure w3html.

data: end of html_tab.

data: itab like abaplist occurs 0 with header line.

  • Table for storing different email addresses

DATA : BEGIN OF I_EMAIL OCCURS 0,

ADDRNUMBER LIKE ADR6-ADDRNUMBER,

SMTP_ADDR LIKE ADR6-SMTP_ADDR,

END OF I_EMAIL.

  • For storing the receivers details

DATA : RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE.

  • for storing information about how the data in the

  • tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are

  • to be distributed to the documents and its attachments.

DATA : OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

  • For storing the summarized content of the objects identified as ASCII

  • objects.

DATA : OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA : OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA : OBJBIN TYPE STANDARD TABLE OF SOLISTI1 INITIAL SIZE 0 WITH HEADER

LINE.

DATA : DOC_CHNG LIKE SODOCCHGI1.

----


  • VARIABLES DECLARATION

----


DATA: tab_lines LIKE sy-tabix.

  • ------------ ------------------------------------------------------*

  • TOP-OF-PAGE *

----


TOP-OF-PAGE.

----


  • AT SELECTION-SCREEN OUTPUT *

----


AT SELECTION-SCREEN OUTPUT.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

PERFORM CALL_STAD.

----


  • END-OF-SELECTION *

----


END-OF-SELECTION.

  • checking if the email option is selected and sending email only

  • if there is any data in the table

IF EMAIL = 'X'.

PERFORM SEND_EMAIL.

ENDIF.

&----


*& FORM CALL_STAD

&----


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 'WWW_HTML_FROM_LISTOBJECT'

exporting

  • REPORT_NAME =

template_name = 'WEBREPORTING_REPORT'

tables

html = html_tab

listobject = itab.

ENDFORM.

&----


*& 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.

&----


*& 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

CLEAR OBJPACK-transf_bin.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

  • 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 = 'htm'.

OBJPACK-OBJ_NAME = 'ATTACHMENT'.

OBJPACK-OBJ_DESCR = 'stad '.

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.

&----


*& 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.

2 REPLIES 2

Former Member
0 Kudos

Add this:

<b>OBJBIN[] = itab[].</b>

just before the "DESCRIBE TABLE OBJBIN LINES TAB_LINES."

0 Kudos

I am getting the error ' objbin and itab are not mutually convertible'