Poor syntax. S9(3)V99 is correct and occupies 3 bytes. Count the number of 9's add 1 and divide by 2 rounding up if necessary. ex.

S9(7)v99. there are 9 nines. (9+1)/2 = 5 bytes.

S9(6)V99. there are 8 nines (8+1)/2 = 4.5 = 5 bytes.

binary data (COMP) has no fractions, integers only.

Anuja Tiwari

Apr 5th, 2006

COMP fields are stored as binary.

9(1) to 9(4) are stored as 2 Binery. 9(5) to 9(9) are stored as 4 Binery. 9(10) to 9(18) are stored as 8 Binery.

so if your question is for S9(1)V9(2) comp, it will be in Binery form and occupy 2 bytes.

NarayaN

Apr 26th, 2006

Can we generalize as follows,

S9(x)V9(y) will occupy (x+y+1)/2 bytes (Rounded to the next higher integer).

Is this for a USING COMP or COMP 3? How is the number of bytes calculated for the other?

Thanks!!

NarayaN

kapil vharande

May 29th, 2006

For comp it will take bytes (n/2+1)For comp-3 it will take bytes as(n/2+1)+.5 & n is numeric charactor define in data division.

Rajeev Saklani

Jul 20th, 2006

Hi,

ur question for comp and comp-3 storage

u have mentioned comp and assumed decimal v, for comp it is pure binary value and decimal is not allowed and storage formula is n/2 where n is number of 9's. For comp-3 we have (n/2 +1) where n is the no of 9's in integer and decimal parts. eg s9(3)v99 would occupy 5/2 +1 = 3 bytes.

for decimal we have comp-1 and comp-2 in halp word and fullword format

The formula for counting the number the bytes for packed decimal i.e Comp-3 is as follows:

(n/2)+1 bytes where n is the number of 9's .

For example ,

05 BALANCE-DUE PIC S9(6)V99 COMP-3.

This has 8 9's . so it will be calculated as ((8/2)+1) = 5 bytes. or in other way . (n+1)/2 = value (rounded) For the above example : ((8+1) /2) = 4.5(rounded) = 5. Comp-3 stores two digits per byte. Hope this helps.

(A) S9(3)V99 COMP-3 will occupy (N/2 +1) if N=Even and (N+1)/2 if N=Odd. Here N=5 which is odd. Hence, No of bytes used for storage internally=3 bytes (B) S9(1)V99 COMP will occupy based on below method:- 9(1) to 9(4) are stored as 2 Binary.
9(5) to 9(9) are stored as 4 Binary.
9(10) to 9(18) are stored as 8 Binary. Since here it's N=3, Thus it will occupy 2 bytes of internal storage. Also Comp can store Decimal numbers.

## How may do the following definitions occupy?(a) s(3)v99 comp-3(b) s(9)v99 comp

## Related Answered Questions

## Related Open Questions