Есть в ABAP такой замечательный класс CL_ABAP_ZIP, который позволяет упаковывать файлы и папки в ZIP. Ниже представлен пример программы, который создает ZIP для выбранной директории.
Код
data : gv_file_length type i,
gv_filehexcontent type xstring,
gv_zipfilehex type xstring,
gt_filebincontent type solix_tab,
gt_zipfilebin type solix_tab,
go_zipper type ref to cl_abap_zip,
gv_zipfilename type string,
gv_folder type string,
gt_files type table of char255 with header line,
gv_file type string,
gv_file_fullpath type string,
gv_no_files type i.
cl_gui_frontend_services=>directory_browse( exporting window_title = 'Folder selection'
changing selected_folder = gv_folder
exceptions others = 4 ).
check sy-subrc eq 0.
cl_gui_frontend_services=>directory_list_files( exporting directory = gv_folder
files_only = 'X'
changing file_table = gt_files[]
count = gv_no_files
exceptions others = 4 ).
check sy-subrc eq 0.
check gv_no_files gt 0.
create object go_zipper.
loop at gt_files.
move gt_files to gv_file.
concatenate gv_folder '\' gv_file into gv_file_fullpath.
cl_gui_frontend_services=>gui_upload(
exporting
filename = gv_file_fullpath
filetype = 'BIN'
importing
filelength = gv_file_length
changing
data_tab = gt_filebincontent
exceptions
others = 4 ).
check sy-subrc eq 0.
call function 'SCMS_BINARY_TO_XSTRING'
exporting
input_length = gv_file_length
importing
buffer = gv_filehexcontent
tables
binary_tab = gt_filebincontent
exceptions
failed = 1
others = 2.
check sy-subrc eq 0.
go_zipper->add( name = gv_file
content = gv_filehexcontent ).
endloop.
gv_zipfilehex = go_zipper->save( ).
call function 'SCMS_XSTRING_TO_BINARY'
exporting
buffer = gv_zipfilehex
tables
binary_tab = gt_zipfilebin.
concatenate gv_folder '.zip' into gv_zipfilename.
call method cl_gui_frontend_services=>gui_download
exporting
filename = gv_zipfilename
filetype = 'BIN'
changing
data_tab = gt_zipfilebin
exceptions
others = 4.
Этот комментарий был удален автором.
ОтветитьУдалить