ZIP 압축하는 예제 프로그램.
*&---------------------------------------------------------------------*
*& Report ZZIP
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zzip.
DATA: lt_file_table TYPE filetable,
ls_file_table TYPE file_table,
lv_rc TYPE i,
lv_filename TYPE string,
lv_path TYPE string,
lv_fullpath TYPE string,
lv_filelength TYPE i,
lt_temptable TYPE w3mimetabtype,
lv_xstring TYPE xstring,
lo_zip TYPE REF TO cl_abap_zip.
cl_gui_frontend_services=>file_open_dialog(
EXPORTING
* window_title = " Title Of File Open Dialog
* default_extension = " Default Extension
* default_filename = " Default File Name
* file_filter = " File Extension Filter String
* with_encoding = " File Encoding
* initial_directory = " Initial Directory
multiselection = abap_true " Multiple selections poss.
CHANGING
file_table = lt_file_table " Table Holding Selected Files
rc = lv_rc " Return Code, Number of Files or -1 If Error Occurred
* user_action = " User Action (See Class Constants ACTION_OK, ACTION_CANCEL)
* file_encoding =
EXCEPTIONS
file_open_dialog_failed = 1 " "Open File" dialog failed
cntl_error = 2 " Control error
error_no_gui = 3 " No GUI available
not_supported_by_gui = 4 " GUI does not support this
OTHERS = 5
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CHECK: lt_file_table IS NOT INITIAL.
CREATE OBJECT lo_zip.
lo_zip->support_unicode_names = abap_true.
LOOP AT lt_file_table INTO ls_file_table.
CLEAR: lv_filename, lv_filelength, lt_temptable, lv_xstring.
lv_filename = ls_file_table-filename.
cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = lv_filename " Name of file
filetype = 'BIN' " File Type (ASCII, Binary)
* has_field_separator = space " Columns Separated by Tabs in Case of ASCII Upload
* header_length = 0 " Length of Header for Binary Data
* read_by_line = 'X' " File Written Line-By-Line to the Internal Table
* dat_mode = space " Numeric and date fields are in DAT format in WS_DOWNLOAD
* codepage = " Character Representation for Output
* ignore_cerr = abap_true " Ignore character set conversion errors?
* replacement = '#' " Replacement Character for Non-Convertible Characters
* virus_scan_profile = " Virus Scan Profile
IMPORTING
filelength = lv_filelength " File Length
* header = " File Header in Case of Binary Upload
CHANGING
data_tab = lt_temptable " Transfer table for file contents
* isscanperformed = space " File already scanned
EXCEPTIONS
file_open_error = 1 " File does not exist and cannot be opened
file_read_error = 2 " Error when reading file
no_batch = 3 " Cannot execute front-end function in background
gui_refuse_filetransfer = 4 " Incorrect front end or error on front end
invalid_type = 5 " Incorrect parameter FILETYPE
no_authority = 6 " No upload authorization
unknown_error = 7 " Unknown error
bad_data_format = 8 " Cannot Interpret Data in File
header_not_allowed = 9 " Invalid header
separator_not_allowed = 10 " Invalid separator
header_too_long = 11 " Header information currently restricted to 1023 bytes
unknown_dp_error = 12 " Error when calling data provider
access_denied = 13 " Access to file denied.
dp_out_of_memory = 14 " Not enough memory in data provider
disk_full = 15 " Storage medium is full.
dp_timeout = 16 " Data provider timeout
not_supported_by_gui = 17 " GUI does not support this
error_no_gui = 18 " GUI not available
OTHERS = 19
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lv_filelength
* first_line = 0
* last_line = 0
IMPORTING
buffer = lv_xstring
TABLES
binary_tab = lt_temptable
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
EXPORTING
full_name = ls_file_table-filename
IMPORTING
stripped_name = lv_filename
EXCEPTIONS
x_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
lo_zip->add(
EXPORTING
name = lv_filename
content = lv_xstring
* compress_level = 6 " Level of Compression
).
ENDLOOP.
lv_xstring = lo_zip->save( ).
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_xstring
IMPORTING
output_length = lv_filelength
TABLES
binary_tab = lt_temptable.
cl_gui_frontend_services=>file_save_dialog(
EXPORTING
* window_title = " Window Title
default_extension = 'ZIP' " Default Extension
default_file_name = 'a.zip' " Default File Name
* with_encoding =
file_filter = 'ZIP(*.ZIP)|*.ZIP' " File Type Filter Table
* initial_directory = " Initial Directory
* prompt_on_overwrite = 'X'
CHANGING
filename = lv_filename " File Name to Save
path = lv_path " Path to File
fullpath = lv_fullpath " Path + File Name
* user_action = " User Action (C Class Const ACTION_OK, ACTION_OVERWRITE etc)
* file_encoding =
EXCEPTIONS
cntl_error = 1 " Control error
error_no_gui = 2 " No GUI available
not_supported_by_gui = 3 " GUI does not support this
invalid_default_file_name = 4 " Invalid default file name
OTHERS = 5
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
cl_gui_frontend_services=>gui_download(
EXPORTING
bin_filesize = lv_filelength " File length for binary files
filename = lv_fullpath " Name of file
filetype = 'BIN' " File type (ASCII, binary ...)
* append = space " Character Field of Length 1
* write_field_separator = space " Separate Columns by Tabs in Case of ASCII Download
* header = '00' " Byte Chain Written to Beginning of File in Binary Mode
* trunc_trailing_blanks = space " Do not Write Blank at the End of Char Fields
* write_lf = 'X' " Insert CR/LF at End of Line in Case of Char Download
* col_select = space " Copy Only Selected Columns of the Table
* col_select_mask = space " Vector Containing an 'X' for the Column To Be Copied
* dat_mode = space " Numeric and date fields are in DAT format in WS_DOWNLOAD
* confirm_overwrite = space " Overwrite File Only After Confirmation
* no_auth_check = space " Switch off Check for Access Rights
* codepage = " Character Representation for Output
* ignore_cerr = abap_true " Ignore character set conversion errors?
* replacement = '#' " Replacement Character for Non-Convertible Characters
* write_bom = space " If set, writes a Unicode byte order mark
* trunc_trailing_blanks_eol = 'X' " Remove Trailing Blanks in Last Column
* wk1_n_format = space
* wk1_n_size = space
* wk1_t_format = space
* wk1_t_size = space
* show_transfer_status = 'X' " Enables suppression of transfer status message
* fieldnames = " Table Field Names
* write_lf_after_last_line = 'X' " Writes a CR/LF after final data record
* virus_scan_profile = '/SCET/GUI_DOWNLOAD' " Virus Scan Profile
* IMPORTING
* filelength = " Number of bytes transferred
CHANGING
data_tab = lt_temptable " Transfer table
EXCEPTIONS
file_write_error = 1 " Cannot write to file
no_batch = 2 " Cannot execute front-end function in background
gui_refuse_filetransfer = 3 " Incorrect Front End
invalid_type = 4 " Invalid value for parameter FILETYPE
no_authority = 5 " No Download Authorization
unknown_error = 6 " Unknown error
header_not_allowed = 7 " Invalid header
separator_not_allowed = 8 " Invalid separator
filesize_not_allowed = 9 " Invalid file size
header_too_long = 10 " Header information currently restricted to 1023 bytes
dp_error_create = 11 " Cannot create DataProvider
dp_error_send = 12 " Error Sending Data with DataProvider
dp_error_write = 13 " Error Writing Data with DataProvider
unknown_dp_error = 14 " Error when calling data provider
access_denied = 15 " Access to file denied.
dp_out_of_memory = 16 " Not enough memory in data provider
disk_full = 17 " Storage medium is full.
dp_timeout = 18 " Data provider timeout
file_not_found = 19 " Could not find file
dataprovider_exception = 20 " General Exception Error in DataProvider
control_flush_error = 21 " Error in Control Framework
not_supported_by_gui = 22 " GUI does not support this
error_no_gui = 23 " GUI not available
OTHERS = 24
).
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
'ABAP' 카테고리의 다른 글
SY-DATUM 과 SY-DATLO 차이 (0) | 2024.01.04 |
---|---|
abap으로 open API (RESTful) 호출하기 (2) | 2023.12.20 |
search help exit 총정리 (0) | 2023.04.25 |
FUNCTION ZADD_1_ALPHANUM (0) | 2022.12.20 |
ABAP TIMESTAMP 총정리 (0) | 2021.12.27 |