Skip to Content

Email with table as email body

Hi All,

I have a requirement to send table with 15 fields in email body.

I need the step by step details to send table in email body.

Also is there any limitation on length or no. of fields which can be sent in email body?

Thanks.

Regards,

Sanjana

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    Posted on Dec 08, 2014 at 06:58 AM

    Hi,

    find below code

    MOVE '<body style="background-color: #D7ECF3;">' TO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    MOVE '<BR>' TO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    CLEAR GS_OBJTXT.

    CONCATENATE text-011 '<BR><BR>'
    text-012 '.<BR><BR>' INTO GS_OBJTXT-LINE SEPARATED BY space.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    MOVE gv_tot_cnt to gv_rec_cnt.

    CONCATENATE Text-001 gs_files-fname '<BR><BR>Total Record(s):' gv_rec_cnt '<BR><BR>'"'<BR><BR>Data Error Record(s):' gv_err_rec_cnt
    INTO GS_OBJTXT-LINE SEPARATED BY space.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    MOVE '<TABLE BORDER=2>' TO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    MOVE '<TR style="background-color: #96A5AA;"> <TH> Pernr </TH> ' TO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    MOVE '<TH> Employee ID </TH> ' TO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    MOVE '<TH> First Name</TH> ' TO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    MOVE '<TH> Last Name </TH>' TO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    MOVE '<TH> Status Message </TH>' TO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.


    LOOP AT GT_ERR_LOG INTO GS_ERR_LOG.

    if GS_ERR_LOG-ERR_PERNR is NOT INITIAL.
    CONCATENATE '<TR> <TD>' GS_ERR_LOG-ERR_PERNR '</TD>' INTO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.
    ELSE.
    MOVE '<TR> <TD></TD>' TO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.
    ENDIF.

    CONCATENATE '<TD>' GS_ERR_LOG-EMPNO '</TD>' INTO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    CONCATENATE '<TD>' GS_ERR_LOG-FIRST_NAME '</TD>' INTO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    CONCATENATE '<TD>' GS_ERR_LOG-LAST_NAME '</TD>' INTO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    CONCATENATE '<TD>' GS_ERR_LOG-ERR_MSG '</TD></TR>' INTO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    ENDLOOP.

    MOVE '</TABLE>' TO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    CLEAR GS_OBJTXT.

    CONCATENATE '<BR>' text-013 '<BR>'
    text-018 INTO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    MOVE '<BR><BR>' TO GS_OBJTXT-LINE.
    APPEND GS_OBJTXT TO GT_OBJTXT.

    * MOVE ' <TABLE><TH>*** This is an auto generated mail from SAP-HCM, Do not reply ***</TH><TH></TH><TH></TH><TH></TH><TH></TH></TABLE>' TO GS_OBJTXT-LINE.
    CONCATENATE '<TABLE><TH>*** This is an auto generated mail from ' sy-sysid sy-mandt 'system, Do not reply ***</TH><TH></TH><TH></TH><TH></TH><TH></TH></TABLE>' INTO GS_OBJTXT-LINE SEPARATED BY space..
    APPEND GS_OBJTXT TO GT_OBJTXT.

    MOVE TEXT-015 TO GS_DOCDATA-OBJ_DESCR.
    GS_DOCDATA-SENSITIVTY = 'F'.

    DESCRIBE TABLE GT_OBJTXT LINES GV_LINES.
    IF NOT GV_LINES IS INITIAL.
    GS_DOCDATA-DOC_SIZE = GV_LINES * 255.
    ENDIF.

    CLEAR GS_OBJPACK.
    GS_OBJPACK-TRANSF_BIN = ''.
    GS_OBJPACK-HEAD_START = 1.
    GS_OBJPACK-HEAD_NUM = 0.
    GS_OBJPACK-BODY_START = 1.
    GS_OBJPACK-BODY_NUM = GV_LINES.
    GS_OBJPACK-DOC_TYPE = 'HTM'.
    GS_OBJPACK-DOC_SIZE = ( GV_LINES - 1 ) * 255 + STRLEN( GS_OBJTXT ).
    APPEND GS_OBJPACK TO GT_OBJPACK.

    if MAIL_REC is NOT INITIAL.
    * GS_RECEIVER-RECEIVER = p_mail1.
    * GS_RECEIVER-REC_TYPE = 'U'.
    * APPEND GS_RECEIVER TO GT_RECEIVER.
    * ENDIF.

    Loop at MAIL_REC.
    gs_receiver-receiver = mail_rec-low.
    gs_receiver-rec_type = 'U'.
    gs_receiver-com_type = c_comtyp_int.
    APPEND gs_receiver TO gt_receiver.
    CLEAR gs_receiver.
    Endloop.
    ENDIF.

    * if p_mail2 is NOT INITIAL.
    * GS_RECEIVER-RECEIVER = p_mail2.
    * GS_RECEIVER-REC_TYPE = 'U'.
    * APPEND GS_RECEIVER TO GT_RECEIVER.
    * ENDIF.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    DOCUMENT_DATA = GS_DOCDATA
    * put_in_outbox = c_x
    COMMIT_WORK = C_X
    IMPORTING
    SENT_TO_ALL = GV_SENTALL
    NEW_OBJECT_ID = GV_NOBJID
    TABLES
    PACKING_LIST = GT_OBJPACK[]
    * OBJECT_HEADER =
    * CONTENTS_BIN = gt_contents
    CONTENTS_TXT = GT_OBJTXT[]
    * CONTENTS_HEX = gt_contents_hex

    RECEIVERS = GT_RECEIVER[]
    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
    .
    Regards,

    Rajesh K

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 08, 2014 at 05:58 AM

    Hello Sanjana,

    You can check the program BCS_EXAMPLE_6.

    In this example internal table data is get converted to pdf attachment and sending the email to the concern person.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 08, 2014 at 04:53 AM

    Sanjana,

    May be you can explore on sending the table data with all the required fields as attachment instead of putting the data as body of the email.

    K.Kiran.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 08, 2014 at 05:05 AM

    Hi Sanjana,

    We wont be able to Create a table in E-mail body as we create in our report programs. You have to manually create the table concatenating "_" and '|" . i think we have display length restriction of 255 Char. So it is better to go with an attachment rather than having it in mail body.

    Thanks!!

    Suvarnamathy R

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 08, 2014 at 05:16 AM

    Hi Sanjana,

    Maybe below link will be helpful for you.

    Mails from SAP to external mail id with HTML formatting - Code Gallery - SCN Wiki

    There are many other discussions done on the same topic in the forum.

    Regards,

    ~Athreya

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 08, 2014 at 05:28 AM
    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.