Skip to Content
author's profile photo Former Member
Former Member

Sending Internal Table data as mail

Hiiii

How can we send internal table data as mail to an external email id?

Thanx,

Vaneet Thakur

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on May 29, 2013 at 05:34 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 29, 2013 at 05:59 AM

    Hi,

    you could use ALV Grid, convert it in HTML and send the mail (please use the Oo, not the function)

    regards

    Fred

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 29, 2013 at 06:46 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 29, 2013 at 07:26 AM

    Hi,

    Use BCS method to send email, i have snippet of coding attached. You just pass the internal table as content to the function module already written in this attachment.

    You can also use the html coding to prepare the email content as table look a like.

    refer this link

    http://scn.sap.com/community/abap/application-development/blog/2012/03/27/simple-bcs-email-method-withwithout-attachment

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 29, 2013 at 05:35 AM
    -1

    Please use the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    Add a comment
    10|10000 characters needed characters exceeded

    • Please never use the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1'. Go for CL_BCS instead.

      Sending internal data per mail depends of what kind of mail you want. Loop at the table, for each table line loop at the structure components, WRITE or MOVE content to text line. Use fixed length format or separate fields by tab character. Put directly in mail body or create attachment.

      So many options.

      Regards,

      Clemens

  • author's profile photo Former Member
    Former Member
    Posted on May 29, 2013 at 05:38 AM
    -1

    Hi,

    pls check FM "SO_NEW_DOCUMENT_ATT_SEND_API1" they mentioned documentation also.

    rgds,

    Krishna

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 29, 2013 at 05:40 AM
    -1

    HI vaneet,

    check

    http://wiki.sdn.sap.com/wiki/display/ABAP/Send+Message+to+External+email+id+and+SAP+User+id+via+ABAP

    http://saptechnical.com/Tips/ABAP/email/Anyformat.htm

    http://wiki.sdn.sap.com/wiki/display/ABAP/Send+Message+to+External+email+id+and+SAP+User+id+via+ABAP

    CONTENTS_TXT = it_objtxt

    in this pass your internal table content.check sample code i used to send in HTML format without any attachment.

    *&---------------------------------------------------------------------*

    *& Form SEND_MAIL

    *&---------------------------------------------------------------------*

    * text

    *----------------------------------------------------------------------*

    * --> p1 text

    * <-- p2 text

    *----------------------------------------------------------------------*

    FORM SEND_MAIL .

    * Select Old data from database

    IF it_zcstm[] is NOT INITIAL.

    REFRESH it_zcstm_old.

    select * from zcstmgt INTO CORRESPONDING FIELDS OF TABLE it_zcstm_old

    FOR ALL ENTRIES IN it_zcstm

    WHERE ZCUST = it_zcstm-zcust AND

    ZCUSTCON = it_zcstm-zcustcon AND

    ZYEAR = it_zcstm-zyear AND

    zdelind = it_zcstm-del.

    ENDIF.

    wa_docdata-obj_name = 'Change Log for Customer Master in Gift Allocation'.

    wa_docdata-obj_descr = 'Change Log for Customer Master in Gift Allocation'.

    wa_objtxt-line = '<html> <body>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<p> Customer Master Before Change </p>'.

    APPEND wa_objtxt TO it_objtxt.

    * table display

    wa_objtxt-line = '<table style="MARGIN: 10px" bordercolor="black" '.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = ' cellspacing="0" cellpadding="3" width="400"'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = ' border="1"><tbody><tr>'.

    APPEND wa_objtxt TO it_objtxt.

    * table header

    wa_objtxt-line = '<th bgcolor="DarkGray">Customer</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Customer Contact No</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Year</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">TLI Contact ID</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Customer Name</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Customer Contact Name</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Customer Contact Designation</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Office Address</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Home address</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Address Preference</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Office Phone</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Home phone</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Mobile Phone</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Fax No</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Email ID</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Comments</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Deletion Indicator</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Last Changed by</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Last changed on</th></tr>'.

    APPEND wa_objtxt TO it_objtxt.

    * wa_objtxt-line = '<th bgcolor="DarkGray"> </th>'.

    * APPEND wa_objtxt TO it_objtxt.

    * wa_objtxt-line = '<th bgcolor="DarkGray"> </th>'.

    * APPEND wa_objtxt TO it_objtxt.

    LOOP AT it_zcstm INTO wa.

    READ TABLE it_zcstm_old INTO wa_old WITH KEY ZCUST = wa-zcust

    ZCUSTCON = wa-zcustcon

    ZYEAR = wa-zyear

    del = wa-del.

    IF sy-subrc eq 0 AND wa ne wa_old.

    CONCATENATE '<tr style="background-color:#eeeeee;"><td>'

    wa_old-zcust

    '</td>'

    INTO wa_objtxt.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zcustcon '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zyear '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-ztlicon '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zcustname '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zconname '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zcondsg '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zoffaddr '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zhomaddr '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zaddrpref '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zoffphone '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zhomphone '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zmobile '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zfaxno '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zemail '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zcomment '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-del '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zlastchg '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa_old-zlastchgon '</td></tr>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    * CONCATENATE '<td>' wa_old- '</td>' INTO wa_objtxt-line.

    * APPEND wa_objtxt TO it_objtxt.

    ENDIF.

    ENDLOOP.

    wa_objtxt-line = '</tbody> </table>'.

    APPEND wa_objtxt TO it_objtxt.

    *Customer Master After Changes*

    wa_objtxt-line = '<p> Customer Master Changes </p>'.

    APPEND wa_objtxt TO it_objtxt.

    * table display

    wa_objtxt-line = '<table style="MARGIN: 10px" bordercolor="black" '.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = ' cellspacing="0" cellpadding="3" width="400"'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = ' border="1"><tbody><tr>'.

    APPEND wa_objtxt TO it_objtxt.

    * table header

    wa_objtxt-line = '<th bgcolor="DarkGray">Customer</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Customer Contact No</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Year</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">TLI Contact ID</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Customer Name</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Customer Contact Name</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Customer Contact Designation</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Office Address</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Home address</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Address Preference</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Office Phone</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Home phone</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Mobile Phone</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Fax No</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Email ID</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Comments</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Deletion Indicator</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Last Changed by</th>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<th bgcolor="DarkGray">Last changed on</th></tr>'.

    APPEND wa_objtxt TO it_objtxt.

    * wa_objtxt-line = '<th bgcolor="DarkGray"> </th>'.

    * APPEND wa_objtxt TO it_objtxt.

    * wa_objtxt-line = '<th bgcolor="DarkGray"> </th>'.

    * APPEND wa_objtxt TO it_objtxt.

    LOOP AT it_zcstm INTO wa.

    READ TABLE it_zcstm_old INTO wa_old WITH KEY ZCUST = wa-zcust

    ZCUSTCON = wa-zcustcon

    ZYEAR = wa-zyear

    del = wa-del.

    IF sy-subrc eq 0 AND wa ne wa_old.

    CONCATENATE '<tr style="background-color:#eeeeee;"><td>'

    wa-zcust

    '</td>'

    INTO wa_objtxt.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zcustcon '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zyear '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-ztlicon '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zcustname '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zconname '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zcondsg '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zoffaddr '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zhomaddr '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zaddrpref '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zoffphone '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zhomphone '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zmobile '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zfaxno '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zemail '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zcomment '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-del '</td> ' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zlastchg '</td>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    CONCATENATE '<td>' wa-zlastchgon '</td></tr>' INTO wa_objtxt-line.

    APPEND wa_objtxt TO it_objtxt.

    * CONCATENATE '<td>' wa_old- '</td>' INTO wa_objtxt-line.

    * APPEND wa_objtxt TO it_objtxt.

    ENDIF.

    ENDLOOP.

    wa_objtxt-line = '</tbody> </table>'.

    APPEND wa_objtxt TO it_objtxt.

    *Customer Master After Changes*

    wa_objtxt-line = '<br><br>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '<p> Regards.</p>'.

    APPEND wa_objtxt TO it_objtxt.

    wa_objtxt-line = '</body> </html> '.

    APPEND wa_objtxt TO it_objtxt.

    data: wa_lines TYPE i.

    DESCRIBE TABLE it_objtxt LINES wa_lines.

    READ TABLE it_objtxt INTO wa_objtxt INDEX wa_lines.

    wa_docdata-doc_size =

    ( wa_lines - 1 ) * 255 + STRLEN( wa_objtxt ).

    CLEAR wa_objpack-transf_bin.

    wa_objpack-head_start = 1.

    wa_objpack-head_num = 0.

    wa_objpack-body_start = 1.

    wa_objpack-body_num = wa_lines.

    wa_objpack-doc_type = 'HTML'.

    APPEND wa_objpack TO it_objpack.

    wa_reclist-receiver = 'xyz@gmail.com'.

    wa_reclist-rec_type = 'U'.

    APPEND wa_reclist TO it_reclist.

    CLEAR wa_reclist.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = wa_docdata

    PUT_IN_OUTBOX = 'X'

    COMMIT_WORK = 'X'

    * IMPORTING

    * SENT_TO_ALL =

    * NEW_OBJECT_ID =

    TABLES

    PACKING_LIST = it_objpack

    OBJECT_HEADER = it_objhead

    * CONTENTS_BIN =

    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.

    else.

    REFRESH: it_reclist,it_objtxt,it_objpack,it_objhead.

    clear: wa_docdata.

    ENDIF.

    ENDFORM. " SEND_MAIL

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.