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 program

Former Member
0 Kudos

i am generating the email from my report program..but i am getting the runtime error..the email format i made using sapscripts..can any one suggest a solution to it..it will be useful if i get the sample code for it..

5 REPLIES 5

Former Member
0 Kudos

Hi,

Check this <a href="http://www.sapdevelopment.co.uk/reporting/email/emailhome.htm">link.</a>

which contains sample programs also.

Better do a search with term 'email' in abap forum , you will get tons of examples .

Hope This Info Helps YOU.

Regards,

Raghav

0 Kudos

what is the runtime error?

Regards,

Rich Heilman

Former Member
0 Kudos

Hi,

<b>Here is the very simple code to send mail from abap program.</b>

*********************************

REPORT Zlat1.

DATA : L_TABLE_LINES LIKE SY-TABIX, " table index

L_TAB TYPE X VALUE '09', " TAB value

L_MANDT TYPE SY-MANDT. " Client

DATA: X_DOC_CHNG LIKE SODOCCHGI1, " document attributes

IT_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

" attachment table

IT_OBJHEAD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

" object header table

IT_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

" binary table

IT_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

IT_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE.

CLEAR IT_RECLIST.

REFRESH IT_RECLIST.

*-popualate email ids

IT_RECLIST-RECEIVER = 'id@company.com'.

IT_RECLIST-REC_TYPE = 'U'.

*-append receiver table

APPEND IT_RECLIST.

CLEAR IT_RECLIST.

*-populate document attributes

CLEAR: X_DOC_CHNG.

X_DOC_CHNG-OBJ_NAME = 'HEADING'.

X_DOC_CHNG-OBJ_DESCR = 'SOME DESCRIPTION'.

*-populate body text

IT_OBJTXT = 'ARCOS Reporting Extraction Error file is attached'.

APPEND IT_OBJTXT.

*-document size

CLEAR : L_TABLE_LINES.

DESCRIBE TABLE IT_OBJTXT LINES L_TABLE_LINES.

READ TABLE IT_OBJTXT INDEX L_TABLE_LINES.

X_DOC_CHNG-DOC_SIZE =

( L_TABLE_LINES - 1 ) * 255 + STRLEN( IT_OBJTXT ).

*-populate packing list for body text

CLEAR IT_OBJPACK-TRANSF_BIN.

IT_OBJPACK-HEAD_START = 1.

IT_OBJPACK-HEAD_NUM = 0.

IT_OBJPACK-BODY_START = 1.

IT_OBJPACK-BODY_NUM = L_TABLE_LINES.

IT_OBJPACK-DOC_TYPE = 'RAW'.

APPEND IT_OBJPACK.

CLEAR IT_OBJPACK.

*-populate object header

IT_OBJHEAD = 'Arcos Error Report'(057).

APPEND IT_OBJHEAD.

CLEAR IT_OBJHEAD.

*--for attachment ---start

*-populate object bin table for attachment

*-column header

CONCATENATE 'Document No.'

'Year'

  • 'Item'

  • 'Material No.'

'Error Text'

INTO IT_OBJBIN SEPARATED BY L_TAB.

APPEND IT_OBJBIN.

CLEAR IT_OBJBIN.

*-error details

CONCATENATE '1'

'1st record'

'1st record in attachment'

INTO IT_OBJBIN SEPARATED BY L_TAB.

APPEND IT_OBJBIN.

CLEAR IT_OBJBIN.

CONCATENATE '2'

'2st record'

'2st record in attachment'

INTO IT_OBJBIN SEPARATED BY L_TAB.

APPEND IT_OBJBIN.

CLEAR IT_OBJBIN.

*-get total no.of lines of Object table(attachment)

CLEAR : L_TABLE_LINES.

DESCRIBE TABLE IT_OBJBIN LINES L_TABLE_LINES.

*-populate object header

IT_OBJHEAD = 'Report'.

APPEND IT_OBJHEAD.

CLEAR IT_OBJHEAD.

*-packing list for attachment

IT_OBJPACK-TRANSF_BIN = 'X'.

IT_OBJPACK-HEAD_START = 1.

IT_OBJPACK-HEAD_NUM = 1.

IT_OBJPACK-BODY_START = 1.

IT_OBJPACK-BODY_NUM = L_TABLE_LINES .

IT_OBJPACK-DOC_TYPE = 'RAW' .

IT_OBJPACK-OBJ_NAME = 'ABCD'.

IT_OBJPACK-OBJ_DESCR = 'ERROR REPORT'.

IT_OBJPACK-DOC_SIZE = L_TABLE_LINES * 255.

APPEND IT_OBJPACK.

CLEAR IT_OBJPACK.

*--code for attachment -- end

*-Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = X_DOC_CHNG

PUT_IN_OUTBOX = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

PACKING_LIST = IT_OBJPACK

OBJECT_HEADER = IT_OBJHEAD

CONTENTS_BIN = IT_OBJBIN

CONTENTS_TXT = IT_OBJTXT

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

RECEIVERS = IT_RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*********************************

rgds,

latheesh

Former Member
0 Kudos

Hai

Check the following Code

REPORT ZRICH_0003.

DATA: ITCPO LIKE ITCPO,

TAB_LINES LIKE SY-TABIX.

  • Variables for EMAIL functionality

DATA: MAILDATA LIKE SODOCCHGI1.

DATA: MAILPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: MAILHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: MAILBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILREC LIKE SOMLREC90 OCCURS 0 WITH HEADER LINE.

DATA: SOLISTI1 LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.

PERFORM SEND_FORM_VIA_EMAIL.

************************************************************************

  • FORM SEND_FORM_VIA_EMAIL *

************************************************************************

FORM SEND_FORM_VIA_EMAIL.

CLEAR: MAILDATA, MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

REFRESH: MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

  • Creation of the document to be sent File Name

MAILDATA-OBJ_NAME = 'TEST'.

  • Mail Subject

MAILDATA-OBJ_DESCR = 'Subject'.

  • Mail Contents

MAILTXT-LINE = 'Here is your file'.

APPEND MAILTXT.

  • Prepare Packing List

PERFORM PREPARE_PACKING_LIST.

  • Set recipient - email address here!!!

MAILREC-RECEIVER = 'itsme@whatever.com'.

MAILREC-REC_TYPE = 'U'.

APPEND MAILREC.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = MAILDATA

PUT_IN_OUTBOX = ' '

TABLES

PACKING_LIST = MAILPACK

OBJECT_HEADER = MAILHEAD

CONTENTS_BIN = MAILBIN

CONTENTS_TXT = MAILTXT

RECEIVERS = MAILREC

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

ENDFORM.

************************************************************************

  • Form PREPARE_PACKING_LIST

************************************************************************

FORM PREPARE_PACKING_LIST.

CLEAR: MAILPACK, MAILBIN, MAILHEAD.

REFRESH: MAILPACK, MAILBIN, MAILHEAD.

DESCRIBE TABLE MAILTXT LINES TAB_LINES.

READ TABLE MAILTXT INDEX TAB_LINES.

MAILDATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( MAILTXT ).

  • Creation of the entry for the compressed document

CLEAR MAILPACK-TRANSF_BIN.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 0.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'RAW'.

APPEND MAILPACK.

  • Creation of the document attachment

  • This form gets the OTF code from the SAPscript form.

  • If you already have your OTF code, I believe that you may

  • be able to skip this form. just do the following code, looping thru

  • your SOLISTI1 and updating MAILBIN.

PERFORM GET_OTF_CODE.

LOOP AT SOLISTI1.

MOVE-CORRESPONDING SOLISTI1 TO MAILBIN.

APPEND MAILBIN.

ENDLOOP.

DESCRIBE TABLE MAILBIN LINES TAB_LINES.

MAILHEAD = 'TEST.OTF'.

APPEND MAILHEAD.

    • Creation of the entry for the compressed attachment

MAILPACK-TRANSF_BIN = 'X'.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 1.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'OTF'.

MAILPACK-OBJ_NAME = 'TEST'.

MAILPACK-OBJ_DESCR = 'Subject'.

MAILPACK-DOC_SIZE = TAB_LINES * 255.

APPEND MAILPACK.

ENDFORM.

************************************************************************

  • Form GET_OTF_CODE

************************************************************************

FORM GET_OTF_CODE.

DATA: BEGIN OF OTF OCCURS 0.

INCLUDE STRUCTURE ITCOO .

DATA: END OF OTF.

DATA: ITCPO LIKE ITCPO.

DATA: ITCPP LIKE ITCPP.

CLEAR ITCPO.

ITCPO-TDGETOTF = 'X'.

  • Start writing OTF code

CALL FUNCTION 'OPEN_FORM'

EXPORTING

FORM = 'ZTEST_FORM'

LANGUAGE = SY-LANGU

OPTIONS = ITCPO

DIALOG = ' '

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'START_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'MAIN'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

  • Close up Form and get OTF code

CALL FUNCTION 'END_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

MOVE-CORRESPONDING ITCPO TO ITCPP.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

RESULT = ITCPP

TABLES

OTFDATA = OTF

EXCEPTIONS

OTHERS = 1.

  • Move OTF code to structure SOLI form email

CLEAR SOLISTI1. REFRESH SOLISTI1.

LOOP AT OTF.

SOLISTI1-LINE = OTF.

APPEND SOLISTI1.

ENDLOOP.

ENDFORM.

Thanks & regards

Sreenivasulu P

Former Member
0 Kudos

Hi raj,

check this link. u will find a lot of sample programs.

regards,

keerthi.