January 2006 Technical Tip - Easytrieve: Data Compression with Packed Decimal

Introduction

I recently had the opportunity to teach an Easytrieve Plus course to some COBOL programmers. Those in attendance were confused by my usage of the term “packed” as in “packed decimal”. These particular programmers had little understanding of the packed decimal data storage format: what they call “packed” I would call “compressed” or even “zipped”. Their very old COBOL programs were using the packed decimal storage format as a way of compressing files for smaller storage space. Their COBOL code would look something like this:

     05  IN-FLDS-1-THRU-3  PIC 9(11) COMP-3.


     05  WS-FLDS-1-THRU-3  PIC 9(11).
     05  FILLER REDEFINES WS-FLDS-1-THRU-3.
         10  WS-FLD1       PIC 9(3).
         10  WS-FLD2       PIC 9(4).
         10  WS-FLD3       PIC 9(4).


*    UNCOMPRESS
     MOVE IN-FLDS-1-THRU-3 TO WS-FLDS-1-THRU-3.

Of course, packing numeric fields singularly results in smaller files. But treating multiple adjacent numeric fields as a single number and packing that number results in fewer sign bits and therefore even smaller files. Of course, there are much better ways to accomplish data compression, but it probably made sense at the time!

Description of the input data

01 – 10  Description
11 – 13  California unit sales
14 – 16  Illinois unit sales
17 – 19  Utah unit sales
20 – 22  Wisconsin unit sales
23 – 25  Beginning inventory
26 – 28  Purchases
29 – 31  Ending inventory
32 – 35  Cost each (99V99)
36 – 39  Sell price each (99V99)

Input ("unpacked") data

GIZMOS    02003002002001709902312252999
WIDGETS   01501001000202203401900110025
JUNQUE    02501501501803005201001550339
Download file here.

Easytrieve Plus program to "pack" the data

//* JOBCARD HERE
//****************************************************      
//* PERMISSIVE DELETE OF PRE-EXISTING DATASET IF ANY *      
//****************************************************      
//STEP005 EXEC PGM=IEFBR14                                  
//DEL1     DD DSN=FIN9ED0.COMPRESS,DISP=(MOD,DELETE),       
//            UNIT=SYSDA,SPACE=(TRK,(1,1),RLSE)             
//******************************************************    
//* CREATE A COMPRESSED VERSION OF THE COGS FILE BY    *    
//* PACKING MULTIPLE FIELDS INTO ONE FIELD.            *    
//******************************************************    
//STEP010 EXEC PGM=EZTPA00                                  
//STEPLIB  DD DSN=BICS.EASYPLUS,DISP=SHR                    
//COGSIN   DD DSN=FIN9ED0.EZ.DATA(COGS),DISP=SHR            
//COGSOUT  DD DSN=FIN9ED0.COMPRESS,DISP=(NEW,CATLG,DELETE), 
//            UNIT=SYSDA,SPACE=(TRK,(1,1),RLSE)             
//SYSPRINT DD SYSOUT=*                                      
//SYSIN    DD *                                             
FILE COGSIN                       
   I-DESC         1  10  A        
   I-CA-IL-UT-WI 11  12  N  0     
   I-BE-PU-QO    23   9  N  0     
   I-CO-SE       32   8  N  0     
                                  
FILE COGSOUT FB(27 0)             
   O-DESC         1  10  A        
   O-CA-IL-UT-WI 11   7  P  0     
   O-BE-PU-QO    18   5  P  0     
   O-CO-SE       23   5  P  0     
                                  
JOB INPUT COGSIN                  
   O-DESC        = I-DESC         
   O-CA-IL-UT-WI = I-CA-IL-UT-WI  
   O-BE-PU-QO    = I-BE-PU-QO     
   O-CO-SE       = I-CO-SE        
   PUT COGSOUT                    
Download source here.

Output ("packed") data

EDIT       FIN9ED0.COMPRESS                                Columns 00001 00027 
Command ===>                                                  Scroll ===> HALF 
****** ***************************** Top of Data ******************************
                                                                               
                                                                               
------------------------------------------------------------------------------ 
000001 GIZMOS            ør    êræ                                             
       CCEDDE444402002000790302599                                             
       7994620000003002C1092C1229C                                             
------------------------------------------------------------------------------ 
000002 WIDGETS              æ    *                                             
       ECCCCEE44401001020230900105                                             
       6947532000051000C2041C0102C                                             
------------------------------------------------------------------------------ 
000003 JUNQUE       &  ð  ê    & æ                                             
       DEDDEC444402051080050001539                                             
       1458450000051051C3021C0503C                                             
------------------------------------------------------------------------------ 
****** **************************** Bottom of Data ****************************

Easytrieve Plus program to "unpack" the data

//* JOBCARD HERE
//************************************************         
//* READ COMPRESSED COGS FILE AND CREATE REPORT. *         
//************************************************         
//STEP010 EXEC PGM=EZTPA00                                 
//STEPLIB  DD DSN=BICS.EASYPLUS,DISP=SHR                   
//COGSIN   DD DSN=FIN9ED0.COMPRESS,DISP=SHR                
//MYLIST   DD SYSOUT=*                                     
//SYSPRINT DD SYSOUT=*                                     
//SYSIN    DD *                                            
FILE COGSIN                                                
   I-DESC         1  10  A                HEADING ('DESC') 
   I-CA-IL-UT-WI 11   7  P  0                              
   I-BE-PU-QO    18   5  P  0                              
   I-CO-SE       23   5  P  0                              
                                                           
FILE MYLIST PRINTER                                        
                                                           
* WORKING-STORAGE SECTION                                    
   W-CA-IL-UT-WI  W  12  N  0                                
     W-CALIF   W-CA-IL-UT-WI     3  N  0  HEADING('CALIF')   
     W-ILL     W-CA-IL-UT-WI +3  3  N  0  HEADING('ILL')     
     W-UTAH    W-CA-IL-UT-WI +6  3  N  0  HEADING('UTAH')    
     W-WISC    W-CA-IL-UT-WI +9  3  N  0  HEADING('WISC')    
   W-BE-PU-QO     W   9  N  0                                
     W-BEGIN   W-BE-PU-QO        3  N  0  HEADING('BEGIN')   
     W-PURCH   W-BE-PU-QO    +3  3  N  0  HEADING('PURCH')   
     W-QOH     W-BE-PU-QO    +6  3  N  0  HEADING('QOH')     
   W-CO-SE        W   8  N  0                                
     W-COST    W-CO-SE           4  N  2  HEADING('COST') +  
                                          MASK ('$$.99')     
     W-SELL    W-CO-SE       +4  4  N  2  HEADING('SELL') +  
                                          MASK ('$$.99')     
                                                             
JOB INPUT COGSIN                                             
                                                             
*  UNCOMPRESS                                                
     W-CA-IL-UT-WI = I-CA-IL-UT-WI                           
     W-BE-PU-QO    = I-BE-PU-QO                    
     W-CO-SE       = I-CO-SE                       
                                                   
   PRINT MYREPORT                                  
                                                   
REPORT MYREPORT PRINTER MYLIST LINESIZE 80         
   TITLE 'COGS DATA UNCOMPRESSED'                  
   LINE I-DESC   W-CALIF  W-ILL  W-UTAH  W-WISC  + 
        W-BEGIN  W-PURCH  W-QOH  W-COST  W-SELL    
Download source here.

Report using "unpacked" data

SDSF OUTPUT DISPLAY FIN9ED0X JOB07808  DSID   102 LINE 0       COLUMNS 02- 81  
 COMMAND INPUT ===>                                            SCROLL ===> HALF 
********************************* TOP OF DATA **********************************
11/01/05                     COGS DATA UNCOMPRESSED                 PAGE      1 
                                                                                
   DESC      CALIF   ILL    UTAH   WISC   BEGIN   PURCH   QOH     COST     SELL 
GIZMOS        20      30     20     20     17      99      23    $12.25   $29.99
WIDGETS       15      10     10      2     22      34      19      $.11     $.25
JUNQUE        25      15     15     18     30      52      10     $1.55    $3.39
******************************** BOTTOM OF DATA ********************************

If you want to know more about Easytrieve Plus or COBOL, please give us a call! You can always count on Caliber Data Training for top quality education.


Go to the articles index. Written by Bill Qualls. Copyright © 2006 by Caliber Data Training 800.938.1222