SAP壓縮excel產生zip文件後作為附件發送mail案例. ...
"SAP壓縮附件
REPORT ZMMR0033_DEL7 .
TYPES: BEGIN OF bin_file,
name TYPE string,
size TYPE i,
data TYPE solix_tab,
END OF bin_file.
DATA: lv_filename TYPE string,
wa_bindata TYPE bin_file,
it_bindata TYPE standard TABLE OF bin_file,
oref_zip TYPE REF TO cl_abap_zip,
lv_zip_xstring TYPE xstring,
lv_xstring TYPE xstring,
lv_xstring2 TYPE xstring,
lv_path TYPE string,
it_filetab TYPE filetable,
ret_code TYPE i,
v_usr TYPE i,
v_zip_size TYPE i,
it_zip_bin_data TYPE STANDARD TABLE OF raw255,
v_dest_filepath TYPE string.
DATA: BEGIN OF it_t001 OCCURS 0,
bukrs TYPE t001-bukrs,
butxt TYPE t001-butxt,
land1 TYPE t001-LAND1,
waers TYPE t001-waers,
END OF it_t001.
DATA main_text TYPE bcsy_text.
DATA: l_c_detal_1 TYPE solix_tab,
l_detal_1 TYPE so_obj_len,
l_filename_detal_1 TYPE sood-objdes.
DATA: g_datel_1 TYPE string.
CONSTANTS: gc_tab TYPE c VALUE cl_bcs_convert=>gc_tab,
gc_crlf TYPE c VALUE cl_bcs_convert=>gc_crlf.
DATA: lv_filesize TYPE i.
DATA: wa_filetab LIKE LINE OF it_filetab.
DATA: g_mail_address TYPE ad_smtpadr.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-b03.
SELECT-OPTIONS: s_addr FOR g_mail_address NO INTERVALS DEFAULT'[email protected]'.
SELECTION-SCREEN END OF BLOCK b3.
START-OF-SELECTION.
PERFORM get_data.
PERFORM DETAIL_DATA_1.
PERFORM text.
* PERFORM send_mail2 .
END-OF-SELECTION.
FORM get_data .
SELECT * FROM t001
INTO CORRESPONDING FIELDS OF TABLE it_t001 ."UP TO 10 ROWS.
ENDFORM. " get_data
FORM DETAIL_DATA_1 .
CLEAR: g_datel_1.
DATA: l_line TYPE string.
DATA:lv_text1(50),
lv_text2(50),
lv_text3(50),
lv_text4(50),
lv_text5(50).
*--> column header
CONCATENATE '存儲地點' '工廠' '物料類型'
INTO l_line SEPARATED BY gc_tab.
*--> 斷行
CONCATENATE g_datel_1 l_line gc_crlf INTO g_datel_1.
LOOP AT it_t001.
lv_text1 = it_t001-bukrs .
lv_text2 = it_t001-butxt .
lv_text3 = it_t001-land1 .
lv_text4 = it_t001-waers .
lv_text5 = it_t001-bukrs .
CONCATENATE lv_text1 lv_text2 lv_text3 lv_text4 lv_text5
INTO l_line SEPARATED BY gc_tab.
*--> 斷行
CONCATENATE g_datel_1 l_line gc_crlf INTO g_datel_1.
ENDLOOP.
TRY.
cl_bcs_convert=>string_to_solix