*Convert ALV list to excel format
lv_xml_type = if_salv_bs_xml=>c_type_mhtml.
lv_xml = gr_table->to_xml( xml_type = lv_xml_type ).
TRY.
size = xstrlen( lv_xml ).
*Send ALV converted excel file attachment
binary_content = cl_document_bcs=>xstring_to_solix(
ip_xstring = lv_xml ).
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document with attachment ---------------
* create document object from the internal table with text
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = main_text
i_subject = 'ZBKLG_Report' ). "#EC NOTEXT
* add the spreadsheet as an attachment to document object
document->add_attachment(
i_attachment_type = 'XLS' "#EC NOTEXT
i_attachment_subject = lv_sub "'ExampleSpreadSheet'
i_attachment_size = size
i_att_content_hex = binary_content ).
* add document object to send request
send_request->set_document( document ).
* --------- add recipient (e-mail address) -----------------------
* create recipient object
LOOP AT s_email.
recipient =
cl_cam_address_bcs=>create_internet_address( s_email-low ).
ld_email = s_email-low.
* add recipient object to send request
send_request->add_recipient( recipient ).
ENDLOOP.
* ---------- send document ---------------------------------------
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
COMMIT WORK.
IF sy-subrc <> 0.
MOVE text-e05 TO l_msg.
REPLACE '&1' WITH p_email INTO l_msg.
MESSAGE l_msg TYPE 'E' DISPLAY LIKE 'E'.
ELSE.
MOVE text-s02 TO l_msg.
REPLACE '&1' WITH ld_email INTO l_msg.
MESSAGE l_msg TYPE 'I' DISPLAY LIKE 'I'.
ENDIF.
* ------------ exception handling ----------------------------------
* replace this rudimentary exception handling with your own one !!!
CATCH cx_bcs INTO bcs_exception.
MESSAGE i865(so) WITH bcs_exception->error_type.
ENDTRY.
But it'll not show the leading zero for order number if you define refer to system field VBELN/EBELN etc. In an excel file, the leading zero will hide automatically although we send it out with leading zeros.
The quick way is to choose this column and set the custom format as 0000000000, then Excel will follow this format and display correctly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |