How to calculate size of a COMP-3 and COMP variables



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

How to calculate size of a COMP-3 and COMP variables

Postby prashanthreddy » Sat Apr 05, 2008 4:29 pm

Hi All,

I would like to know how to calculate the Pic size of a COMP-3 and COMP variables.
My requirement is in my COBOL program one variable is declared as S9(9)V99 COMP-3.Now i would like to declare an equivalent alpha numeric for the COMP-3 variable. wat is the Pic size of alpha numeric ( X(??)) variable.
How to calculate the size of equivalent alpha numeric for COMP-3 and also COMP ??

Thanks in advance.

regards,
Prashanth
prashanthreddy
 
Posts: 8
Joined: Sat Jan 19, 2008 3:19 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How to calculate size of a COMP-3 and COMP variables

Postby CICS Guy » Sat Apr 05, 2008 7:32 pm

For COMP-3, it is simple..... Add up the number of 9s, add one for the sign and then divide by two and round up.....
S9(9)V99 is X'99999999999S' or six bytes
S9(8)V99 is X'09999999999S' or six bytes
S9(7)V99 is X'999999999S' or five bytes

For COMP, I suggest that you look it up yourself.
Pay attention to both the COMP (binary) and the COMP-5 (native binary)....
CICS Guy
 
Posts: 246
Joined: Wed Jun 20, 2007 4:08 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to calculate size of a COMP-3 and COMP variables

Postby dick scherrer » Sat Apr 05, 2008 11:52 pm

Hello,

Now i would like to declare an equivalent alpha numeric for the COMP-3 variable.
Depending on exactly what you want to do, knowing the physical length of the comp/comp-3 variables may not be all that you need to know.

If you explain how you want to use the "equivalent alpha numeric", we may be able to offer more usable suggestions.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: How to calculate size of a COMP-3 and COMP variables

Postby suryaprakesh » Thu Apr 10, 2008 12:18 pm

hi

the comp-3 values can be calculated by using the formula

(n/2+1)(when the number is even) for instance pic s9(4) comp-3 ,so here n is 4 by using the formula we get 3 bytes.
(n/2 +1/2) (when the number is odd) for instance pic s9(5) comp-3 sh here n is 5 and answer is also 3 bytes.

and for comp s9(1) to s9(4) - 2 bytes
s9(5)to s9(9)- 4bytes
s9(10)to s9(18) 8bytes

These users thanked the author suryaprakesh for the post:
rajeshdatrika (Wed Feb 15, 2017 3:44 pm)
suryaprakesh
 
Posts: 1
Joined: Thu Apr 10, 2008 11:54 am
Has thanked: 0 time
Been thanked: 1 time

Re: How to calculate size of a COMP-3 and COMP variables

Postby sinmani » Fri May 25, 2012 3:15 pm

prashanthreddy wrote:Hi All,

I would like to know how to calculate the Pic size of a COMP-3 and COMP variables.
My requirement is in my COBOL program one variable is declared as S9(9)V99 COMP-3.Now i would like to declare an equivalent alpha numeric for the COMP-3 variable. wat is the Pic size of alpha numeric ( X(??)) variable.
How to calculate the size of equivalent alpha numeric for COMP-3 and also COMP ??

Thanks in advance.

regards,
Prashanth


None of the mentioned answers are correct.
The question is declare an equivalent PIC X variable that should be 9 + 2 = PIC X (11).

The calculation which is being done in the other replies is about the bytes compiler takes to store the comp-3 variable internally to save memory.

Seniors correct me if I am wrong
-----------------------------------------
As long as you think you are a student, you are doing well.
The day you consider yourself as the master of the game..........well
sinmani
 
Posts: 93
Joined: Thu Mar 22, 2012 10:02 am
Has thanked: 14 times
Been thanked: 0 time

Re: How to calculate size of a COMP-3 and COMP variables

Postby Robert Sample » Fri May 25, 2012 4:37 pm

sinmani , since the original question was posted more than 4 YEARS AGO, do you really think your answer will make a difference to that person?
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: How to calculate size of a COMP-3 and COMP variables

Postby NicC » Fri May 25, 2012 5:01 pm

Actually 9+2+1 for the decimal point (if you want to display that as well)
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: How to calculate size of a COMP-3 and COMP variables

Postby sinmani » Fri May 25, 2012 7:14 pm

Robert Sample wrote:sinmani , since the original question was posted more than 4 YEARS AGO, do you really think your answer will make a difference to that person?


Hi Robert ,

It might not help the person who asked that question but it can definitely help thousands of readers who flock to this forum for gaining knowledge.
:)
-----------------------------------------
As long as you think you are a student, you are doing well.
The day you consider yourself as the master of the game..........well
sinmani
 
Posts: 93
Joined: Thu Mar 22, 2012 10:02 am
Has thanked: 14 times
Been thanked: 0 time

Re: How to calculate size of a COMP-3 and COMP variables

Postby BillyBoyo » Fri May 25, 2012 9:35 pm

And since the original question was so poorly worded that we don't know what was wanted... I can't exactly say it wasn't a request to know the bytes rather than the digits...
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: How to calculate size of a COMP-3 and COMP variables

Postby jygboy » Tue Oct 04, 2016 2:13 am

i will make you understand with examples-
formula is - [(N/2)+1] = and Truncate it to Last pure number
Eg- S9(11) = [(11/2)+1] = 6.5 --> round up to last pure no which is 6
OR
S -takes 1/2 byte and N/2
S9(7) = 1/2+7/2 = 4
S9(8) = 1/2+8/2=4.5 = 5 (NEXT PURE NUMBER)

S9(7)V99 COMP 3 = 7+2=9 S9(9) = 1/2+9/2=5 BYTE
Thanks..!!
JygBoy
jygboy
 
Posts: 1
Joined: Fri Sep 30, 2016 12:22 am
Location: Pennsylvania, USA
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post