11-27-2009 8:29 PM
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
12-01-2009 6:05 AM
Hi,
Please go through the link below:
http://wiki.sdn.sap.com/wiki/display/ABAP/Workingwithfiles
Hope it helps
Regards
Mansi
11-28-2009 2:51 AM
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
11-28-2009 2:55 AM
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.
11-28-2009 4:41 PM
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 ?
11-28-2009 5:03 PM
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.
11-28-2009 6:27 PM
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....
11-30-2009 4:12 PM
12-01-2009 6:05 AM
Hi,
Please go through the link below:
http://wiki.sdn.sap.com/wiki/display/ABAP/Workingwithfiles
Hope it helps
Regards
Mansi
12-02-2009 10:11 PM
Zip the internal table data and write to Application server....anybody did this?
Thanks,
Fract