Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 11577

Re: Store file in unix server in ZIP format

$
0
0

Try below code

 

Steps:

  • Read file from the application server.
  • Add file to a Zip Folder.
  • Create a Zip File.
  • Convert xstring to the binary format.
  • Write file to the application server.

The sample code is :

 

 

DATA: lt_tab            TYPE SWXMLCONT,
ls_tab            TYPE X255.

DATA: lv_zip_content     TYPE xstring ,
lv_file(255)       VALUE '\\CTSINTBMVSTR1\sapmnt\trans\test_file',
lv_zip_file(255)   VALUE '\\CTSINTBMVSTR1\sapmnt\trans\test.zip',
lv_file_length     TYPE i ,
lv_content         TYPE xstring,
l_or_zip           TYPE REF TO cl_abap_zip.

CREATE OBJECT l_or_zip.

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

*Add a File to a Zip Folder
l_or_zip->add( name = 'test_file' content = lv_content ).

CLEAR lv_content .

*Create a Zip File
lv_zip_content   = l_or_zip->save( ).

* Convert 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_tab.

*Download file to the application server
OPEN DATASET lv_zip_file FOR OUTPUT IN BINARY MODE.
LOOP AT lt_tab INTO ls_tab.
TRANSFER ls_tab TO lv_zip_file.
ENDLOOP.
CLOSE DATASET lv_zip_file.


Viewing all articles
Browse latest Browse all 11577

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>