Skip to Content
author's profile photo Former Member
Former Member

How to read the content of ZIP folder from presentation sever throw ABAP program?

Hi Dear All,

How to read the content of ZIP folder from presentation sever throw ABAP program?

I have tried read ZIP files (.ZIP and .RAR) formatted files through Class : 'CL_GUI_FRONTEND_SERVICES' .

I have go the file name format and size.

My question is: How to read the data from 'ABC.ZIP'.?

eg: i have stored 3 txt format file (1.txt,2.txt and 3.txt ) and one Image '.JPEG' format file to ABC.ZIP

how get which are the data available in ABC.ZIP?

is there any FM,BAPI or and class available in SAP?

Regards,

Akshath/Ali

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Jul 26, 2012 at 12:11 PM

    Hello,

    SAP has provided a CL_ABAP_ZIP to handle zip files. You can use this to achieve your requirement, please refer to the code snippet below:

       DATA: gt_raw_data       TYPE tab_raw512,
    gv_fil_len TYPE i,
    gv_zip_xstring TYPE xstring,
    go_zip TYPE REF TO cl_abap_zip,
    gwa_zipped_files TYPE cl_abap_zip=>t_file.

    * Upload the ZIP file in 'BIN' format
    cl_gui_frontend_services=>gui_upload(
    EXPORTING
    filename = `C:\Users\suhas.saha\Desktop\test.zip`
    filetype = 'BIN'
    IMPORTING
    filelength = gv_fil_len
    CHANGING
    data_tab = gt_raw_data
    EXCEPTIONS
    file_open_error = 1
    file_read_error = 2
    no_batch = 3
    gui_refuse_filetransfer = 4
    invalid_type = 5
    no_authority = 6
    unknown_error = 7
    bad_data_format = 8
    header_not_allowed = 9
    separator_not_allowed = 10
    header_too_long = 11
    unknown_dp_error = 12
    access_denied = 13
    dp_out_of_memory = 14
    disk_full = 15
    dp_timeout = 16
    not_supported_by_gui = 17
    error_no_gui = 18
    OTHERS = 19
    ).
    IF sy-subrc = 0.
    * Convert the RAW data from the zip file to a binary stream
    CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
    EXPORTING
    input_length = gv_fil_len
    IMPORTING
    buffer = gv_zip_xstring
    TABLES
    binary_tab = gt_raw_data
    EXCEPTIONS
    failed = 1
    OTHERS = 2.
    IF sy-subrc = 0.
    CREATE OBJECT go_zip. "Create the ZIP utility object

    * Load the zip file into the Zip Utility
    go_zip->load(
    EXPORTING
    zip = gv_zip_xstring
    EXCEPTIONS
    zip_parse_error = 1
    OTHERS = 2
    ).
    IF sy-subrc = 0.
    * Get the details of the zipped files
    LOOP AT go_zip->files INTO gwa_zipped_files.
    WRITE: / gwa_zipped_files-name, gwa_zipped_files-size.
    ENDLOOP.
    ELSE.
    "Error handling for Zip file load
    ENDIF.
    ELSE.
    "Error handling for RAW to binary stream conversion
    ENDIF.
    ELSE.
    "Error handling for file upload
    ENDIF.

    You need to check if this code works on other zip formats viz., .rar, .7z etc. 😊

    BR,

    Suhas

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.