May 2005 Technical Tip Easytrieve: A Cautionary Note on the use of Packed Decimal Fields

Last month I had a former student tell me that Easytrieve should not be used on packed decimal fields because it treated all packed decimal fields as unsigned. I told her that this was not the case and set about to write a short Easytrieve program to verify this. The results surprised me!

What I discovered was that if a decimal specification is omitted, the sign is indeed lost! The following program will serve to demonstrate:

//* JOBCARD HERE
//STEP010 EXEC PGM=EZTPA00                                                      
//***************************************************************               
//*  IF YOU LEAVE OFF DECIMAL SPECIFICATION YOU LOSE THE SIGN!  *               
//***************************************************************               
//MYINPUT  DD *                                                                 
12345        UNSIGNED                                                           
1234E        POSITIVE                                                           
1234N        NEGATIVE                                                           
//MYOUTPUT DD DSN=&&PACKED,DISP=(NEW,PASS),UNIT=SYSDA,                          
//            SPACE=(TRK,(1,1),RLSE),                                           
//            DCB=(RECFM=FB,LRECL=10,BLKSIZE=0)                                 
//SYSPRINT DD SYSOUT=*                                                          
//SYSIN    DD *                                                                 
FILE MYINPUT                                                                    
ZONED     1  5  N  0                                                            
                                                                                
FILE MYOUTPUT                                                                   
PACKED1   1  3  P  0                                                            
PACKED2   5  3  P                                                               
                                                                                
JOB INPUT MYINPUT                                                               
   PACKED1 = ZONED                                                              
   PACKED2 = ZONED                                                              
   PUT MYOUTPUT                                                                 
                                                                                
//STEP020 EXEC PGM=IDCAMS                                                       
//SYSIN    DD *                                                                 
  PRINT INFILE(MYINPUT) HEX                                                     
//SYSPRINT DD SYSOUT=*                                                          
//MYINPUT  DD DSN=&&PACKED,DISP=(OLD,DELETE)                                    
//

The IDCAMS dump follows. You can see the sign in the first field but not in the second:

RECORD SEQUENCE NUMBER - 1
 12345C4012345F404040
 
RECORD SEQUENCE NUMBER - 2
 12345C4012345F404040
 
RECORD SEQUENCE NUMBER - 3
 12345D4012345F404040

The moral of this story is always include the decimal specification for packed decimal fields.

We hope you will consider Caliber Data Training when searching for Easytrieve training.


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