Skip to Content
author's profile photo Former Member
Former Member

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

* for the SENDMAIL button<br>
 IF gv_user = 'X'.<br>
 gv_user = ''.<br>
 gv_user = 'X'.<br>
 FIELD-SYMBOLS: <fs_receiver> TYPE yrecipients.<br>
 lo_send_request = cl_bcs=>create_persistent( ).<br>
 " Write the e-mail text<br>
 APPEND 'Dear associate, ...' TO i_text.<br>
 APPEND 'Thank you and best regards!' TO i_text.<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>
 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>
 " set the e-mail address of the sender:<br>
 lo_sender = cl_cam_address_bcs=>create_internet_address( '' ).<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>
 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>
 " assign document to the send request:<br>
 lo_send_request->set_document( lo_document ).<br>
 " add the sender:<br>
 lo_send_request->set_sender( lo_sender ).<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>
 CATCH cx_document_bcs INTO lx_document_bcs.<br>
 CATCH cx_send_req_bcs INTO bcs_error.<br>
 bcs_mess = bcs_error->get_text( ).<br>
Add comment
10|10000 characters needed characters exceeded

1 Answer

  • Best Answer
    Posted on Nov 01, 2016 at 12:13 PM

    Have you Seen the Below Standard Example


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

    Add comment
    10|10000 characters needed characters exceeded