## 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

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 ??

regards,
Prashanth
prashanthreddy

Posts: 8
Joined: Sat Jan 19, 2008 3:19 pm

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

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: 258
Joined: Wed Jun 20, 2007 4:08 am

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

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.

dick scherrer
Global moderator

Posts: 6324
Joined: Sat Jun 09, 2007 8:58 am

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

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
suryaprakesh

Posts: 1
Joined: Thu Apr 10, 2008 11:54 am

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

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 ??

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

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

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: 2890
Joined: Sat Dec 19, 2009 8:32 pm
Location: Atlanta, GA

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

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: 2342
Joined: Sun Jul 04, 2010 12:13 am
Location: Down on the pig farm

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

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

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

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: 3579
Joined: Tue Jan 25, 2011 12:02 am