Hardware compression has been available on the iSeries 400 for some time. But did you know that software compression is also available, and it's relatively easy to use?
IBM offers two algorithms: simple terse (whatever that is) and IBM LZ1. The latter is IBM's patented implementation of the Lempel-Ziv algorithm, used in WinZip and pkzip. In my experience, this algorithm is much the better of the two, so I'll cover LZ1 here.
To use compression, you need to provide the address and length of the source and result strings, and the algorithm number. (1=Simple Terse, 2=IBM LZ1.) These details are placed in a data structure, known as a template. The address of the template is then passed to the MI builtin function.
The compress function will populate the result field, and place the length of the compressed string in CompressLen. In this example, CompressLen = 65. That's an excellent compression ratio, but this a rather contrived example!
Decompression is similar. Note that we do not need to provide the source length or algorithm number. The decompress function can determine these from the compressed string.
The decompress function will populate the result field, and place the length of the decompressed string in decompresslen. You must be sure to provide a long enough result field. Often you will know the original string length, so this will not be a problem.
So when is compression useful? Recently
Requires Free Membership to View
Register today to access targeted resources from our editorial writers and independent industry experts including news, tips, and advice to help you do your job more efficiently and effectively. Stay informed on the hottest topics and biggest challenges faced by IT professionals working with iSeries products and services.
Compression example:
* Prototype for MI builtin function:
D Compress pr Extproc('_CPRDATA')
D RcvrPtr * Value
* Compression template:
D Rcvr ds
D SourceLen 10i 0 Inz(%Size(Source))
D ResultLen 10i 0 Inz(%Size(Result))
D CompressLen 10i 0 Inz(0)
D Algorithm 5i 0 Inz(2)
D 18 Inz(*LOVAL)
D SourcePtr * Inz(%Addr(Source))
D ResultPtr * Inz(%Addr(Result))
D Source s 2400 Inz(*ALL'The cat sat on the mat. ')
D Result s 2400
C CallP Compress (%Addr(Rcvr))
Decompression example:
* Prototype for MI builtin function:
D Decompress pr Extproc('_DCPDATA')
D RcvrPtr * Value
* Decompression template:
D Rcvr ds
D 4 Inz(*LOVAL)
D ResultLen 10i 0 Inz(%Size(Result))
D DecompressLen 10i 0 Inz(0)
D 20 Inz(*LOVAL)
D SourcePtr * Inz(%Addr(Source))
D ResultPtr * Inz(%Addr(Result))
D Source s 2400
D Result s 2400
C CallP Decompress (%Addr(Rcvr))
================================== MORE INFORMATION ON THIS TOPIC ==================================
The Best Web Links: tips, tutorials and more.
Ask your programming questions--or help out your peers by answering them--in our live discussion forums.
Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.
This was first published in January 2002