View previous topic :: View next topic
|
Author |
Message |
paramita.barman
New User
Joined: 12 Oct 2006 Posts: 18
|
|
|
|
Hi,
I have a salary field ---- say 30 dollars.
Use of COMP or COMP-3------- what is best and why? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Comp-3, IBM MFs deals with decimal arithmetic easily and at a native level. |
|
Back to top |
|
|
paramita.barman
New User
Joined: 12 Oct 2006 Posts: 18
|
|
|
|
Thanks William. |
|
Back to top |
|
|
tangentray
New User
Joined: 30 Dec 2006 Posts: 20 Location: Kolkata, India
|
|
|
|
Should Comp not be better than comp-3?
Comp is binary and comp 3 is packed decimal (BCD), all computations being done in binary ultimately I think comp-3 has to be converted to normal binary before aritmatic operations or is it that the system directly handles BCD? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
tangentray wrote: |
Should Comp not be better than comp-3?
Comp is binary and comp 3 is packed decimal (BCD), all computations being done in binary ultimately I think comp-3 has to be converted to normal binary before aritmatic operations or is it that the system directly handles BCD? |
No, for starters, this question was for a salary field and secondly, IBM MFs have native BCD instructions (machine level op codes). ZAP that |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
For basically ALL money fields and quantity fields (number of items, head counts, units produced, etc) COMP-3 should be used. Binary should be used only when binary is REALLY needed. Space savings is not much of an issue. The value 123456789 takes 5 bytes stored as comp-3 - it takes 4 bytes stored as binary.
The underlying assembler that provides comma and minus and dollar-sigh insertion must be done from packed-decimal fields, so if you use binary, the value has to be converted internally to comp-3 for character insertion to execute.
Also, (as Bill pointed out) the mainframe has hardware-level packed- decimal instructions that are designed for business arithmetic. |
|
Back to top |
|
|
sachin_star3 Warnings : 1 New User
Joined: 30 Sep 2006 Posts: 78 Location: pune
|
|
|
|
the comp is best for boudry levels
i.e example 1] for 4 character - comp requires 2bytes
where as comp-3 requires (4/2+1)= 3byte
2] for 8 chracter - comp requires 4 byte and comp-3 =5 byte
otherelse comp-3 is best
geerally comp-3 used for decimal point
and comp for binary
i this will help you
-sachin borase
pune |
|
Back to top |
|
|
vinit
New User
Joined: 31 Jul 2006 Posts: 8 Location: TCS, INDIA
|
|
|
|
as dick pointed out that in mainframes space is not an issue
and regarding the money field i have been using comp 3 only
so it is advised to do so |
|
Back to top |
|
|
warren
New User
Joined: 30 Aug 2006 Posts: 14 Location: Tampa, Florida
|
|
|
|
I believe it is much easier to make an error in packed decimal (comp-3). Most S0C7 data exceptions I have experienced, come from packed fields. I especially try to avoid packed fields in assembler, where there is more direct programmer control and therefore more chance of human error. The superior use of storage and faster processing (over packed) are really not necessary in today's world, as pointed out by others above; but it doesn't hurt, either. I don't know of any real advantage to using packed over binary. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Most 0c7's are NOT because of packed decimal but rather from some code that allowed invalid data to be placed in the field.
Better an 0c7 than an invalid answer. |
|
Back to top |
|
|
sachin_star3 Warnings : 1 New User
Joined: 30 Sep 2006 Posts: 78 Location: pune
|
|
|
|
comp-3 is best because salary cantain the decimal poind also
otherwise for round or for integer the comp is best
because comp takes less space |
|
Back to top |
|
|
|