How does packed decimal work?


Can someone explain logically how packed data is unpacked?

I have an example - i think number 2984 is packed as the following ascii values.. (i got from comparing 2 files)

2     182     19     45     140

If I made a mistake above, can you 'pack' 2984, as hex or ascii, and explain how you did it?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xeniumAuthor Commented:
this is quite easy.

take a number
this is stored as

is stored as

The space required is always Int( positions / 2) + 1

ie to hold 11 degits is

Int(11/2) = 5 + 1 =6

so as you can se in the example to store 5 is int (5/2) = 2 + 1 = 3
xeniumAuthor Commented:
Hi Dave,
I'm a little confused, and novice in this area. Can you clarify:

Is plus always F and minus always D?

What do you mean by stored as:

What is this as a 3 byte ascii string, or a hex string? I need to read this on a PC.
Can you do same for my example 2984.

CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

The F is wlways positive and d -ve.

for your example

2984 - packed fields always use a odd number of positions hence yours would be be stored as
02984 - this is represented as


the 0 become the upper part of the first byte
the 2 becomes the second part of the first byte
the 9 become the firstpart of the second byte
the 8 becomes the second part of the second byte
the 4 become the first part of the last byte
and F becomes the last part of the last byte as it is +ve.

Is that any clearer.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The conversion that you are doing is never easy for the following reasons.

1)      the as 400 has a coded page for each file
2)      this could be say 37 for USA or 285 for UK so if your download is not binary the packed number (stored as Hex) could be converted differently
3)      if you are used SQL server then you are running Microsoft – which has ODBC. The 400 is ODBC and ADODB compliant. These routines have conversion built in, they do not run as fast as ftp but are easy to code. I would look at that.

the drivers come on the AS/400 client acces pc. This needs to be installed on the pc doing the download.
If that is not an option then they also contain converiosn routines that an be coded into VB, c##, etc  that will perform the conversions
xeniumAuthor Commented:
HI Dave, thanks for explanation.
Actually the data is from mainframe, but no topic (i think ) so i guessed an AS400 expert would be able to answer the logic easily enough - thanks!

Currently unpacking is done mainframe side, i'm just exploring other options due to human resource limitation on the mainframe side.


xeniumAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IBM System i

From novice to tech pro — start learning today.