Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
COMP and COMP-3: What is best and why?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: COMP and COMP-3: What is best and why?
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: 3158
Location: Tucson AZ

PostPosted: Wed Jan 31, 2007 1:20 pm    Post subject:
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    Post subject:
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Wed Jan 31, 2007 8:09 pm    Post subject:
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

Site Director


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

PostPosted: Wed Jan 31, 2007 10:46 pm    Post subject:
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    Post subject: COMP and COMP-3: What is best and why?
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    Post subject:
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    Post subject: I believe comp (binary) is better.
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

Site Director


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

PostPosted: Fri Feb 09, 2007 1:23 am    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm
No new posts Need help to populate date in COMP-3 ... chetanambi DFSORT/ICETOOL 3 Tue Jun 21, 2016 12:25 pm
No new posts comparing comp-3 and unpacked numbers juares castro COBOL Programming 3 Mon May 30, 2016 6:46 pm
No new posts SIGNED DECIMAL TO COMP-3 using cobol ... ram_vizag COBOL Programming 1 Tue Mar 01, 2016 11:32 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us