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

Issue with cl_bcs

shweta_m2
Explorer
0 Likes
4,158

Hi,

I need to send details of employees having 9 columns and few rows in the mail body as tabular format. I am using cl_bcs to send mail and have concatenated required data into ls_mail_text_row TYPE soli and appended it to internal table lt_mail_text TYPE bcsy_text.

However, it's not exactly in a tabular format. We can adjust using spaces, but the display is not exactly in table form . So please suggest if any other options are possible.

Regards,

Shweta

1 ACCEPTED SOLUTION
Read only

former_member209120
Active Contributor
0 Likes
3,755

DATA:
t_objbin   TYPE STANDARD TABLE OF solisti1,   " Attachment data
t_objtxt   TYPE STANDARD TABLE OF solisti1,   " Message body
t_objpack  TYPE STANDARD TABLE OF sopcklsti1, " Packing list
t_reclist  TYPE STANDARD TABLE OF somlreci1,  " Receipient list
t_objhead  TYPE STANDARD TABLE OF solisti1.   " Header

DATA: wa_docdata TYPE sodocchgi1,   " Document data
       wa_objtxt  TYPE solisti1,     " Message body
       wa_objbin  TYPE solisti1,     " Attachment data
       wa_objpack TYPE sopcklsti1,   " Packing list
       wa_reclist TYPE somlreci1.    " Receipient list

DATA: w_tab_lines TYPE i.           " Table lines


TYPES : BEGIN OF TY_SFLIGHT,
         CARRID     TYPE  SFLIGHT-CARRID,
         CONNID     TYPE  SFLIGHT-CONNID,
         FLDATE     TYPE  SFLIGHT-FLDATE,
         PRICE      TYPE  SFLIGHT-PRICE,
         CURRENCY   TYPE  SFLIGHT-CURRENCY,
         PLANETYPE  TYPE  SFLIGHT-PLANETYPE,
         END OF TY_SFLIGHT.

TYPES : BEGIN OF TY_FINAL,
         CARRID(3) TYPE C,
         CONNID(4) TYPE C,
         FLDATE(8) TYPE C,
         PRICE(17) TYPE C,
         CURRENCY(5) TYPE C,
         PLANETYPE(10) TYPE c,
         END OF TY_FINAL.

data : it_sflight type TABLE OF TY_SFLIGHT,
        wa_sflight type TY_SFLIGHT.
data : it_FINAL type TABLE OF TY_FINAL,
        wa_FINAL type TY_FINAL.




* Start-of-selection
START-OF-SELECTION.

select CARRID
        CONNID
        FLDATE
        PRICE
        CURRENCY
        PLANETYPE
        from sflight into table it_sflight up to 10 rows.

lOOP AT IT_SFLIGHT INTO WA_SFLIGHT.
   WA_final-CARRID     =    WA_SFLIGHT-CARRID.
   WA_final-CONNID     =    WA_SFLIGHT-CONNID.
   WA_final-FLDATE     =    WA_SFLIGHT-FLDATE.
   WA_final-PRICE      =    WA_SFLIGHT-PRICE.
   WA_final-CURRENCY   =    WA_SFLIGHT-CURRENCY.
   WA_final-PLANETYPE  =    WA_SFLIGHT-PLANETYPE.
  append wa_final to it_final.
clear wa_final.
endloop.

* Creating message
   PERFORM create_message.

* Sending Message
   PERFORM send_message.

*&---------------------------------------------------------------------*
*&      Form  create_message
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM create_message .

**1 Title, Description & Body
   PERFORM create_title_desc_body.

**2 Receivers
   PERFORM fill_receivers.

ENDFORM.                    " create_message

*&---------------------------------------------------------------------*
*&      Form  CREATE_TITLE_DESC_BODY
*&---------------------------------------------------------------------*
*       Title, Description and body
*----------------------------------------------------------------------*
FORM create_title_desc_body.

*...Title
   wa_docdata-obj_name  = 'Email notification'.

*...Description
   wa_docdata-obj_descr = 'Email body in HTML'.

*...Message Body in HMTL
   wa_objtxt-line = '<html> <body style="background-color:#FFE4C4;">'.
   APPEND wa_objtxt TO t_objtxt.

   wa_objtxt-line = '<p> List of Test materials </p>'.
   APPEND wa_objtxt TO t_objtxt.

*   table display
   wa_objtxt-line = '<table style="MARGIN: 10px" bordercolor="#90EE90" '.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = ' cellspacing="0" cellpadding="3" width="400"'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = ' border="1"><tbody><tr>'.
   APPEND wa_objtxt TO t_objtxt.

*   table header
   wa_objtxt-line = '<th bgcolor="#90EE90">Airline Code</th>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<th bgcolor="#90EE90">Flight Connection Number</th>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<th bgcolor="#90EE90">Flight date</th>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<th bgcolor="#90EE90">Airfare</th>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<th bgcolor="#90EE90">Local currency of airline</th>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<th bgcolor="#90EE90">Aircraft Type</th></tr>'.
   APPEND wa_objtxt TO t_objtxt.

*   table Contents
   Loop at it_FINAL into wa_FINAL.
      wa_objtxt-line = '<tr style="background-color:#eeeeee;">'.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-CARRID '</td>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-CONNID '</td>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-FLDATE '</td>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-PRICE '</td>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-CURRENCY '</td>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-PLANETYPE '</td></tr>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     clear wa_FINAL.
   endloop.


*   table close
   wa_objtxt-line = '</tbody> </table>'.
   APPEND wa_objtxt TO t_objtxt.


*   Signature with background color
   wa_objtxt-line = '<br><br>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<p> Regards,</p>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<p style="background-color:#1E90FF;"><b> Your Name</b></p>'.
   APPEND wa_objtxt TO t_objtxt.


*   HTML close
   wa_objtxt-line = '</body> </html> '.
   APPEND wa_objtxt TO t_objtxt.

* Document data
   DESCRIBE TABLE t_objtxt      LINES w_tab_lines.
   READ     TABLE t_objtxt      INTO wa_objtxt INDEX w_tab_lines.
   wa_docdata-doc_size =
       ( w_tab_lines - 1 ) * 255 + STRLEN( wa_objtxt ).

* Packing data
   CLEAR wa_objpack-transf_bin.
   wa_objpack-head_start = 1.
   wa_objpack-head_num   = 0.
   wa_objpack-body_start = 1.
   wa_objpack-body_num   = w_tab_lines.
*   we will pass the HTML, since we have created the message
*   body in the HTML
   wa_objpack-doc_type   = 'HTML'.
   APPEND wa_objpack TO t_objpack.

ENDFORM.                    " CREATE_TITLE_DESC_BODY

*&---------------------------------------------------------------------*
*&      Form  fill_receivers
*&---------------------------------------------------------------------*
*       Filling up the Receivers
*----------------------------------------------------------------------*
FORM fill_receivers .

   wa_reclist-receiver = '[email protected]'.
   wa_reclist-rec_type = 'U'.
   APPEND wa_reclist TO t_reclist.
   CLEAR  wa_reclist.


ENDFORM.                    " fill_receivers
*&---------------------------------------------------------------------*
*&      Form  send_message
*&---------------------------------------------------------------------*
*       Sending Mail
*----------------------------------------------------------------------*
FORM send_message .

* Send Message to external Internet ID
   CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
     EXPORTING
       document_data              = wa_docdata
       put_in_outbox              = 'X'
       commit_work                = 'X'     "used from rel.6.10
     TABLES
       packing_list               = t_objpack
       object_header              = t_objhead
       contents_txt               = t_objtxt
       receivers                  = t_reclist
     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 NE 0.
     WRITE: 'Sending Failed'.
   ELSE.
     WRITE: 'Sending Successful'.
   ENDIF.
ENDFORM.                    " send_message

Mail Out put


Hi,

I need to send details of employees having 9 columns and few rows in the mail body as tabular format. I am using cl_bcs to send mail and have concatenated required data into ls_mail_text_row TYPE soli and appended it to internal table lt_mail_text TYPE bcsy_text.

However, it's not exactly in a tabular format. We can adjust using spaces, but the display is not exactly in table form . So please suggest if any other options are possible.

Regards,

Shweta

19 REPLIES 19
Read only

former_member219762
Contributor
0 Likes
3,755

Hi,

   We can do it by attaching html format.Please go through http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e009f97e-ee5d-2e10-31ba-9c9509e59...

Regards,

Sreenivas.

Read only

Former Member
0 Likes
3,755
Shweta,
To get the data to appear in tabular form, you'll need to use HTML to format it.  At my company we've created a function module for this.  Add the following html tags to your content:
<html>
<body>
<table>
  (enclose table rows in <tr> and </tr>)
  (inside the rows, enclose table cells in <td> and </td>)
</table>
</body>
</html>
Then concatenate that into your variable lt_mail_text and use that when you create the document.
data l_document type cl_document_bcs.
l_document = cl_document_bcs=>create_document(
  I_type = 'HTM'
  I_importance = 5
  I_text = lt_mail_text
  I_subject = 'Great formatted Email' ).
Best regards,
Eric
Read only

0 Likes
3,755

Hi Eric,

I used HTML code and it works.

Thank you.

Read only

0 Likes
3,755

Would you mind marking my answer as correct so people know this question is answered?  Thanks.

Read only

0 Likes
3,755

Hi,

May I point you to "The Rules of Engagement" of scn:

http://scn.sap.com/docs/DOC-19331

Grounds for Rejections of Posts or Removal from the Community:

1.Points-cheating: Creating, rating, responding to any content for the purpose of increasing one’s own or another’s points.  This includes collaboration with other users to rate content highly, creating “fake” users to rate one’s content highly, or any other points-motivated activity that does not benefit the community at large.

Regards.

Read only

0 Likes
3,755

Thank you for your concern.  I wasn't trying to abuse the points system.  I just wanted the question to be closed, since the OP replied that he had a working answer a week ago and still hasn't marked the question as complete.  This would benefit the community at large, which is why I posted.

Read only

0 Likes
3,755

Asking OP to mark answered or assumed answered should not be considered point gaming if you are not writing "rewards points if useful". In fact marking questions as answered is part of netiquette for OP.

On the other hand, there are some real point abusing instances where fake friends like every comment written by a particular person. Unfortunately there is no way to report entire person.

Read only

0 Likes
3,755

Hi,

I think that this is the role of the moderators and not us mortals....

I will never use "marking my answer as correct" .

Regards.

Read only

0 Likes
3,755

I think (not sure) that marking own answer as correct does not result in point gain. Otherwise point gamers won't need fake accounts to like and rate their content.

If OP figures out the answer after reading helpful replies, he can post full solution and mark it as correct, and other replies as helpful.

Read only

0 Likes
3,755

Hi Experts,

Our motive should help other on sharing knowledge and gaining knowledge from other.....

Points never helps you to grow.... Only knowledge helps....

Pl. stop this discussion... this is my request.

Read only

Former Member
0 Likes
3,755

Hi Shweta,

     You can achieve by representing the data in HTML format.Use tags like <tr> </tr> and <td> </td> for representing table data. But I had faced an issue where table format appears in SOST or the SAP inbox but when it came to mail id (in my case its lotus note) the table didnt appear in the mail body.

Hope this helps,

~Athreya

Read only

rosenberg_eitan
Active Contributor
0 Likes
3,755
Read only

former_member209120
Active Contributor
0 Likes
3,755

This message was moderated.

Read only

former_member209120
Active Contributor
0 Likes
3,756

DATA:
t_objbin   TYPE STANDARD TABLE OF solisti1,   " Attachment data
t_objtxt   TYPE STANDARD TABLE OF solisti1,   " Message body
t_objpack  TYPE STANDARD TABLE OF sopcklsti1, " Packing list
t_reclist  TYPE STANDARD TABLE OF somlreci1,  " Receipient list
t_objhead  TYPE STANDARD TABLE OF solisti1.   " Header

DATA: wa_docdata TYPE sodocchgi1,   " Document data
       wa_objtxt  TYPE solisti1,     " Message body
       wa_objbin  TYPE solisti1,     " Attachment data
       wa_objpack TYPE sopcklsti1,   " Packing list
       wa_reclist TYPE somlreci1.    " Receipient list

DATA: w_tab_lines TYPE i.           " Table lines


TYPES : BEGIN OF TY_SFLIGHT,
         CARRID     TYPE  SFLIGHT-CARRID,
         CONNID     TYPE  SFLIGHT-CONNID,
         FLDATE     TYPE  SFLIGHT-FLDATE,
         PRICE      TYPE  SFLIGHT-PRICE,
         CURRENCY   TYPE  SFLIGHT-CURRENCY,
         PLANETYPE  TYPE  SFLIGHT-PLANETYPE,
         END OF TY_SFLIGHT.

TYPES : BEGIN OF TY_FINAL,
         CARRID(3) TYPE C,
         CONNID(4) TYPE C,
         FLDATE(8) TYPE C,
         PRICE(17) TYPE C,
         CURRENCY(5) TYPE C,
         PLANETYPE(10) TYPE c,
         END OF TY_FINAL.

data : it_sflight type TABLE OF TY_SFLIGHT,
        wa_sflight type TY_SFLIGHT.
data : it_FINAL type TABLE OF TY_FINAL,
        wa_FINAL type TY_FINAL.




* Start-of-selection
START-OF-SELECTION.

select CARRID
        CONNID
        FLDATE
        PRICE
        CURRENCY
        PLANETYPE
        from sflight into table it_sflight up to 10 rows.

lOOP AT IT_SFLIGHT INTO WA_SFLIGHT.
   WA_final-CARRID     =    WA_SFLIGHT-CARRID.
   WA_final-CONNID     =    WA_SFLIGHT-CONNID.
   WA_final-FLDATE     =    WA_SFLIGHT-FLDATE.
   WA_final-PRICE      =    WA_SFLIGHT-PRICE.
   WA_final-CURRENCY   =    WA_SFLIGHT-CURRENCY.
   WA_final-PLANETYPE  =    WA_SFLIGHT-PLANETYPE.
  append wa_final to it_final.
clear wa_final.
endloop.

* Creating message
   PERFORM create_message.

* Sending Message
   PERFORM send_message.

*&---------------------------------------------------------------------*
*&      Form  create_message
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM create_message .

**1 Title, Description & Body
   PERFORM create_title_desc_body.

**2 Receivers
   PERFORM fill_receivers.

ENDFORM.                    " create_message

*&---------------------------------------------------------------------*
*&      Form  CREATE_TITLE_DESC_BODY
*&---------------------------------------------------------------------*
*       Title, Description and body
*----------------------------------------------------------------------*
FORM create_title_desc_body.

*...Title
   wa_docdata-obj_name  = 'Email notification'.

*...Description
   wa_docdata-obj_descr = 'Email body in HTML'.

*...Message Body in HMTL
   wa_objtxt-line = '<html> <body style="background-color:#FFE4C4;">'.
   APPEND wa_objtxt TO t_objtxt.

   wa_objtxt-line = '<p> List of Test materials </p>'.
   APPEND wa_objtxt TO t_objtxt.

*   table display
   wa_objtxt-line = '<table style="MARGIN: 10px" bordercolor="#90EE90" '.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = ' cellspacing="0" cellpadding="3" width="400"'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = ' border="1"><tbody><tr>'.
   APPEND wa_objtxt TO t_objtxt.

*   table header
   wa_objtxt-line = '<th bgcolor="#90EE90">Airline Code</th>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<th bgcolor="#90EE90">Flight Connection Number</th>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<th bgcolor="#90EE90">Flight date</th>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<th bgcolor="#90EE90">Airfare</th>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<th bgcolor="#90EE90">Local currency of airline</th>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<th bgcolor="#90EE90">Aircraft Type</th></tr>'.
   APPEND wa_objtxt TO t_objtxt.

*   table Contents
   Loop at it_FINAL into wa_FINAL.
      wa_objtxt-line = '<tr style="background-color:#eeeeee;">'.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-CARRID '</td>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-CONNID '</td>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-FLDATE '</td>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-PRICE '</td>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-CURRENCY '</td>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     concatenate '<td>' wa_FINAL-PLANETYPE '</td></tr>' into wa_objtxt-line.
     append wa_objtxt to t_objtxt.
     clear wa_FINAL.
   endloop.


*   table close
   wa_objtxt-line = '</tbody> </table>'.
   APPEND wa_objtxt TO t_objtxt.


*   Signature with background color
   wa_objtxt-line = '<br><br>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<p> Regards,</p>'.
   APPEND wa_objtxt TO t_objtxt.
   wa_objtxt-line = '<p style="background-color:#1E90FF;"><b> Your Name</b></p>'.
   APPEND wa_objtxt TO t_objtxt.


*   HTML close
   wa_objtxt-line = '</body> </html> '.
   APPEND wa_objtxt TO t_objtxt.

* Document data
   DESCRIBE TABLE t_objtxt      LINES w_tab_lines.
   READ     TABLE t_objtxt      INTO wa_objtxt INDEX w_tab_lines.
   wa_docdata-doc_size =
       ( w_tab_lines - 1 ) * 255 + STRLEN( wa_objtxt ).

* Packing data
   CLEAR wa_objpack-transf_bin.
   wa_objpack-head_start = 1.
   wa_objpack-head_num   = 0.
   wa_objpack-body_start = 1.
   wa_objpack-body_num   = w_tab_lines.
*   we will pass the HTML, since we have created the message
*   body in the HTML
   wa_objpack-doc_type   = 'HTML'.
   APPEND wa_objpack TO t_objpack.

ENDFORM.                    " CREATE_TITLE_DESC_BODY

*&---------------------------------------------------------------------*
*&      Form  fill_receivers
*&---------------------------------------------------------------------*
*       Filling up the Receivers
*----------------------------------------------------------------------*
FORM fill_receivers .

   wa_reclist-receiver = '[email protected]'.
   wa_reclist-rec_type = 'U'.
   APPEND wa_reclist TO t_reclist.
   CLEAR  wa_reclist.


ENDFORM.                    " fill_receivers
*&---------------------------------------------------------------------*
*&      Form  send_message
*&---------------------------------------------------------------------*
*       Sending Mail
*----------------------------------------------------------------------*
FORM send_message .

* Send Message to external Internet ID
   CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
     EXPORTING
       document_data              = wa_docdata
       put_in_outbox              = 'X'
       commit_work                = 'X'     "used from rel.6.10
     TABLES
       packing_list               = t_objpack
       object_header              = t_objhead
       contents_txt               = t_objtxt
       receivers                  = t_reclist
     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 NE 0.
     WRITE: 'Sending Failed'.
   ELSE.
     WRITE: 'Sending Successful'.
   ENDIF.
ENDFORM.                    " send_message

Mail Out put


Read only

0 Likes
3,755

Hi Ramesh,

Read only

0 Likes
3,755

As specified above, I used HTML tags in ABAP coding and it works. Thanks a lot for all your responces.

Read only

0 Likes
3,755

Hi Shweta,

If you got solution then close this thread by mark it as a correct answer.

Read only

FredericGirod
Active Contributor
0 Likes
3,755

Hi Shweta,

make a simple report (if it's an ALV use Docking Container) and try to use this solution :

http://scn.sap.com/docs/DOC-42253

regards

Fred

Read only

0 Likes
3,755

HI,

Use below constant to create a new line

constants:

  

   gc_crlf type c value cl_bcs_convert=>gc_crlf.

concatenate this constant at the end of your data.

This tells the system end of line. like if you are concatenating in loop then data from next loop will come in next line.