October 17


Substring a Packed numeric in a Logical File

By NickLitten

October 17, 2021

Packed, File, Logical, Numeric, SST, Substring

How to Substring a Packed numeric in a Logical File

So – you have a Physical file and you want to create a logical with substrings of file data or maybe concatenation of the same data. “That’s easy” I can hear you think… but… but… what if you need to do this with a substring a number – maybe a Date? And what if that number is a Packed Numeric?

“Uhoh, you can’t substring Packed Numerics” I can also hear you think

1 – Stop thinking so loud


2 – Let’s Substring this Packed numeric Easily

You cannot substring a packed numeric but if you simply over-ride the numeric definition to ZONED the it can be Sub stringed easily. Yes that’s right 🙂

Take this Physical File for example:

A          R RCDFORMAT
A            FIRSTNAME      50A       TEXT('MY FIRST NAME')
A            SURNAME        50A       TEXT('SURNAME')
A            AGE            3P 0      TEXT('AGE')
A            SHOESIZE       3S 0      TEXT('SHOE SIZE')

Now this can easily be broken down by Logical like this:

A          R RCDFORMAT                 PFILE(CUSTPF)      
A            FIRSTNAME                                    
A            SURNAME    
 ** Now let's define the same field but simply over-ride its a SIGNED(ZONED)                                  
A            AGE             S      
 ** Now we can substring thtese values
A            AGE1               I      SST(AGE 1 1)       
A            AGE2               I      SST(AGE 2 1)       
A            AGE3               I      SST(AGE 3 1)       
A            SHOESIZE                                     
A          K AGE                                          

Sometimes the easy tricks are the cool little tricks…

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips