View Full Version : Zoned numeric vs packed
06-20-2002, 06:44 AM
All HLL programs move decimal values to a packed area. This is because all internal moves and calculations are performed on packed values. Dave
06-20-2002, 07:02 AM
Why? The simple answer is: "Because". And now, on to the more complicated answer: By default, decimal numeric variables in RPG are stored in packed decimal format, even if they are defined in zoned format in an external record. Note that a variable may be defined in several different record formats, and each may be defined using a different numeric format. That is, packed in one record, zoned in another, and possibly binary decimal in a third. RPG resolves any potential conflict by just defaulting to packed decimal format internally. If you want the variable to be defined in a different format, you have a couple of alternatives. You could explicitly define the variable as a standalone field with an explicit format. But you'd then have to change the internal definition to match any changes to the field in the record. Or, you could define the field as a data structure subfield, in which case, the variable would be implicitly defined as zoned format. You can make this easier by coding an externally described data structure from the record.
06-20-2002, 09:42 AM
> And now, on to the more complicated answer: By default, decimal numeric variables in RPG are stored in packed decimal format, Hans, Could you, in 100 words or less, explain why packed is used? IIRC, the 36 used zoned to perform arithmetic operations; I assume the 38 used packed. To my human thinking, I would think zoned would be the way to do arithmetic. Is it something simple like the chipset involved in the math calcs that lends itself to working best on packed? Bill
06-20-2002, 10:41 AM
Do you remember a time when memory and CPU time was expensive? Packed was considered preferable to zoned since packed takes almost half the storage, and arithmetic operations on packed decimal generally run faster. Furthermore, packed decimal arithmetic has practically the exact same semantics as zoned decimal, and so programs could be ported from S/34 to S/38 relatively easily. (The 36 came after the 38.) BTW, in all computers these days (and in at least the past 30 years), arithmetic is fastest in binary format. (That is, integer and unsigned in RPG IV.)
06-20-2002, 12:32 PM
Why doesn't RPG default to the faster integer format?
06-21-2002, 04:43 AM
Compatibility. Plus, decimal numerics have a much greater range than integer/unsigned. 31 digits versus 19 or 20 digits. Also, don't forget that in most RPG applications, performance of the arithmetic is overwhelmed by the performance of the I/O operations.
06-21-2002, 05:47 AM
Hans Boldt wrote: Also, don't forget that in most RPG applications, performance of the arithmetic is overwhelmed by the performance of the I/O operations. This should not be the case. TTBOMK, the ALU should handle all mathmatical operations while the I/O processor handles I/O. Neither should overly burden the CPU. Dave
06-21-2002, 06:04 AM
Huh? Don't forget that I/O performance is limited by slow hardware, such as rotating disk platters and swinging actuators. Or network delays. Or waiting for user input on a terminal. As a result, I/O is normally a couple of orders of magnitude slower than CPU bound code.
06-21-2002, 06:15 AM
The point Hans was trying to make was that the arithmetic operations are not the bottleneck in RPG applications, so relying on slower operations for math isn't that big a deal for most applications. I/O is the bottleneck in most database-intensive applications, to the extent that inefficiencies in I/O will make inefficiencies in arithmetic seem trivial.
06-21-2002, 07:00 AM
The real point is that hard drives operate on the order of milliseconds (1/1000th) and RAM operates on the order of nanoseconds (1/billionth). So, RAM is roughly a million times faster. Oh sure, the system will find some hard drive data in a RAM cache, but certainly you can't cache 500GB! Chris
06-21-2002, 07:00 AM
Can someone tell me why is it that when you define a field in a DDS described file as zoned decimal (S in column 35) and use that field in a RPG IV program, the RPG compiler thinks it's packed? Please see my examples below. I would appreciate any information anyone has on this. Michael Soucy
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.