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

SAP ABAP - Nested ZIP files

Former Member
0 Likes
2,496

Hi, My requirement is to zip a file and then zip that into another folder with few more files and place it on App Server. I could do the first zip, but couldn't figure out how to do nested zip. Please help if anyone has done it before.

Example:

1. Zip files A, B, C into Zipper1.zip

2. Zip Zipper1.zip, D, E, F into Zipper2.zip

3. Write Zipper2.zip onto App Server

Thanks,
Murali.

1 ACCEPTED SOLUTION
Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
2,188

You can v_zip->add( ) any xstring data (content) to ZIP. Even the v_zipcontent which you got from v_zip->save( ). Just make sure you do not use same cl_abap_zip object instance (basic OOP).

-- Tomas --

You can v_zip->add( ) any xstring data (content) to ZIP. Even the v_zipcontent which you got from v_zip->save( ). Just make sure you do not use same cl_abap_zip object instance (basic OOP).

9 REPLIES 9
Read only

TMSingh_SAP
Participant
0 Likes
2,188

Hi,

Not sure why 2 times zipped. I think the logic for first zip will work with files only and the same can not be used to zip - zipped file along with other file.

Technically, you are doing zip for A,B,C,D,E,F..then why not single zip for all these?

Thanks,

Mohan

Read only

0 Likes
2,188

Sorry No, I am not doing all the files in a single zip.

My requirement for 3rd party is to generate a zip file which contains "1 zip file with n number of files + some more files".

This is the requirement. If I have to zip all in one zip then I could have done it.

Thanks,

Murali.

Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
2,188

What is there to figure out? Second level of archiving is same like first or any other.

Where exactly you have problem?

-- Tomas --
Read only

matt
Active Contributor
0 Likes
2,188

Perhaps you could share how you did the first zip.

Read only

Former Member
0 Likes
2,188

I will share how to zip(including nested zip) once I am done with my development.

Thanks,
Murali

Read only

matt
Active Contributor
0 Likes
2,188

"I will share how to zip(including nested zip) once I am done with my development."

You say you've done the first zip. The reason I wanted to see that was that it might give a hint as to why you're finding doing the second zip difficult. A Tomas Buryanek points out - what is there to figure out?

Read only

Former Member
0 Likes
2,188

Here is the code for the first zip. It generated Test.zip on the Application Server.

*>>>>>>

REPORT ztest_zip.

PARAMETERS: p_file TYPE localfile.

TYPES: BEGIN OF type_ekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
END OF type_ekpo.

TYPES: type_t_ekpo TYPE STANDARD TABLE OF type_ekpo,
type_t_rec TYPE STANDARD TABLE OF sdokcntasc.

DATA: t_ekpo TYPE type_t_ekpo,
t_rec TYPE type_t_rec,
t_zipdata TYPE TABLE OF x255,
w_ekpo TYPE type_ekpo,
w_rec TYPE sdokcntasc,
w_zipdata TYPE x255.

DATA: v_date TYPE sy-datum,
v_zipcontent TYPE xstring,
v_zipcontent1 TYPE xstring,
v_zipfile TYPE string VALUE 'Test.zip',
v_content TYPE xstring,
v_xstr TYPE xstring,
v_name TYPE string,
v_filelength TYPE i,
v_zip TYPE REF TO cl_abap_zip.

v_date = sy-datum - 7.

SELECT ebeln
ebelp
FROM ekpo
INTO TABLE t_ekpo
WHERE aedat >= v_date.

CLEAR: w_rec.
CONCATENATE 'Purchase Order#'
'Item #'
INTO w_rec-line
SEPARATED BY ','.
APPEND w_rec TO t_rec.

CLEAR w_rec.

LOOP AT t_ekpo INTO w_ekpo.
CONCATENATE w_ekpo-ebeln
w_ekpo-ebelp
INTO w_rec-line
SEPARATED BY ','.
APPEND w_rec TO t_rec.
CLEAR w_rec.
ENDLOOP.

CLEAR v_content.
CREATE OBJECT v_zip.
CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'
IMPORTING
buffer = v_xstr
TABLES
text_tab = t_rec
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc = 0.
REFRESH: t_rec.
FREE: t_rec.
ENDIF.

v_name = 'Test.csv'.
v_zip->add( name = v_name content = v_xstr ).
v_zipcontent = v_zip->save( ).

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = v_zipcontent
IMPORTING
output_length = v_filelength
TABLES
binary_tab = t_zipdata.

CONCATENATE p_file
v_zipfile
INTO v_zipfile
SEPARATED BY '/'.
OPEN DATASET v_zipfile FOR OUTPUT IN BINARY MODE.
LOOP AT t_zipdata INTO w_zipdata.
TRANSFER w_zipdata TO v_zipfile.
ENDLOOP.
CLOSE DATASET v_zipfile.

*<<<<<<

Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
2,189

You can v_zip->add( ) any xstring data (content) to ZIP. Even the v_zipcontent which you got from v_zip->save( ). Just make sure you do not use same cl_abap_zip object instance (basic OOP).

-- Tomas --
Read only

2,188

Thank you Tomas. It is resolved.