Google Search - Blog...........

ABAP - ZIP Files In Application Server Using FM SCMS_XSTRING_TO_BINARY.

report Z_ZIP_FILES_IN_APPSVR .

DATA: lt_data TYPE TABLE OF x255,
ls_data LIKE LINE OF lt_data.

DATA: lv_zip_content TYPE xstring ,
lv_dsn1(100) VALUE '/sap/NSP/sys/test.as',
lv_dsn2(100) VALUE '/sap/NSP/sys/test2.mxml',
lv_dsn3(100) VALUE '/sap/NSP/sys/testarchive.zip',
lv_file_length TYPE i ,
lv_content TYPE xstring,
lo_zip TYPE REF TO cl_abap_zip.

CREATE OBJECT lo_zip.

* Read the data as a string
clear lv_content .
OPEN DATASET lv_dsn1 FOR INPUT IN BINARY MODE.
READ DATASET lv_dsn1 INTO lv_content .
CLOSE DATASET lv_dsn1.

lo_zip->add( name = 'test.as' content = lv_content ).

clear lv_content .

OPEN DATASET lv_dsn2 FOR INPUT IN BINARY MODE.
READ DATASET lv_dsn2 INTO lv_content .
CLOSE DATASET lv_dsn2.

lo_zip->add( name = 'test2.mxml' content = lv_content ).

lv_zip_content = lo_zip->save( ).

* Conver the xstring content to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_zip_content
IMPORTING
output_length = lv_file_length
TABLES
binary_tab = lt_data.


OPEN DATASET lv_dsn3 FOR OUTPUT IN BINARY MODE.
LOOP AT lt_data INTO ls_data.
TRANSFER ls_data TO lv_dsn3.
ENDLOOP.
CLOSE DATASET lv_dsn3.



RETURN TO MAIN INDEX:

- Sample Programs On Uploading & Downloading Files.

- Sample Programs On HR ABAP.

- Sample Report Programs On ALV List/ Grid Display.

- Sample Programs On Selection Screen.

- Sample Programs On BDC.

.....Back To MAIN INDEX.


8 comments:

  1. I am facing one issue it would be great if you can help me

    I have .zip file on sap server and I want to download it on local disk. When I do it using GUI_DOWNLOAD I do get a zip file on local disk but when I try to unzipp I get error. If you have any information on this please let me knwo.
    Thanks in advance

    ReplyDelete
  2. Thanks for posting your sample program.

    ReplyDelete
  3. Thanks Rao. Your code really helped me.. Easy to understand and use.

    ReplyDelete
  4. I have been working with zip files for some years. And I have never met with such situation. Some days ago I lost whole my hundreds zip archives. I kept one's head and found - check repair zip file on a soft forum. It worked out my issue quite easy and I didn't spend the money!

    ReplyDelete
  5. This look pretty cool but after I downloaded testarchive.zip from AL11 to my PC, my ZIP program does not recognize the format....Does this create a real ZIP file ?

    ReplyDelete
  6. yes, it creates real zip file and able to download by using CG3Y

    ReplyDelete
  7. Yes, it creates real zip file and able to download by using CG3Y

    ReplyDelete
  8. Exist some interesting tools for solving problems. But one day I had very compound problem and used one application which assisted me easily and above it can help in different issues as well - the winzip wizard cannot open this file; it does not appear to be a valid archive.

    ReplyDelete