Skip to Content
avatar image
Former Member

how to send result of a report as an email

hi experts,

how to send the result of a report as an email to the user.

plz help

regards,

malleswari.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Dec 07, 2006 at 09:07 AM

    Hi,

    Check this Weblog:

    /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

    Check these link as well..

    http://www.sap-img.com/abap/sending-email-with-attachment.htm

    /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

    I did a search in the forum, an di found lot of threads to send mail from ALV ....

    Look at the below threads

    how-to-send-alv-list-report-as-html-attachment-in

    https://www.sdn.sap.com/irj/sdn/forumsearch

    how-to-send-alv-report-by-mail

    how-to-send-an-alv-grid-report-to-sap-user-mail

    how-to-send-an-alv-grid-report-to-sap-user-mail

    Have a look at below code:

    REPORT ZSENDEXTERNAL.

    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: TAB_LINES LIKE SY-TABIX.

    • Creation of the document to be sent

    • File Name

    DOC_CHNG-OBJ_NAME = 'SENDFILE'.

    • Mail Subject

    DOC_CHNG-OBJ_DESCR = 'Send External Mail'.

    • Mail Contents

    OBJTXT = 'Minimum bid : $250000'.

    APPEND OBJTXT.

    OBJTXT = 'A representation of the pictures up for auction'.

    APPEND OBJTXT.

    OBJTXT = 'was included as attachment.'.

    APPEND OBJTXT.

    DESCRIBE TABLE OBJTXT LINES TAB_LINES.

    READ TABLE OBJTXT INDEX TAB_LINES.

    DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

    • Creation of 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.

    • Creation of the document attachment

    • (Assume that the data in OBJBIN is in BMP format)

    *OBJBIN = ' O/ '. APPEND OBJBIN.

    *OBJBIN = ' | '. APPEND OBJBIN.

    *OBJBIN = ' / '. APPEND OBJBIN.

    *DESCRIBE TABLE OBJBIN LINES TAB_LINES.

    *OBJHEAD = 'PICTURE.BMP'.

    *APPEND OBJHEAD.

    • Creation of the entry for the compressed attachment

    *OBJPACK-TRANSF_BIN = 'X'.

    *OBJPACK-HEAD_START = 1.

    *OBJPACK-HEAD_NUM = 1.

    *OBJPACK-BODY_START = 1.

    *OBJPACK-BODY_NUM = TAB_LINES.

    *OBJPACK-DOC_TYPE = 'BMP'.

    *OBJPACK-OBJ_NAME = 'PICTURE'.

    *OBJPACK-OBJ_DESCR = 'Representation of object 138'.

    *OBJPACK-DOC_SIZE = TAB_LINES * 255.

    *APPEND OBJPACK.

    • Completing the recipient list

    RECLIST-RECEIVER = 'youremail@sap.com'.

    RECLIST-REC_TYPE = 'U'.

    APPEND RECLIST.

    *RECLIST-RECEIVER = 'SAPUSERNAME'.

    *RECLIST-REC_TYPE = 'P'.

    *APPEND RECLIST.

    • Sending the document

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = DOC_CHNG

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

    CASE SY-SUBRC.

    WHEN 0.

    WRITE: / 'Result of the send process:'.

    LOOP AT RECLIST.

    WRITE: / RECLIST-RECEIVER(48), ':'.

    IF RECLIST-RETRN_CODE = 0.

    WRITE 'The document was sent'.

    ELSE.

    WRITE 'The document could not be sent'.

    ENDIF.

    ENDLOOP.

    WHEN 1.

    WRITE: / 'No authorization for sending to the specified number',

    'of recipients'.

    WHEN 2.

    WRITE: / 'Document could not be sent to any recipient'.

    WHEN 4.

    WRITE: / 'No send authorization'.

    WHEN OTHERS.

    WRITE: / 'Error occurred while sending'.

    ENDCASE.

    Reward points if this helps.

    Manish

    Message was edited by:

    Manish Kumar

    Message was edited by:

    Manish Kumar

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 07, 2006 at 09:09 AM

    Hi,

    refer this program.

    REPORT ZSSO_DOCUMENT_SEND_API1.

    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: TAB_LINES LIKE SY-TABIX.

    • Creating the document to be sent

    DOC_CHNG-OBJ_NAME = 'OFFER'.

    DOC_CHNG-OBJ_DESCR = 'Auction of a Picasso jr'.

    OBJTXT = 'Reserve price : $250000'.

    APPEND OBJTXT.

    OBJTXT = 'A reproduction of the painting to be auctioned'.

    APPEND OBJTXT.

    OBJTXT = 'is enclosed as an attachment.'.

    APPEND OBJTXT.

    DESCRIBE TABLE OBJTXT LINES TAB_LINES.

    READ TABLE OBJTXT INDEX TAB_LINES.

    DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 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.

    • Creating the document attachment

    • (Assume the data in OBJBIN are given in BMP format)

    OBJBIN = ' \O/ '. APPEND OBJBIN.

    OBJBIN = ' | '. APPEND OBJBIN.

    OBJBIN = ' / \ '. APPEND OBJBIN.

    DESCRIBE TABLE OBJBIN LINES TAB_LINES.

    OBJHEAD = 'picasso.bmp'. APPEND OBJHEAD.

    • Creating the entry for the compressed attachment

    OBJPACK-TRANSF_BIN = 'X'.

    OBJPACK-HEAD_START = 1.

    OBJPACK-HEAD_NUM = 1.

    OBJPACK-BODY_START = 1.

    OBJPACK-BODY_NUM = TAB_LINES.

    OBJPACK-DOC_TYPE = 'BMP'.

    OBJPACK-OBJ_NAME = 'ATTACHMENT'.

    OBJPACK-OBJ_DESCR = 'Reproduction object 138'.

    OBJPACK-DOC_SIZE = TAB_LINES * 255.

    APPEND OBJPACK..

    • Entering names in the distribution list

    RECLIST-RECEIVER = 'guido.geldsack@money.com'.

    RECLIST-REC_TYPE = 'U'.

    APPEND RECLIST.

    RECLIST-RECEIVER = 'DLI-NEUREICH'.

    RECLIST-REC_TYPE = 'P'.

    APPEND RECLIST.

    • 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.

    CASE SY-SUBRC.

    WHEN 0.

    WRITE: / 'Result of the send process:'.

    LOOP AT RECLIST.

    WRITE: / RECLIST-RECEIVER(48), ':'.

    IF RECLIST-RETRN_CODE = 0.

    WRITE 'sent successfully'.

    ELSE.

    WRITE 'not sent'.

    ENDIF.

    ENDLOOP.

    WHEN 1.

    WRITE: / 'no authorization to send to the specified number of' 'recipients!'.

    WHEN 2.

    WRITE: / 'document could not be sent to any of the recipients!'.

    WHEN 4.

    WRITE: / 'no authorization to send !'.

    WHEN OTHERS.

    WRITE: / 'error occurred during sending !'.

    ENDCASE.

    Regards,

    pankaj singh.

    mark helpful answers

    Add comment
    10|10000 characters needed characters exceeded