cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos
* 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. 

Accepted Solutions (1)

Accepted Solutions (1)

former_member196331
Active Contributor
0 Kudos

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.

Answers (0)