Skip to Content
0

CL_BCS - How do I populate an Excel attachment in a mail with data and headers of an internal table?

Nov 01, 2016 at 12:04 PM

417

avatar image
Former Member
* for the SENDMAIL button<br>
 IF gv_user = 'X'.<br>
 gv_user = ''.<br>
 ELSE.<br>
 gv_user = 'X'.<br>
 ENDIF.<br>
<br>
 FIELD-SYMBOLS: <fs_receiver> TYPE yrecipients.<br>
<br>
 TRY.<br>
<br>
 lo_send_request = cl_bcs=>create_persistent( ).<br>
<br>
 " Write the e-mail text<br>
 APPEND 'Dear associate, ...' TO i_text.<br>
 APPEND 'Thank you and best regards!' TO i_text.<br>
<br>
 " Send in RAW, TXT, HTML etc. format<br>
 lo_document = cl_document_bcs=>create_document(<br>
 i_type = 'RAW'<br>
 i_text = i_text<br>
 i_hex = lt_body_hex<br>
 i_subject = 'Monthly Billing Error List' ) .<br>

*add the document as an attachment<br>
 lo_document->add_attachment(<br>
 i_attachment_type = 'xls' " lv_attachment_type<br>
* i_attachment_size = lv_attachment_size<br>
 i_attachment_subject = 'attachment' " lv_attachment_subject<br>
 i_att_content_hex = lt_att_content_hex ).<br>
* ENDIF.<br>
<br>
 " set the e-mail address of the sender:<br>
 lo_sender = cl_cam_address_bcs=>create_internet_address( 'do-not-reply@domain.com' ).<br>
<br>
 " set the e-mail address of the recipient<br>
 SELECT * FROM yrecipients<br>
 INTO TABLE gt_recipients<br>
 FOR ALL ENTRIES IN gt_recipients<br>
 WHERE vkorg = gt_recipients-vkorg.<br>
<br>
 LOOP AT gt_recipients ASSIGNING <fs_receiver>.<br>
 lo_recipient = cl_sapuser_bcs=>create( sy-uname ).<br>
 lo_send_request->add_recipient( lo_recipient ) .<br>
 ENDLOOP.<br>
<br>
 " assign document to the send request:<br>
 lo_send_request->set_document( lo_document ).<br>
<br>
 " add the sender:<br>
 lo_send_request->set_sender( lo_sender ).<br>
<br>
 MOVE space TO lv_with_error_screen.<br>
 " SAP Send Email CL_BCS<br>
 lv_sent_to_all = lo_send_request->send( lv_with_error_screen ).<br>
<br>
 CATCH cx_document_bcs INTO lx_document_bcs.<br>
<br>
 CATCH cx_send_req_bcs INTO bcs_error.<br>
 bcs_mess = bcs_error->get_text( ).<br>
<br>
 ENDTRY.<br>
<br>
ENDFORM. 
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Kali Charan Nov 01, 2016 at 12:13 PM
0

Have you Seen the Below Standard Example

BCS_EXAMPLE_7

They are fetching the Data from table and concatenate to the long string Lv_string, Then passing it to the class.

Share
10 |10000 characters needed characters left characters exceeded