Skip to Content
avatar image
Former Member

How to read a .ZIP file available in the SAP application server


Hi All,

I went through some of the threads related to reading .zip files at the application server and tried doing the same through ABAP code but it was futile.

I can see the .zip file at the said path in the application server.This .zip file is suppose to contain .txt format files.

Following is my piece of code :

DATA file_name TYPE string.
DATA zipped_data TYPE xstring.
DATA unzipped_data TYPE xstring.
DATA text_data TYPE string.

DATA zip TYPE REF TO cl_abap_zip.

OPEN DATASET file_name FOR INPUT IN BINARY MODE FILTER 'uncompress'.

READ DATASET file_name INTO zipped_data.

CREATE OBJECT zip.
zip->load( zipped_data ).
CALL METHOD zip->GET
EXPORTING
* NAME = zipped_data
INDEX = lv_index
IMPORTING
CONTENT = unzipped_data
EXCEPTIONS
ZIP_INDEX_ERROR = 1
ZIP_DECOMPRESSION_ERROR = 2
others = 3.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

While I try to read the file into zipped_data i fetch nothing.

Please throw some light into this .

Quick help will be rewarded.

Regards

Pratibha

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Sep 03, 2015 at 07:50 AM

    Hi,

    DATA lo_zipobj TYPE REF TO cl_abap_zip.

    CREATE OBJECT lo_zipobj. " Instances of class

    CALL METHOD lo_zipobj->load

    EXPORTING

    zip = lv_filecontent. " lv_filecontent is ZIP File Content of type XSTRING

    *Attribute FILES will have number of files in the ZIP.

    *Using Get file Method of class CL_ABAP_ZIP get the file content from ZIP and pass it to method READ as below.

    LOOP AT lo_zipobj->files INTO ls_files.

    CALL METHOD lo_zipobj->get

    EXPORTING

    name = ls_files-name

    IMPORTING

    content = lv_xstring.

    CALL METHOD cl_abap_conv_in_ce=>create

    EXPORTING

    input = lv_xstring

    encoding = 'UTF-8'

    replacement = '?'

    ignore_cerr = abap_true

    RECEIVING

    conv = l_addr.

    CALL METHOD l_addr->read

    IMPORTING

    data = l_string.

    ENDLOOP.

    Add comment
    10|10000 characters needed characters exceeded