SAP File, Download Files from AL11;ABAP Program for Application server File;How to zip a file using ABAP

How to zip a file using ABAP in SAP with CL_ABAP_ZIP

How to zip a file using ABAP: The easy why it to use the standard class CL_ABAP_ZIP.
You will find following a ready to run program taking a file in input and converting it into Zip file in the Presentation server.

How to zip a file using ABAP ?

The different step to zip a file using ABAP is

  1. Uploading the file into memory
  2. Convert Binary to XString
  3. Create an instance of cl_abap_zip
  4. Add Binary File to
  5. Get ZIP File in Binary mode
  6. Convert XSTRING to String
  7. Download ZIP file on Presentation server

ABAP Program to Zip a file using ABAP

The output screen will look like :
How to Zip a file in abap

And the result is:
ZIP File in ABAP Result
The first Step is to upload the file and to convert it to XSTRING format.

Learn more about Conversion ABAP: between Binary, String, XString and Table

The second step is to create a new Zip file using CL_ABAP_ZIP->ADD method, then to save the Zip file.

Check also   SAP Alternative Unit of Measure for Material

ZIP file in ABAP with GZIP

An other ways to How to zip a file using ABAP is using GZIP/GUNZIP compression and decompression algorithm.
But if you want to go the hard way, you can implement your own GZIP/GUNZIP compress.
The advantage of GZIP/GUNZIP:

  • Independent of CPU type, operation system …
  • Works also on Data stream
  • Efficiency compress method
Check also   Best ABAP Ressources on the Web

Go and play with this GZIP/GUNZIP custom ABAP in this link

Other Methods  CL_ABAP_ZIP Class

The standard Class CL_ABAP_ZIP is the perfect fit to handle ZIP File using ABAP code.
In the previous example, we mostly used the methods ADD and SAVE.

Here the list of CL_ABAP_ZIP Methods:

ZIP Method Description
LOAD Loads a Zip File
SAVE Creates a Zip File
GET Reads a File from the Zip Folder
ADD Adds a File to a Zip Folder
DELETE Deletes a File in the Zip Folder
CRC32 Calculate a CRC32 Value
SPLICE Loads and Splits a Zip File

Other utility class for GZIP CL_ABAP_GZIP

CL_ABAP_GZIP Class for (De)Compression (GZIP) is other alternative if you want to use rather GZIP compression.

Here the list of the methods of CL_ABAP_GZIP are: