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.

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

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:

GZIP Method Description
COMPRESS_TEXT Compression of Text in GZIP Format
DECOMPRESS_TEXT Decompression of Zipped Text
COMPRESS_BINARY Compression of Binary Data in GZIP Format
DECOMPRESS_BINARYDecompression of Zipped Binary Data

SAP and SAP logo are registered trademarks of SAP AG. Sap4tech.net is not associated with SAP AG.

We have made every effort to make sure provide relevant search results, use the content on this site at your own risk.

We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.