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

Table in an e-mail


I need to send a mail through ABAP which contains a table . And no. of columns in the table will change dynamically. How can i insert such table in an e-mail.

Please suggest

Thanks & Regards

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Feb 26, 2007 at 05:22 AM

    Hi Puneet,

    You can do it two ways, Either you send the Table in the body of the mail or You download the table into an Excel File and attach it to mail. You can do it programatically using:-




    • Description : Subroutine to send the composed EMAIL to assigned *

    • Processors *


    • Interface : *

    • -->IT_MESSAGE - Internal table to hold the body of EMAIL *

    • -->IV_PROCESSOR- Import parameter containing the Recepient's Mail Id*


    FORM send_email_message USING it_message LIKE gt_message


    CONSTANTS: lc_subject(40) TYPE c

    VALUE 'CDOP Object List for you'."#EC NOTEXT

    DATA: lt_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

    lt_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE.

    DATA: lv_doc_data LIKE sodocchgi1.

    • Fill the document data.

    lv_doc_data-doc_size = 1.

    • Populate the subject/generic message attributes

    lv_doc_data-obj_langu = sy-langu.

    lv_doc_data-obj_name = 'SAPRPT'.

    lv_doc_data-obj_descr = lc_subject.

    lv_doc_data-sensitivty = 'F'.

    • Describe the body of the message

    CLEAR lt_packing_list.

    REFRESH lt_packing_list.

    lt_packing_list-transf_bin = space.

    lt_packing_list-head_start = 1.

    lt_packing_list-head_num = 0.

    lt_packing_list-body_start = 1.

    DESCRIBE TABLE it_message LINES lt_packing_list-body_num.

    lt_packing_list-doc_type = 'RAW'.

    APPEND lt_packing_list.

    • Add the recipients email address

    CLEAR lt_receivers.

    REFRESH lt_receivers.

    lt_receivers-receiver = iv_processor.

    lt_receivers-rec_type = 'B'.

    APPEND lt_receivers.

    • Send Mail



    document_data = lv_doc_data


    packing_list = lt_packing_list

    contents_txt = it_message

    receivers = lt_receivers


    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.


    ENDFORM. "send_email_message

    • The above is sample code. You can use the function *module 'SO_NEW_DOCUMENT_ATT_SEND_API1' to send mails. Also the *attahments.

    Thanks and regards,


    Note: Points keep me alive on SDN 😊.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 26, 2007 at 05:38 AM

    I use HTML formatting to accomplish this - you can then also have headings, colours etc. Search the forum for examples of sending HTML in email.



    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 26, 2007 at 11:52 AM

    Hi Puneet,

    Find below the report by which you can fetch the values from a DB table say MARA and append them into the body of an email and send it across the desired users.


    REPORT zsapmailtest .

    *Data declaration part

    DATA: lv_object_type LIKE sood-objtp.

    DATA: BEGIN OF gt_object_hd_change.


    DATA: END OF gt_object_hd_change.

    DATA: BEGIN OF gt_objcont OCCURS 10.


    DATA: END OF gt_objcont.

    DATA: BEGIN OF gt_objhead OCCURS 0.


    DATA: END OF gt_objhead.

    DATA: BEGIN OF raw_head.


    DATA: END OF raw_head.

    DATA: BEGIN OF gt_receivers OCCURS 0.


    DATA: END OF gt_receivers.

    DATA : BEGIN OF gt_mara OCCURS 0,

    matnr LIKE mara-matnr,

    ernam LIKE mara-ernam,

    END OF gt_mara.

    PARAMETERS: receiver LIKE gt_receivers-recnam. " Name


    MOVE 'Sort field goes here' TO gt_object_hd_change-objsrt. " Sort field

    MOVE 'Name of the object goes here' TO gt_object_hd_change-objnam. " Name

    MOVE 'Document title goes here' TO gt_object_hd_change-objdes. " Title

    MOVE 'F' TO gt_object_hd_change-objsns. " Functional OBJECT

    MOVE 'E' TO gt_object_hd_change-objla. " Language

    • Object type of the new document

    MOVE 'RAW' TO lv_object_type.

    CLEAR gt_objcont.

    *Body of the mail . Where you can Loop the table and sent it across

    <b>SELECT matnr ernam FROM mara

    INTO TABLE gt_mara.

    gt_objcont-line+0(18) = 'Material Name'.

    gt_objcont-line+28(38) = 'Created by'.

    APPEND gt_objcont.

    gt_objcont-line = '----


    APPEND gt_objcont.

    *Writing the contents of the internal table to the body of the mail

    LOOP AT gt_mara.

    CLEAR gt_objcont.

    gt_objcont-line+0(18) = gt_mara-matnr.

    gt_objcont-line+19(38) = gt_mara-ernam.

    APPEND gt_objcont.


    • Specific header (Dependent on the object type, here RAW)

    REFRESH gt_objhead.

    DESCRIBE TABLE gt_objcont LINES raw_head-rawsiz.

    MOVE raw_head TO gt_objhead.

    APPEND gt_objhead.

    *RECEIVERS table

    CLEAR gt_receivers.

    REFRESH gt_receivers.

    MOVE receiver TO gt_receivers-recnam. " Name

    MOVE 'B' TO gt_receivers-recesc. " Receiver type

    MOVE 'X' TO gt_receivers-sndcp. " Send as a copy

    MOVE 'X' TO gt_receivers-sndex. " EXPRESS DOCUMENT

    APPEND gt_receivers.

    *Function module to send mail



    object_hd_change = gt_object_hd_change

    object_type = lv_object_type

    outbox_flag = 'X'

    owner = sy-uname


    objcont = gt_objcont

    objhead = gt_objhead

    receivers = gt_receivers.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.



    Hope the above code is simple and fulfills your requirement.

    Thanks and regards,


    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Siva,

      The code that you gave is somewhat helpful but it didn't solve my problem.

      First of all its giving Run time error and that error is in module SO_OBJECT_SEND

      And 2nd thing is that i have to send e-mail automatically......means i have to fetch e-mail id of recipient in program itself and then have to send mail automatically.

      Please suggest as soon as you can

      Thanks and Regards


  • author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2007 at 08:56 AM

    Hi Puneet,

    You can fetch e-mail id of recipient in program and pass the values directly to this field(gt_receivers-recnam) in the above code and append them instead of supplying the values to this field from the input parameter of the selection screen

    <b>MOVE receiver TO gt_receivers-recnam. </b>

    The above code runs in my system without any Runtime error.I have checked in SAP ENT system.

    Thanks and Regards,


    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 27, 2007 at 08:59 AM

    Hi Puneet,

    See Rich's post in this thread:


    Explore a bit of HTML for including tables in the body of the 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.