Application Development and Automation 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: 
Read only

Table in an e-mail

Former Member
0 Likes
549

And one more thing, i have to send that table in an e-mail body itself, not as an attachment.

Please suggest as soon as possible

4 REPLIES 4
Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
507

Use SO_NEW_DOCUMENT_SEND_API1 and put the internal table name into object_content:

  DATA: i_email_body LIKE solisti1 OCCURS 0 WITH HEADER LINE,
        i_reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
        doc_data LIKE sodocchgi1.

<fill in tables i_reclist, i_email_body>

  CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
    EXPORTING
      document_data              = doc_data
      commit_work                = 'X'
    TABLES
      object_content             = i_email_body
      receivers                  = i_reclist

Read only

0 Likes
507

Follow the link and you can send the table as an excel sheet attachment.

https://wiki.sdn.sap.com/wiki/display/Snippets/EmailfromSAP

Read only

0 Likes
507

The easiest solution is to write the table to a list display, save the list, convert to HTML and then pass this to the SEND function module. There are others ways, including embeding your own HTML, so that you can format it the way you want.



report zrich_0003 .

data: imara type table of mara with header line.
data: list type table of  abaplist with header line.
data: htmllines type table of w3html with header line.

data: maildata   like sodocchgi1.
data: mailtxt    like solisti1 occurs 10 with header line.
data: mailrec    like somlrec90 occurs 0  with header line.

start-of-selection.

* Get the data and write the list.
  select * into table imara from mara
             up to 100 rows.
  loop at imara.
    write:/ imara-matnr, imara-ersda, imara-mtart,
            imara-matkl, imara-groes.
  endloop.

* Save the list
  call function 'SAVE_LIST'
       tables
            listobject         = list
       exceptions
            list_index_invalid = 1
            others             = 2.

* Convert it to HTML
  call function 'WWW_LIST_TO_HTML'
       tables
            html = htmllines.

* Send the mail
  perform send_mail_nodialog..

* Forget about the list output.
  leave list-processing.

************************************************************************
*      Form  SEND_MAIL_NODIALOG
************************************************************************
form send_mail_nodialog.

  maildata-obj_name = 'TEST'.
  maildata-obj_descr = 'Test Subject'.

  loop at htmllines.
    mailtxt = htmllines.
    append mailtxt.
  endloop.

  mailrec-receiver = 'you@yourcompany.com'.
  mailrec-rec_type  = 'U'.
  append mailrec.

  call function 'SO_NEW_DOCUMENT_SEND_API1'
       exporting
            document_data              = maildata
            document_type              = 'HTM'
            put_in_outbox              = 'X'
       tables
            object_header              = mailtxt
            object_content             = mailtxt
            receivers                  = mailrec
       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.

endform.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
507

Hi,

Check this example..

  • Declarations.

PARAMETERS: p_email(50) LOWER CASE.

DATA: document_data LIKE sodocchgi1.

DATA: t_content LIKE STANDARD TABLE OF solisti1.

DATA: s_content LIKE solisti1.

DATA: t_receivers LIKE STANDARD TABLE OF somlreci1.

DATA: s_receivers LIKE somlreci1.

START-OF-SELECTION.

  • Receivers.

s_receivers-receiver = p_email.

s_receivers-rec_type = 'U'.

s_receivers-express = 'X'.

APPEND s_receivers TO t_receivers.

  • Subject

document_data-obj_descr = 'New mail from Sap'.

  • Body

s_content = 'Hi,'.

APPEND s_content TO t_content.

CLEAR: s_content.

APPEND s_content TO t_content.

s_content = 'Test email from sap, please don''t reply to this email'.

APPEND s_content TO t_content.

CLEAR: s_content.

APPEND s_content TO t_content.

s_content = 'Thanks,'.

APPEND s_content TO t_content.

s_content = 'Naren.'.

APPEND s_content TO t_content.

  • Send the email.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = document_data

TABLES

object_content = t_content

receivers = t_receivers

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 e208(00) WITH 'Error in sending email :-(('.

ELSE.

MESSAGE s208(00) WITH 'Email sent )'.

ENDIF.

SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.

Thanks,

Naren