Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Unzip file

Former Member
0 Kudos

Hi all,

I have trying to unzip a server file. I have using this code:

DATA: BEGIN OF tabl OCCURS 500,

line(400),

END OF tabl.

CALL 'SYSTEM' ID 'COMMAND' FIELD 'unzip -o /usr/sap/tmp/TAS000002_TAS_2010110430.ZIP'

ID 'TAB' FIELD tabl[].

The result of this instruction is sy-subrc = 0 and the content of the table tabl is:

Archive: /usr/sap/tmp/TAS000002_TAS_2010110430.ZIP

inflating: 0301066001020100000000017001.JPG

inflating: 0301066001020100000000017002.JPG

inflating: 0301066001020100000000017003.JPG

inflating: 0301066001020100000000251004.JPG

inflating: 0301066001020100000000251005.JPG

inflating: 0301066001020100000000251006.JPG

inflating: 0301066001020100000000251007.JPG

inflating: 0301066001020100000000251008.JPG

inflating: 0301066001020100000000251009.JPG

inflating: 0301066001020100000000251010.JPG

inflating: 0301066001020100000000251011.JPG

inflating: 0301066001020100000000251012.JPG

inflating: 0301066001020100000000087013.PDF

inflating: 0301066001020100000000024014.PDF

It seems to it works correctly but in the path /usr/sap/tmp/ there is no new files.

My question is can I unzip a file into the server? Does SAP allow this?

Thanks in advance,

Ruben

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Have you tried class CL_ABAP_ZIP? It has a simple API.

You may also go through this links.

8 REPLIES 8

Former Member
0 Kudos

Hi,

Have you tried class CL_ABAP_ZIP? It has a simple API.

You may also go through this links.

0 Kudos

Hi Vinraaj,

yes, I have seen a lot of threads of this forum. I have tried a lot of possible solutions with class CL_ABAP_ZIP and CL_ABAP_GZIP unsuccessfully.

I only need some abap example with this functionality works.

Many thanks in advance,

Ruben

0 Kudos

Please check the thread , there is sample provided which might be useful.

Regards

Ranganath

Former Member
0 Kudos

Hi rbnhid ,

You got solution for this? I have the same requirement to unzip certain files from ftp and transfer the extracted files to another directory in ftp.

Regards

Siva

0 Kudos

Hi,

yes I have resolved this query. I send you the code I used that unzip the zip file in the same path.

REPORT zunzip.

TYPES: t_xline(2048) TYPE x,

BEGIN OF t_line,

line(1024) TYPE c,

END OF t_line.

DATA: size TYPE i,

data_tab TYPE STANDARD TABLE OF t_xline,

ls_data_tab LIKE LINE OF data_tab,

text_tab TYPE STANDARD TABLE OF t_line,

input_x TYPE xstring,

output_x TYPE xstring,

cl_zip TYPE REF TO cl_abap_zip,

files LIKE LINE OF cl_abap_zip=>files,

name TYPE string,

lv_output TYPE string,

lv_unix TYPE i,

lv_path TYPE string,

lt_result TYPE match_result_tab,

ls_result LIKE LINE OF lt_result,

lv_lineas TYPE i,

lv_offset TYPE i.

PARAMETER: p_file TYPE string OBLIGATORY LOWER CASE.

START-OF-SELECTION.

lv_path = p_file.

IF p_file(1) = '/'.

lv_unix = 1.

FIND ALL OCCURRENCES OF '/' IN lv_path RESULTS lt_result.

DESCRIBE TABLE lt_result LINES lv_lineas.

READ TABLE lt_result INTO ls_result INDEX lv_lineas.

lv_offset = ls_result-offset + 1.

lv_path = lv_path(lv_offset).

ELSE.

lv_unix = 0.

FIND ALL OCCURRENCES OF '\' IN lv_path RESULTS lt_result.

DESCRIBE TABLE lt_result LINES lv_lineas.

READ TABLE lt_result INTO ls_result INDEX lv_lineas.

lv_offset = ls_result-offset + 1.

lv_path = lv_path(lv_offset).

ENDIF.

IF lv_unix EQ 0.

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = p_file

filetype = 'BIN'

IMPORTING

filelength = size

CHANGING

data_tab = data_tab.

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

EXPORTING

input_length = size

IMPORTING

buffer = input_x

TABLES

binary_tab = data_tab.

ELSE.

OPEN DATASET p_file IN BINARY MODE FOR INPUT.

IF sy-subrc EQ 0.

READ DATASET p_file INTO input_x.

CLOSE DATASET p_file.

ENDIF.

ENDIF.

CREATE OBJECT cl_zip.

CALL METHOD cl_zip->load( EXPORTING zip = input_x ).

LOOP AT cl_zip->files INTO files.

CLEAR output_x.

MOVE files-name TO name.

cl_zip->get( EXPORTING name = name

IMPORTING content = output_x ).

REFRESH data_tab.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = output_x

IMPORTING

output_length = size

TABLES

binary_tab = data_tab.

CALL FUNCTION 'SCMS_BINARY_TO_TEXT'

EXPORTING

input_length = size

TABLES

binary_tab = data_tab

text_tab = text_tab.

CONCATENATE lv_path name INTO lv_output.

IF lv_unix EQ 0.

CALL METHOD cl_gui_frontend_services=>gui_download

EXPORTING

bin_filesize = size

filename = lv_output

filetype = 'BIN'

CHANGING

data_tab = data_tab.

ELSE.

OPEN DATASET lv_output FOR OUTPUT IN BINARY MODE.

IF sy-subrc EQ 0.

LOOP AT data_tab INTO ls_data_tab.

TRANSFER ls_data_tab TO lv_output.

ENDLOOP.

CLOSE DATASET lv_output.

ENDIF.

ENDIF.

ENDLOOP.

0 Kudos

hi,

Thanks for your help.

i tried this code and it gets into dump error..

Error analysis

A RAISE statement in the program "CL_ABAP_ZIP===================CP" raised the

exception

condition "ZIP_PARSE_ERROR".

Since the exception was not intercepted by a superior

program, processing was terminated.

Regards

Siva

0 Kudos

Hi,

what version do you have? My version is 6.0. Perhaps this class is different between these versions.

Have you debugged the code?

Regards,

Ruben

0 Kudos

Hi,

The problem exactly happening at the below statement.

-> CALL METHOD cl_zip->load( EXPORTING zip = input_x ).

This class is working when i try to extract files from PC or presentation server but showing dump when extracting from application server.

-Siva