Application Development 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: 

Send tabular output in email using oops

arpita_churi3
Active Participant
0 Kudos

Hi All,

  

  I am sending email notificatios to users using following methdos of class:

CL_DOCUMENT_BCS->CREATE-DOCUMENT

CL_BCS->ADD_RECIPIENT

CL_BCS->SEND

I am able to send email but now requirement is to send output internal table of 3 columns and upto 5 rows in tabular format.

Please help.

Thanks,

Arpita

1 ACCEPTED SOLUTION

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

You can create html table .

See sample program Y_R_EITAN_TEST_10_09 attached .

Regards.

I change the program so the same table is sent in the body of the message AND as attachment. See FORM get_html_table

9 REPLIES 9

Former Member
0 Kudos

Hi Arpita,

You can create your document of type HTML using html tags you can achieve the tabular format in email.

Regards,

Shashikanth

0 Kudos

Hi Arpita,

You can send email in tabular format.

that can be acheived through HTML tags.

let us see how to fill the HTML tables t_html and t_html1 with a simple HTML code. Let us consider the scenario for displaying the payroll details of an employee.

 

APPEND text-000 TO t_html."<head>

APPEND text-001 TO t_html."<style type="text/css">

APPEND text-002 TO t_html."<!--

APPEND text-003 TO t_html."table{background-color:#FFF;border-collapse:collapse;}

APPEND text-004 TO t_html. "td.Data{background- color:#FFF;border:1px solid black;padding:3px;}

APPEND text-005 TO t_html."td.Heading{background-color:Blue;text- align:center;border:1px solidblack;padding:3px;}

APPEND text-006 TO t_html. "--> APPEND text-007 TO t_html. "</style> APPEND text-000 TO t_html. "<head>

 

Note: The statements like "<head> etc... are the text which is written with in text elements.

 

Here we are making a tabular form of display. So we need to create a table also with different heading colors. Here we can use text-elements to update into the internal table because HTML coding starting with

" will be treated as comment in SAP so we can use text elements for such type of statements.

 

APPEND text-008 TO t_html. " <h2>

APPEND text-009 TO t_html. " heading

APPEND text-008 TO t_html. " <h2>

Now the table heading and the table body will be populated as shown below.

APPEND text-011 TO t_html. " <TABLE class="Data">

APPEND text-012 TO t_html. " <tr>

 

This is to mention the start of the table row. I.e. <tr> and <td> for the data in that row.

 

APPEND text-013 TO t_html. "<td class="Heading">

APPEND text-014 TO t_html. "<font color="White" size="2">

APPEND text-020 TO t_html. "Date

 

APPEND text-015 TO t_html. "</font>

APPEND text-016 TO t_html. "</td>

APPEND text-013 TO t_html. "<td class="Heading">

APPEND text-014 TO t_html. "<font color="White" size="2">

APPEND text-021 TO t_html. "Action APPEND text-015 TO t_html. "</font>

APPEND text-016 TO t_html. "</td>

APPEND text-029 TO t_html. "</tr>

 

In the similar fashion you can add the field headings which you need to display in the table by changing the text-011 (in this case) with the heading fields. In this case you can also use loop the fieldcatlog table and assign the headings to it.

Now we can add the contents of the table ie the value for the field’s headings.

 

APPEND text-012 TO t_html. "<tr>

APPEND text-017 TO t_html. "<td class="Data">

APPEND text-018 TO t_html. "<font color="Black" size="1">

APPEND lv_char TO t_html. "Loop the contents from final fieldcatlog

table and assign the value to this variable. See

Note for brief explanation.

APPEND text-015 TO t_html. "</font>

APPEND text-016 TO t_html. "</td>

APPEND text-029 TO t_html. "</tr>

APPEND text-019 TO t_html. "</TABLE>

 

So now the table is ready for display with the HTML code. When the HTML table is processed the statements within the table is consider as the HTML coding statements and it is processed. So it will have the effect of HTML format.

Now the internal tables which are required for the display are filled. Now let us see the entire code of the mailing part.

 

WRITE sy-datum TO lv_date MM/DD/YYYY. "To get date displayed in that format

WRITE sy-uzeit TO lv_time USING EDIT MASK '__:__:__'."To get time in correct

Format.

CONCATENATE text-009 lv_date lv_time INTO lv_sub SEPARATED BY space. "Subject

 

* Creates persistent send request

TRY. v_send_request = cl_bcs=>create_persistent( ).

 

* Creating Document

IF t_html IS NOT INITIAL. v_document = cl_document_bcs=>create_document( i_type = „HTM‟ i_importance = „5‟ i_text = t_html i_subject = lv_sub ).

 

CALL METHOD v_document->add_attachment EXPORTING i_attachment_type = „HTM‟ i_attachment_subject = lv_sub i_att_content_text = t_html.

Thanks,

Marimuthu.K

0 Kudos

Hi marimuthu,

Thanks a lot..

I tried the same.as follows:

  lo_send_request = cl_bcs=>create_persistent( ).

   ****HTML***********
    DATA:lt_text TYPE soli_tab.
    APPEND text-001 TO lt_text. "<HTML>
    APPEND text-002 TO lt_text. "<BODY>
    APPEND text-005 TO lt_text. "<TABLE WIDTH="40" BORDER="1">
    APPEND text-007 to lt_text. "<TR>
    APPEND text-007 to lt_text. "<TD>Plant</TD><TD>UOM</TD>
    APPEND text-008 to lt_text. "</TR>
    APPEND text-006 TO lt_text. "</TABLE>
    APPEND text-004 TO lt_text. "</BODY>
    APPEND text-003 TO lt_text. "</HTML>

******************************
    lo_document = cl_document_bcs=>create_document(
    i_type      = 'HTM'
    i_importance = '5'
    i_text      = lt_text
    i_subject   = 'Inspection Plan' ).

    lo_document->add_attachment(
      EXPORTING
      i_attachment_type    = 'HTM'
      i_attachment_subject = 'Inspection Plan Head'
      i_att_content_text    = lt_text ).

    lo_send_request->set_document( lo_document ).
    lo_sender = cl_sapuser_bcs=>create( sy-uname ).

*     Set sender
    lo_send_request->set_sender(
    EXPORTING
    i_sender = lo_sender ).

    LOOP AT i_email INTO w_email.
      lo_recipient = cl_cam_address_bcs=>create_internet_address( w_email-email ).
*    *     Set recipient
      lo_send_request->add_recipient(
      EXPORTING
      i_recipient = lo_recipient
      i_express = 'X' ).
    ENDLOOP.



*     Send email
    lo_send_request->send(
    EXPORTING
    i_with_error_screen = 'X'
    RECEIVING
    result = lv_sent_to_all ).
    COMMIT WORK.

I am able to see output in email bost in table format.but at the same time it is going as attachment in email as .HTMl file.

But i dont want attachment.

Pls help.

Thanks,

Arpita

0 Kudos

Hi Arpita,

please comment below code and try.

    lo_document->add_attachment(

      EXPORTING

      i_attachment_type    = 'HTM'

      i_attachment_subject = 'Inspection Plan Head'

      i_att_content_text    = lt_text ).

Thanks,

Marimuthu.K

0 Kudos

Hi Arpita,

Is your issue solved or still exist??

Thanks,

Marimuthu.K

0 Kudos

Thnks,

issue still exists..

I want table output in email body...this is correct but along with it is going as attachment as .HTML file.

and one more thing I want to add some text in email body as well .

For that I am using CREATE_DOCUMENT method

twice with I_type RAW and HTMbut whichever is last is coming in email.

Please help on this.

Thanks.

Arpita


0 Kudos

If I comment this code then output table is not coming .

I want both RAW and HTM  type.

and work area values are populated as w_final-werks instead of 1001

I have used as <TD>w_final-werks</TD>

Kindly help.

ipravir
Active Contributor
0 Kudos

Hi Arpita,

You an send the information in HTML format as mail body.

Try below link to create a format in HTML first and use the html code to create Header, table and Footer information.

And send those all information a HTM type of document.

http://online-html-editor.org

Use CL_DOCUMENT_BCS=>CREATE_DOCUMENT and pass the 'HTM" document type with Internal table, which will contains the HTML coding.

Regards.

Praveer.

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

You can create html table .

See sample program Y_R_EITAN_TEST_10_09 attached .

Regards.

I change the program so the same table is sent in the body of the message AND as attachment. See FORM get_html_table