Application Development and Automation 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: 
Read only

Read a zip file from Application server.

Former Member
0 Likes
4,782

Hi,

Is there a way to read a zip file from the applicatoin server to internal table in ABAP program? The operation system is running MS windows server. The zip file contains only 1 text file. I tried to use open dataset 'uncompress', and use read dataset, but read dataset gave me sy-subrc = 4. Any feedback is greatly appreciated.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,384

hi,

briefly, without error handling.

DATA zip TYPE REF TO cl_abap_zip.

DATA file_name TYPE string.

DATA zipped_data TYPE xstring.

DATA unzipped_data TYPE xstring.

OPEN DATASET file_name IN BINARY MODE FOR INPUT.

READ DATASET file_name INTO zipped_data.

*CLOSE DATASET file_name.

CREATE OBJECT zip.

zip->load( zipped_data ).

CALL METHOD zip->get

EXPORTING

index = 1 " first file in zip

IMPORTING

content = unzipped_data.

hi,

briefly, without error handling.

DATA zip TYPE REF TO cl_abap_zip.

DATA file_name TYPE string.

DATA zipped_data TYPE xstring.

DATA unzipped_data TYPE xstring.

OPEN DATASET file_name IN BINARY MODE FOR INPUT.

READ DATASET file_name INTO zipped_data.

*CLOSE DATASET file_name.

CREATE OBJECT zip.

zip->load( zipped_data ).

CALL METHOD zip->get

EXPORTING

index = 1 " first file in zip

IMPORTING

content = unzipped_data.

5 REPLIES 5
Read only

chaiphon
Contributor
0 Likes
2,384

Check out this [Thread|;.

This last answer from Thomas may help you.

Chaiphon

Read only

Former Member
0 Likes
2,385

hi,

briefly, without error handling.

DATA zip TYPE REF TO cl_abap_zip.

DATA file_name TYPE string.

DATA zipped_data TYPE xstring.

DATA unzipped_data TYPE xstring.

OPEN DATASET file_name IN BINARY MODE FOR INPUT.

READ DATASET file_name INTO zipped_data.

*CLOSE DATASET file_name.

CREATE OBJECT zip.

zip->load( zipped_data ).

CALL METHOD zip->get

EXPORTING

index = 1 " first file in zip

IMPORTING

content = unzipped_data.

Read only

0 Likes
2,384

Thanks for the quick response.

I tested it, and I get the data from the zip file. And now how to I read the data as lines of character type? I'd like to read content of the data and populate it in the internal table.

Thanks

Lily

Read only

0 Likes
2,384

hi,

to convert xstring to text you can use this:


DATA unzipped_data TYPE xstring.
DATA text_data TYPE string.
DATA conv_x2c TYPE REF TO cl_abap_conv_in_ce.

conv_x2c = cl_abap_conv_in_ce=>create( ).
conv_x2c->convert( EXPORTING input = unzipped_data IMPORTING data = text_data ).

moreover, if you want to split your text at "end of line" (CR LF in microsoft windows) into lines:


DATA text_lines TYPE TABLE OF string.

SPLIT text_data AT cl_abap_char_utilities=>cr_lf INTO TABLE text_lines.

Read only

Former Member
0 Likes
2,384

Some days ago I downloaded a film in zip archive. Today I have tried to watch it but I couldn't extract the archive. I saw an unknown error. My friend told me that he didn't know what to do next. I was distressed, but suddenly entered the Google and by chance found - <a href="http://www.recoverytoolbox.com/damaged_zip_file.html">damage zip</a>. The utility worked out my issue within seconds and totally free of charge as I kept in mind.