I would like to zip a document i retrieved from content management system into a folder, such as <b>template.zip</b>
I tried to use the class cl_abap_gzip=>compress_binary, and download to local drive. It was downloaded in the .zip file, but I was unable to open this .zip file.
Below is my code to zip and gui_download. Am i downloading to the right extension (.zip) or it should be coded in another way?
Kindly review and correct my mistake.
" retrieve document from content management system CALL METHOD cl_crm_documents=>get_with_table EXPORTING loio = ls_loios raw_mode = 'X' IMPORTING file_access_info = lt_file_info file_content_binary = lt_contents error = ls_error. READ TABLE lt_file_info INTO ls_file_info INDEX 1. DATA: raw_in TYPE xstring, gzip_out TYPE xstring, input_length TYPE i, raw_in_len TYPE i, gzip_out_len TYPE i, crc32(4) TYPE x. input_length = ls_file_info-file_size. " convert to xstring CALL FUNCTION 'SCMS_BINARY_TO_XSTRING' EXPORTING input_length = input_length IMPORTING buffer = raw_in TABLES binary_tab = lt_contents 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. " get the length of xstring raw_in_len = XSTRLEN( raw_in ). " compress the file TRY. CALL METHOD cl_abap_gzip=>compress_binary EXPORTING raw_in = raw_in raw_in_len = raw_in_len compress_level = 6 IMPORTING gzip_out = gzip_out gzip_out_len = gzip_out_len. CATCH cx_parameter_invalid_range . CATCH cx_sy_buffer_overflow . ENDTRY. " convert the compressed xstring to binary CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = gzip_out IMPORTING output_length = gzip_out_len TABLES binary_tab = lt_contents. " download to presentation server CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING bin_filesize = gzip_out_len filename = 'c:template.zip' filetype = 'BIN' CHANGING data_tab = lt_contents EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 not_supported_by_gui = 22 error_no_gui = 23 OTHERS = 24.
Thanks & Regards,
I think gzip is used to compress files in gz... well at least in linux is like that.
Do you have a gzip program in your desktop? you could try to change the file name, i.e. c:\template.gz and try to uncompress with gzip...