Skip to Content
0
Former Member
Nov 27, 2009 at 08:29 PM

Zip the file and download onto Appication Server

1030 Views

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