Zip Dosya Oluşturma (Çoklu Dosya & Sıkıştırma)
Kullanım :
perform f_downoad_xlsx.
types: begin of ty_x_data,
data type zsd_t_table,
tabname like dd02l-tabname,
filename type string,
end of ty_x_data.
types: begin of ty_x_splice_entry,
name type string,
offset type i,
length type i,
compressed type i,
end of ty_x_splice_entry.
types: tty_x_data type standard table of ty_x_data.
form f_prepare_file using prm_path type string
prt_master type zsd_t_table .
data: ls_file type ty_x_data.
data: lt_outtab type ref to data.
data: lt_data type tty_x_data.
ls_file-data = prt_master.
ls_file-filename = `Dosya.XLS`.
ls_file-tabname = `ZSD_S_TABLE`.
append ls_file to lt_data.
perform sub_create_zip_file using lt_data prm_path.
endform. "f_prepare_file
*&---------------------------------------------------------------------*
*& Form f_downoad_xlsx
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form f_downoad_xlsx.
data: lv_file type string.
data: lv_file_name type string.
data: lv_file_path type string.
data: lv_file_fullpath type string.
data: lv_default_file_name type string.
data: lv_user_action type i.
concatenate `SD Raporu ` sy-datum into lv_default_file_name separated by `_`.
* Display save dialog window
call method cl_gui_frontend_services=>file_save_dialog
exporting
* window_title = ` `
default_extension = `ZIP`
default_file_name = lv_default_file_name
initial_directory = ``
changing
filename = lv_file_name
path = lv_file_path
fullpath = lv_file_fullpath
user_action = lv_user_action.
check lv_file_fullpath is not initial.
perform f_prepare_file using lv_file_fullpath gt_master .
endform. "f_downoad_xlsx
*&---------------------------------------------------------------------*
*& Form sub_create_zip_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form sub_create_zip_file using prt_data type tty_x_data
prm_path type string.
data :
data_line type ref to data,
ixml type xstring,
xml type string,
izip type ref to cl_abap_zip,
zip_file type xstring,
binary_tab type standard table of x255,
lwa_data type ty_x_data,
lt_splice_entries type table of ty_x_splice_entry,
lwa_splice_entries type ty_x_splice_entry,
l_filename type string,
input_length type i,
lv_index type sytabix,
lwa_file type ty_x_data.
data: lt_fieldcat type lvc_t_fcat .
data: ls_fieldcat type lvc_s_fcat .
field-symbols : <fs_data> type zsd_t_ka_satis,
<fs_data_row> type zsd_s_ka_satis,
<fs_data_field> type any.
create object izip.
data: lt_textdata type truxs_t_text_data.
data: ls_textdata like line of lt_textdata.
data: lv_content type string.
data: lvx_content type xstring.
data: ls_row type zsd_s_ka_satis.
data: lv_cell type string.
data: lv_xndx type int4.
data: app_type(50) .
app_type = `text/plain; charset=iso-8859-1`.
*Download to XML File(s)
loop at prt_data into lwa_data.
clear : data_line,zip_file,binary_tab[],ixml,xml.
clear lv_content.
perform f_append_header_row using lwa_data-tabname
changing lv_content .
call method ref_grid_master->get_frontend_fieldcatalog
importing
et_fieldcatalog = lt_fieldcat[].
delete lt_fieldcat[] where no_out = `X`.
loop at lwa_data-data assigning <fs_data_row>.
loop at lt_fieldcat into ls_fieldcat.
lv_xndx = sy-tabix.
if <fs_data_field> is assigned. unassign <fs_data_field>. endif.
assign component ls_fieldcat-fieldname of structure <fs_data_row> to <fs_data_field>.
if <fs_data_field> is assigned.
clear lv_cell.
lv_cell = <fs_data_field>.
if ls_fieldcat-datatype = `CURR` or ls_fieldcat-datatype = `QUAN` .
replace all occurrences of `.` in lv_cell with `,`.
replace all occurrences of `-` in lv_cell with ``.
if sy-subrc eq 0.
concatenate `-` lv_cell into lv_cell.
endif .
endif.
concatenate lv_content lv_cell cl_abap_char_utilities=>horizontal_tab into lv_content.
endif.
endloop.
concatenate lv_content cl_abap_char_utilities=>newline into lv_content.
endloop.
call function `SCMS_STRING_TO_XSTRING`
exporting
text = lv_content
mimetype = app_type
encoding = `1100` "`4110` " >>>> UTF8
importing
buffer = lvx_content
exceptions
failed = 1
others = 2.
if sy-subrc <> 0.
*124 IBM EBCDIC 00697/00297
*1100 iso-8859-1
*1105 US-ASCII (7 bits)
*1160 windows-1252
*4102 utf-16be
*4103 utf-16le
*4110 utf-8
*8000 Shift-JIS
*8300 BIG5
endif.
izip->add( name = lwa_data-filename
content = lvx_content ).
endloop.
*concatenate cl_abap_char_utilities=>byte_order_mark_utf8
* zip_file
* into zip_file in byte mode.
*Create a new zip file
zip_file = izip->save( ).
call function `SCMS_XSTRING_TO_BINARY`
exporting
buffer = zip_file
tables
binary_tab = binary_tab.
cl_gui_frontend_services=>gui_download(
exporting
filename = prm_path
filetype = `BIN`
changing
data_tab = binary_tab ). "i_tab2 ).
if sy-subrc ne 0.
raise file_not_created.
endif.
endform. " SUB_CREATE_ZIP_FILE
*&---------------------------------------------------------------------*
*& Form f_append_row_xml
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PRM_TABNAME text
* <--CHN_XML text
*----------------------------------------------------------------------*
form f_append_header_row using prm_tabname type tabname
changing chn_header type string.
data: lt_fieldcat type lvc_t_fcat .
data: ls_fieldcat type lvc_s_fcat .
data: lv_xml_columns type string.
call method ref_grid_master->get_frontend_fieldcatalog
importing
et_fieldcatalog = lt_fieldcat[].
delete lt_fieldcat[] where no_out = `X`.
clear lv_xml_columns.
loop at lt_fieldcat into ls_fieldcat where no_out is initial.
concatenate lv_xml_columns ls_fieldcat-scrtext_m cl_abap_char_utilities=>horizontal_tab into lv_xml_columns .
endloop.
concatenate lv_xml_columns cl_abap_char_utilities=>newline into chn_header.
endform. "f_append_row_xml