在工作中,我们常常需要将订单、出库单和发票等单据用excel的方式发给用户或者客户。
网上有很多的相关的代码,但简洁已于使用的还是SAP的样例代码,请参见BCS_EXAMPLE_7
sap代码我摘抄如下:
report bcs_example_7.
* This report provides an example for sending an Excel
* attachment in Unicode Systems
constants:
gc_tab type c value cl_bcs_convert=>gc_tab,
gc_crlf type c value cl_bcs_convert=>gc_crlf.
parameters:
mailto type ad_smtpadr
default 'john.doe@crazy-company.com'. "#EC *
data send_request type ref to cl_bcs.
data document type ref to cl_document_bcs.
data recipient type ref to if_recipient_bcs.
data bcs_exception type ref to cx_bcs.
data main_text type bcsy_text.
data binary_content type solix_tab.
data size type so_obj_len.
data sent_to_all type os_boolean.
start-of-selection.
perform create_content.
perform send.
*&---------------------------------------------------------------------*
*& Form send
*&---------------------------------------------------------------------*
form send.
try.
* -------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
* -------- create and set document with attachment ---------------
* create document object from internal table with text
append 'Hello world!' to main_text. "#EC NOTEXT
document = cl_document_bcs=