Data compression on the iSeries 400

Data compression on the iSeries 400

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.

    By submitting your registration information to Search400.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of Search400.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

I needed to store an audit trail of seven days' worth of data (approximately 70000 records) as received via MQ Series. The data arrived as one long string, 10800 bytes long. That's an uncompressed length of over 700MB. The data contained lots of blanks and zeroes, and was an ideal candidate for compression. By storing the compressed data in a variable length field in the audit file, I was able to reduce the storage requirements by a factor of 15. Very useful and quite straightforward!


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

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.