Page 1 of 2

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

PostPosted: Sat Apr 05, 2008 4:29 pm
by prashanthreddy
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

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

PostPosted: Sat Apr 05, 2008 7:32 pm
by CICS Guy
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)....

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

PostPosted: Sat Apr 05, 2008 11:52 pm
by dick scherrer
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.

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

PostPosted: Thu Apr 10, 2008 12:18 pm
by suryaprakesh
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

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

PostPosted: Fri May 25, 2012 3:15 pm
by sinmani
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

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

PostPosted: Fri May 25, 2012 4:37 pm
by Robert Sample
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?

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

PostPosted: Fri May 25, 2012 5:01 pm
by NicC
Actually 9+2+1 for the decimal point (if you want to display that as well)

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

PostPosted: Fri May 25, 2012 7:14 pm
by sinmani
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.
:)

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

PostPosted: Fri May 25, 2012 9:35 pm
by BillyBoyo
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...

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

PostPosted: Tue Oct 04, 2016 2:13 am
by jygboy
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