SAP Virtual/Onsite Trainings

Tips Categories:

Contribute?

What's New?

What's Hot?

Web Dynpro for ABAP Tutorials


Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe  Unsubscribe 

Creating ZIP file on UNIX/Application server

By Jayshree Santosh Mahajan, Cognizant

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.

Output:

Execute the program. The test.zip will be created on the UNIX server.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image