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: 

HTML Table does not display when sending the email from report

Former Member
0 Kudos

Hi Experts,

I have created an automatic email generation program and scheduled a back ground job for it to run every week. I used SO_NEW_DOCUMENT_ATT_SEND_API1 function and the email body is in HTML and I have to display some data in tabular form. I am able to get the expected output on my computer only on Internet explorer. In Firefox the table borders and colors are not showing up. When I opened the same email on another computer's Internet explorer, it is not showing the borders there too. Are there any settings I need to configure? I have spent lot of time in designing the table and I am frustrated that it is not showing properly. Any help would be great if you can,

Thanks

Ajith C

7 REPLIES 7

former_member1052991
Active Participant
0 Kudos

Hi Ajith,

Can you try with the following code:

DATA:LTAB_HTMLTABLE TYPE STANDARD TABLE OF W3HTML,
       LTAB_COLHEAD   TYPE STANDARD TABLE OF W3HEAD,
       ITAB_FIELDS    TYPE STANDARD TABLE OF W3FIELDS.
  DATA:LCL_RECIPIENT  TYPE REF TO IF_RECIPIENT_BCS,
       LCL_BCS        TYPE REF TO CL_BCS,
       LCL_DOCUMENT   TYPE REF TO CL_DOCUMENT_BCS,
       LFLAG_SENT_TO_ALL
                      TYPE OS_BOOLEAN,
       LCX_BCS        TYPE REF TO CX_BCS,
       LTAB_TEXTMAIL  TYPE SOLI_TAB,
       LWA_TEXT       TYPE SOLI,
       L_EMAIL        TYPE ADR6-SMTP_ADDR.
  DATA:LTAB_TEXTLINES TYPE STANDARD TABLE OF TLINE,
       LWA_LINE       TYPE TLINE,
       LWA_TVARVC     TYPE TVARVC.
  DATA:L_LANGU        TYPE SY-LANGU,
       LFLAG_ADRSFOUND TYPE CHAR01,
       LTEXT_HEADER   TYPE THEAD-TDNAME,
       LTEXT_FOOTER   TYPE THEAD-TDNAME VALUE 'ZMAIL_FOOTER'.
  DATA: L_FIELDPOS    TYPE W3HEAD-NR.
  DATA: L_VAR         TYPE STRING.
  DATA: L_IDX         TYPE N LENGTH 2 VALUE 1.
  DATA: L_COLHEADER   TYPE W3HEAD-TEXT.
  DATA: L_SUBJECT     TYPE CHAR50.
  FIELD-SYMBOLS: <FS_COLHEADER> TYPE ANY.
  CONSTANTS:
      LC_COLHEADERS   TYPE I VALUE 10,
      LC_HEADER(11)   TYPE C VALUE 'Deal export',
      LC_HEADER01(08) TYPE C VALUE 'Log date',
      LC_HEADER02(10) TYPE C VALUE 'Time stamp',
      LC_HEADER03(12) TYPE C VALUE 'Deal Item ID',
      LC_HEADER04(09) TYPE C VALUE 'Deal Code',
      LC_HEADER05(13) TYPE C VALUE 'Customer Code',
      LC_HEADER06(12) TYPE C VALUE 'Product Code',
      LC_HEADER07(19) TYPE C VALUE 'Dict Deal Item Code',
      LC_HEADER08(06) TYPE C VALUE 'Status',
      LC_HEADER09(15) TYPE C VALUE 'Document Number',
      LC_HEADER10(13) TYPE C VALUE 'Error Message'.
  L_LANGU = SY-LANGU.
  CLEAR L_SUBJECT.
* Subject
  CONCATENATE LC_HEADER     C_OPEN  SY-DATUM+0(4) C_SLASH
              SY-DATUM+4(2) C_SLASH SY-DATUM+6(2) C_CLOSE
              INTO L_SUBJECT.
  IF NOT IT_ERRTEXT IS INITIAL.
    DO LC_COLHEADERS TIMES.
      IF L_IDX = 1.
        L_COLHEADER = LC_HEADER01.
      ELSEIF L_IDX = 2.
        L_COLHEADER = LC_HEADER02.
      ELSEIF L_IDX = 3.
        L_COLHEADER = LC_HEADER03.
      ELSEIF L_IDX = 4.
        L_COLHEADER = LC_HEADER04.
      ELSEIF L_IDX = 5.
        L_COLHEADER = LC_HEADER05.
      ELSEIF L_IDX = 6.
        L_COLHEADER = LC_HEADER06.
      ELSEIF L_IDX = 7.
        L_COLHEADER = LC_HEADER07.
      ELSEIF L_IDX = 8.
        L_COLHEADER = LC_HEADER08.
      ELSEIF L_IDX = 9.
        L_COLHEADER = LC_HEADER09.
      ELSEIF L_IDX = 10.
        L_COLHEADER = LC_HEADER10.
      ENDIF.
      L_FIELDPOS = L_IDX.
      CALL FUNCTION 'WWW_ITAB_TO_HTML_HEADERS'
        EXPORTING
          FIELD_NR = L_FIELDPOS
          TEXT     = L_COLHEADER
        TABLES
          HEADER   = LTAB_COLHEAD.

      ADD 1 TO L_IDX.
    ENDDO.
* Creation of html table for content
    CALL FUNCTION 'WWW_ITAB_TO_HTML'
*      EXPORTING
*        all_fields             = 'X'
      TABLES
        HTML                   = LTAB_HTMLTABLE
        ROW_HEADER             = LTAB_COLHEAD
        FIELDS                 = ITAB_FIELDS
        ITABLE                 = IT_ERRTEXT.

    REFRESH:
      LTAB_TEXTMAIL.

    CLEAR:LWA_TEXT.
    INSERT LWA_TEXT INTO TABLE LTAB_TEXTMAIL.

    CLEAR:LWA_TEXT.
    INSERT LWA_TEXT INTO TABLE LTAB_TEXTMAIL.

    APPEND LINES OF LTAB_HTMLTABLE TO LTAB_TEXTMAIL.

    CLEAR:LWA_TEXT.
    INSERT LWA_TEXT INTO TABLE LTAB_TEXTMAIL.
    INSERT LWA_TEXT INTO TABLE LTAB_TEXTMAIL.
    INSERT LWA_TEXT INTO TABLE LTAB_TEXTMAIL.

* Creation of document
    TRY.
        LCL_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
          I_TYPE = 'HTM'
          I_TEXT = LTAB_TEXTMAIL
          I_SUBJECT = L_SUBJECT
          ).
      CATCH CX_BCS INTO LCX_BCS.
    ENDTRY.

    TRY.
        LCL_BCS = CL_BCS=>CREATE_PERSISTENT( ).
      CATCH CX_BCS INTO LCX_BCS.
    ENDTRY.

    CLEAR:
      LFLAG_ADRSFOUND.

* Getting Mail ID from variant table
    SELECT *
      INTO LWA_TVARVC
      FROM TVARVC
      WHERE NAME EQ 'ZADS_DEAL_MAIL_TO'.

      LFLAG_ADRSFOUND = 'X'.
      L_EMAIL = LWA_TVARVC-LOW.

      TRY.
          LCL_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS(
            L_EMAIL
            ).
        CATCH CX_BCS INTO LCX_BCS.
      ENDTRY.

      TRY.
          CALL METHOD LCL_BCS->ADD_RECIPIENT
            EXPORTING
              I_RECIPIENT = LCL_RECIPIENT
              I_EXPRESS   = 'X'.
        CATCH CX_BCS INTO LCX_BCS.
      ENDTRY.
      CLEAR:LWA_TVARVC.
    ENDSELECT.

* If mail id not found in variant table set default mail id
    IF LFLAG_ADRSFOUND IS INITIAL.
      L_EMAIL = 'testmail at gmail dotcom'.
      TRY.
          LCL_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS(
            L_EMAIL
            ).
        CATCH CX_BCS INTO LCX_BCS.
      ENDTRY.

      TRY.
          CALL METHOD LCL_BCS->ADD_RECIPIENT
            EXPORTING
              I_RECIPIENT = LCL_RECIPIENT
              I_EXPRESS   = 'X'.
        CATCH CX_BCS INTO LCX_BCS.
      ENDTRY.
    ENDIF.

    TRY.
        CALL METHOD LCL_BCS->SET_DOCUMENT( LCL_DOCUMENT ).
      CATCH CX_BCS INTO LCX_BCS.
    ENDTRY.

    TRY.
* Method for sending mail immediately
        CALL METHOD LCL_BCS->SET_SEND_IMMEDIATELY( 'X' ).

* Sending Mail
        CALL METHOD LCL_BCS->SEND(
          EXPORTING
            I_WITH_ERROR_SCREEN = 'X'
          RECEIVING
            RESULT = LFLAG_SENT_TO_ALL
            ).
      CATCH CX_BCS INTO LCX_BCS.
    ENDTRY.

    COMMIT WORK.

  ENDIF.

Edited by: MKM on Jan 19, 2012 11:13 AM

0 Kudos

Hi MKM,

Thanks for the quick reply. It looks to me like there are many things in your code which are new to me. Because I am not familiar with oops concept. However I am going to try this, thanks. As I mentioned earlier, I was successful in creating the email body which contains a table, send it automatically using SO_NEW_DOCUMENT_ATT_SEND_API. In R/3 system inbox and on some system's Internet Explorer , it is appearing good with all the table borders and color. However in Firefox and some system's Internet Explorer it is not showing the table borders and cells. This email is expected to be viewed in devices like a Blackberry also. That is where I am finding it difficult. I am going to try your code.

Thanks again

Ajith C

0 Kudos

If you want to try out the BCS Method, i have sample code here, just try with HTML table here also..

DATA lt_message TYPE bcsy_text.
DATA lv_mail_title TYPE so_obj_des.
DATA document TYPE REF TO cl_document_bcs.
DATA recipient TYPE REF TO if_recipient_bcs.
DATA send_request TYPE REF TO cl_bcs.
DATA sent_to_all TYPE os_boolean.
DATA bcs_execption TYPE REF TO cx_bcs.
DATA email_id TYPE ADR6-SMTP_ADDR

send_request = cl_bcs=>create_persistent( ).
*Create Title
CONCATENATE 'Mail Subject' '-' 'xxx'
INTO lv_mail_title RESPECTING BLANKS.
*Create Message(EMAIL Body)
APPEND '<p>The Message body.......</p>' TO lt_message.
*.....Here You append your HTML Code for table....*
...
*Create Document
document = cl_document_bcs=>create_document(
     i_type = 'HTM'
     i_text =  message_body
     i_subject = subject ).

*Add document to email
send_request->set_document( document ).
 
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = email_id ).
*add recipients to send request
send_request->add_recipient( i_recipient = recipient ).
sent_to_all = send_request->send(
i_with_error_screen = 'X' ).
COMMIT WORK.
IF sent_to_all = 'X'.
MESSAGE s398(00) WITH 'Message Sent Succesfully'.
RETURN.
ENDIF.

After that also, if aligning is not correct then add that table as attachment file.

Former Member
0 Kudos

0 Kudos

Hi All,

I have tried both the codes and the issue is same. I guess the issue is that I am using css stylesheet. If it is a normal html coding without using any css attributes, it is displaying in all the browsers. Now I need to learn how to overcome this. Thank you so much for all the help provided.

Ajith C

Former Member
0 Kudos

The issue was that I was viewing the emails in Outlook Web Access. It is designed to be used with Internet Explorer. In the broswers like Firefox, Chrome, it will not show the html content in the body of the email. However you will see one link called 'View as Webpage' just right to the subject of the email on clicking which, the email will open as a webpage. In internet explorer, this is not required. Thanks everyone for helping me on this.

Ajith

Former Member
0 Kudos

The issue was that I was viewing the emails in Outlook Web Access. It is designed to be used with Internet Explorer. In the broswers like Firefox, Chrome, it will not show the html content in the body of the email. However you will see one link called 'View as Webpage' just right to the subject of the email on clicking which, the email will open as a webpage. In internet explorer, this is not required. Thanks everyone for helping me on this.

Ajith