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

Advantages of using comp-3 variables


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
garv_fundu
Warnings : 1

New User


Joined: 02 Nov 2006
Posts: 22

PostPosted: Mon Dec 11, 2006 2:28 pm
Reply with quote

Hi all,

Why exactly do we declare a variable as comp-3?

Is there any specific reason or advantage in doing so?

How can it serve the purpose if the variable is a counter variable?

Kindly clarify.

[/u]
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Mon Dec 11, 2006 3:20 pm
Reply with quote

Comp-3 is packed decimal, one of the mainframe native modes of arithmetic.
Declaring a variable as comp-3 (rather than display) allows arithmetic to be performed without conversation.
Actually, depending on what the counter is used for, comp might be more efficient.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Mon Dec 11, 2006 6:12 pm
Reply with quote

Whereas COMP may be more efficient than COMP-3, reading a COMP-3 value in hex is usually easier than reading COMP in hex. Human efficiency and ease may be more important than machine efficiency.
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: Mon Dec 11, 2006 8:59 pm
Reply with quote

Hello,

Would you believe conversion<g>?
Quote:
Declaring a variable as comp-3 (rather than display) allows arithmetic to be performed without conversation.



Quote:
Whereas COMP may be more efficient than COMP-3, reading a COMP-3 value in hex is usually easier than reading COMP in hex. Human efficiency and ease may be more important than machine efficiency.


With the mainframe, comes a set of "packed decimal" instructions. These are designed for "business arithmetic" - calculating and showing edited things like quantities and dollars. To get a value to a zz,zzz,zz9.99- field, the underlying assembler will prepare the edited value by first staging the value to a packed-decimal field (if it is not already in packed decimal format), then "edit"ing it into the target field.

While comp may save a bit of storage, it often will not use less machine cycles (which few care about these days. . .).
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Mon Dec 11, 2006 9:28 pm
Reply with quote

dick scherrer wrote:
Would you believe conversion<g>?

icon_rolleyes.gif Grumble, grumble icon_rolleyes.gif
Dang spellchecker, do what I mean, not what I say!.....grin......
Back to top
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 127
Location: kerala,india

PostPosted: Tue Dec 12, 2006 11:22 am
Reply with quote

Actually COMP 3 is used in case we had a signed number in comp3 each 2 digit will take 1 byte and the rightmost byte will contain only one digit plus the sign. So there is a reserved place for sign in COMP3 it will avoid the use of extra one byte for sign
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Tue Dec 12, 2006 3:35 pm
Reply with quote

cobolunni wrote:
there is a reserved place for sign in COMP3 it will avoid the use of extra one byte for sign

icon_lol.gif
COMP3 only needs an extra half byte for its sigh while COMP gets by with one bit.....
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: Tue Dec 12, 2006 11:54 pm
Reply with quote

Hmmmm. . . .


Quote:

COMP3 only needs an extra half byte for its sigh while COMP gets by with one bit...


Long sigh . . . . ?

Quote:


Grumble, grumble
Dang spellchecker, do what I mean, not what I say!.....grin......
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Tue Dec 12, 2006 11:59 pm
Reply with quote

dick scherrer wrote:
Long sigh . . . . ?
Well, they almost look the same....grin.... Heck with my fat fingers what do you expect icon_lol.gif

Quote:

Grumble, grumble
Dang spellchecker, do what I mean, not what I say!.....grin......
[/quote]
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 JCL with variables JCL & VSAM 1
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
No new posts JCL Variables JCL & VSAM 1
Search our Forums:

Back to Top