IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

COMP and COMP-3: What is best and why?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
paramita.barman

New User


Joined: 12 Oct 2006
Posts: 18

PostPosted: Wed Jan 31, 2007 12:55 pm
Reply with quote

Hi,

I have a salary field ---- say 30 dollars.

Use of COMP or COMP-3------- what is best and why?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Jan 31, 2007 1:20 pm
Reply with quote

Comp-3, IBM MFs deals with decimal arithmetic easily and at a native level.
Back to top
View user's profile Send private message
paramita.barman

New User


Joined: 12 Oct 2006
Posts: 18

PostPosted: Wed Jan 31, 2007 2:19 pm
Reply with quote

Thanks William. icon_razz.gif
Back to top
View user's profile Send private message
tangentray

New User


Joined: 30 Dec 2006
Posts: 20
Location: Kolkata, India

PostPosted: Wed Jan 31, 2007 6:56 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Jan 31, 2007 8:09 pm
Reply with quote

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 icon_eek.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jan 31, 2007 10:46 pm
Reply with quote

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
View user's profile Send private message
sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Thu Feb 01, 2007 3:19 am
Reply with quote

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
View user's profile Send private message
vinit

New User


Joined: 31 Jul 2006
Posts: 8
Location: TCS, INDIA

PostPosted: Fri Feb 02, 2007 2:54 pm
Reply with quote

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
View user's profile Send private message
warren

New User


Joined: 30 Aug 2006
Posts: 14
Location: Tampa, Florida

PostPosted: Fri Feb 09, 2007 12:03 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Feb 09, 2007 1:23 am
Reply with quote

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
View user's profile Send private message
sachin_star3
Warnings : 1

New User


Joined: 30 Sep 2006
Posts: 78
Location: pune

PostPosted: Fri Feb 23, 2007 5:19 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
No new posts Cobol COMP-2 fields getting scrambled... Java & MQSeries 6
No new posts convert alphanumeric PIC X(02) to hex... COBOL Programming 3
Search our Forums:

Back to Top