Application Development 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: 

Zip the file and download onto Appication Server

Former Member
0 Kudos

Hi,

I am trying to zip the file and download onto Application Server location. I couldn't find any difference in the file size, when i download the same data as .txt and .zip. The file size is same. Is it correct way what i am doing for zip the file and download on to Application server....

DATA: i_tab TYPE spfli OCCURS 0 WITH HEADER LINE,
l_fname TYPE string,
l_outrow(740).
DATA lo_zip TYPE REF TO cl_abap_zip.
DATA lt_zip_file TYPE cl_abap_zip=>t_files.
DATA ls_zip_file TYPE LINE OF cl_abap_zip=>t_files.
DATA: l_xstring TYPE xstring,
      zip TYPE xstring.
DATA: file_length TYPE i.
DATA: BEGIN OF it_data OCCURS 0,
        carrid(3),
        connid(4),
        countryfr(3),
        cityfrom(20),
        airpfrom(3),
        countryto(3),
      END OF it_data.

PARAMETERS: p_fname(128) TYPE c DEFAULT '\usr\sap\sys\down\testdown1.zip' OBLIGATORY.
l_fname = p_fname.

REFRESH i_tab. CLEAR i_tab.
SELECT * FROM spfli INTO TABLE i_tab.

REFRESH it_data.  CLEAR it_data.
LOOP AT i_tab.
  it_data-carrid = i_tab-carrid.
  it_data-connid = i_tab-connid.
  it_data-countryfr = i_tab-countryfr.
  it_data-cityfrom = i_tab-cityfrom.
  it_data-airpfrom = i_tab-airpfrom.
  it_data-countryto = i_tab-countryto.
  APPEND it_data.
  CLEAR it_data.
ENDLOOP.

OPEN DATASET l_fname FOR OUTPUT in text MODE encoding DEFAULT.
LOOP AT it_data.
  IF sy-subrc = 0.
    CONCATENATE it_data-carrid '|'
                it_data-connid '|'
                it_data-countryfr '|'
                it_data-cityfrom '|'
                it_data-airpfrom '|'
                it_data-countryto
             INTO l_outrow.

    TRANSFER l_outrow TO l_fname.
  ENDIF.
ENDLOOP.

CLOSE DATASET l_fname.
DESCRIBE FIELD l_fname LENGTH file_length in BYTE MODE.

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
  EXPORTING
    input_length = file_length
  IMPORTING
    buffer       = l_xstring
  TABLES
    binary_tab   = it_data.

CREATE OBJECT lo_zip.
CALL METHOD lo_zip->add
  EXPORTING
    name    = l_fname
    content = l_xstring.
CALL METHOD lo_zip->save
  RECEIVING
    zip = zip.

Thanks,

fract

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Please go through the link below:

http://wiki.sdn.sap.com/wiki/display/ABAP/Workingwithfiles

Hope it helps

Regards

Mansi

8 REPLIES 8

Former Member
0 Kudos

Check this code



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. 

Edited by: Harsh Bhalla on Nov 28, 2009 8:25 AM

Former Member
0 Kudos

your technique is also correct , you are not able to view the differnce in file size because the file size is very small and hence change is negligable. Hope you get it.

0 Kudos

Thanks for the reply. I have already seen the above code. Do we need to install Winzip or any other Zip software on Application Server ?

0 Kudos

Winzip will work.

Also, you will not be able to view the content of the zip file , untill and unless you have a software for opening it.

0 Kudos

Something wrong in my code. When i executed the above code the zip file size is bigger than original Text file.

I am opening the file in Text mode(OPEN DATASET l_fname FOR OUTPUT in text MODE encoding DEFAULT.), after transfering the internal table data to file i am calling FM 'SCMS_BINARY_TO_XSTRING'. After this i added this code.

CREATE OBJECT lo_zip.
CALL METHOD lo_zip->add
  EXPORTING
    name    = l_fname
    content = l_xstring.
CALL METHOD lo_zip->save
  RECEIVING
    zip = zip.

Please somebody look the above code and let me know any changes in it....

0 Kudos

Somebody please look the code....

Former Member
0 Kudos

Hi,

Please go through the link below:

http://wiki.sdn.sap.com/wiki/display/ABAP/Workingwithfiles

Hope it helps

Regards

Mansi

0 Kudos

Zip the internal table data and write to Application server....anybody did this?

Thanks,

Fract