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: 

How to send the Report output thru email

Former Member
0 Kudos

Dear All,

Is there a way to send the output of a abap report thru mail. I am sure it is there.

My report output is as following.

-


Emp Code : A01234

Name: XYZ

Email-ID: xyz@abc.com

Dear XYZ,

You have Rs....... as outstanding. Please clear all dues by ..(date).

Thankyou,

asdf.

-


Please advice how to accomplish this. Send a sample source code if possible.

Regards,

Alok.

3 REPLIES 3

Former Member
0 Kudos

HI

Check the following link, which will help you in sending mail.

Prepare data that is displayed in the output as an internal table and use that to send it in a mail.

Kind Regards

Eswar

0 Kudos

Below you can find the sample code for sending the report as email.

Do use this as cross reference..

DATA: reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objhex LIKE solix OCCURS 10 WITH HEADER LINE,

listobject LIKE abaplist OCCURS 0 WITH HEADER LINE,

so_ali LIKE soli OCCURS 0 WITH HEADER LINE,

list_index LIKE sy-lsind VALUE 0,

packing_list LIKE sopcklsti1,

docdata LIKE sodocchgi1,

tab_lines TYPE i,

l_rqident LIKE tsp01-rqident,

att_type LIKE soodk-objtp.

objtxt[] = mail_text[].

IF p_skip_attach IS INITIAL. " INS SIR 3971 TODD

SYSTEM-CALL LOAD LISTLEVEL-STACK INTO wrkstack.

IF wrkstack[] IS INITIAL.

SKIP 2.

WRITE: /30 text-001 COLOR 5.

ENDIF.

ENDIF. " INS SIR 3971 TODD

  • Prepare Receipient List

REFRESH: reclist.

LOOP AT rcpnt_userids.

IF rcpnt_userids-l_adr_name NA '@'.

reclist-receiver = rcpnt_userids-usrnam.

reclist-rec_type = 'B'.

reclist-express = 'X'.

ELSE.

reclist-receiver = rcpnt_userids-l_adr_name.

reclist-rec_type = 'U'.

reclist-express = 'X'.

ENDIF.

APPEND reclist.

CLEAR reclist.

ENDLOOP.

  • Prepare Doc Data

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

docdata-obj_langu = sy-langu.

docdata-obj_name = 'ABAP Listing'.

docdata-obj_descr = subject.

docdata-sensitivty = 'O'.

  • Prepare OBJPACK

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.

att_type = 'ALI'.

DESCRIBE TABLE so_ali LINES tab_lines.

READ TABLE so_ali INDEX tab_lines.

objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( so_ali ).

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = subject.

APPEND objpack.

  • SAP supplied API function module to send Message

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

put_in_outbox = 'X'

commit_work = 'X' "used from rel. 6.10

TABLES

packing_list = objpack

object_header = objhead

contents_bin = so_ali

contents_txt = objtxt

receivers = reclist

EXCEPTIONS

too_many_reclist = 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.

MESSAGE i398(00) WITH 'SAP Office API Error'

sy-subrc

''.

ENDIF.

Former Member
0 Kudos

Hi Alok,

put the text in an internal table and send it via email.

Here a short example:

REPORT ZGRO_TEST.

*

DATA: OBJ_PACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

OBJ_BIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

OBJ_TXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

REC_LIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

DOC_DATA LIKE SODOCCHGI1.

*

START-OF-SELECTION.

*

DOC_DATA-OBJ_NAME = SY-REPID.

DOC_DATA-OBJ_DESCR = 'Message'.

*

REC_LIST-RECEIVER = 'xxx@xxx.de'. "the receiver-email address

REC_LIST-REC_TYPE = 'U'.

APPEND REC_LIST.

*

OBJ_PACK-BODY_START = 01.

OBJ_PACK-BODY_NUM = 03.

OBJ_PACK-DOC_TYPE = 'RAW'.

APPEND OBJ_PACK.

*

OBJ_TXT-LINE = 'Guten Tag,'.

APPEND OBJ_TXT.

OBJ_TXT-LINE = 'ich bin ein email-Text.'.

APPEND OBJ_TXT.

OBJ_TXT-LINE = 'Regards, Dieter'.

APPEND OBJ_TXT.

*

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_DATA

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = OBJ_PACK

CONTENTS_TXT = OBJ_TXT

CONTENTS_BIN = OBJ_BIN

RECEIVERS = REC_LIST.

*

IF SY-SUBRC <> 0.

WRITE: / SY-SUBRC.

EXIT.

ENDIF.

*

WAIT UP TO 2 SECONDS.

*

SUBMIT RSCONN01 WITH MODE = 'INT'

WITH OUTPUT = ' '

AND RETURN.

*

END-OF-SELECTION.

Hope it helps.

Regards, Dieter