View previous topic :: View next topic
|
Author |
Message |
asr1983
New User
Joined: 31 May 2005 Posts: 11
|
|
|
|
hi,
i just want to know how the comp-3 is stored in the system and when it
is displayed how is it displayed.
Ex : 01 z pic s9(4) comp-3 value +1234.
how is it stored .....
and if given
display z.
how is it displayed
siva |
|
Back to top |
|
|
kanak
Moderator
Joined: 12 Mar 2005 Posts: 252 Location: India
|
|
|
|
COMPUTATIONAL-3 or COMP-3 (internal decimal)
For VS COBOL II, this is the equivalent of PACKED-DECIMAL.
PACKED-DECIMAL
Specified for internal decimal items. Such an item appears in storage in packed decimal format. There are 2 digits for each character position, except for the trailing character position, which is occupied by the low-order digit and the sign. Such an item can contain any of the digits 0 through 9, plus a sign, representing a value not exceeding 18 decimal digits.
No idea how it get displayed. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi siva,
It is converted to external decimal format (unpacked) before it is DISPLAYed.
Everthing looks normal except for the sign: it's diplayed using the low order 4 bits of the packed field as the high order 4 bits of the displayed byte and the low order digit of the packed field as the low order 4 bits of the diplayed byte.
E.g. X'011C' DISPLAYs as 01A (X'F0F1C1'). |
|
Back to top |
|
|
Ashutosh Shrinet
New User
Joined: 22 Aug 2004 Posts: 10 Location: New Delhi
|
|
|
|
hi siva
comp3 stored as packed decimal format.if u want to display it first u move this variable into another variable which's usage clause is display. then u can see the value of comp3.otherwise it will show in hexadecimal. |
|
Back to top |
|
|
senthilkumar selvaraju
New User
Joined: 30 May 2005 Posts: 16
|
|
|
|
hi siva, Ashutosh Shrinet message is correct. as per your example it takes 3 bytes( n/2 + 1)
n- number of bytes (1234 i.e 4 bytes)
1 - for sign so (4/2 + 1) = 3 bytes (but i am not sure about odd bytes storage ) If any having answer please reply......... |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Ashutosh,
You said:
Quote: |
comp3 stored as packed decimal format.if u want to display it first u move this variable into another variable which's usage clause is display. then u can see the value of comp3.otherwise it will show in hexadecimal. |
Have you ever tried to DISPLAY a COMP-3 field? You're in for a surprise.
The best way to formulate the size of a packed (COMP-3) field is to count the number of digit desired add 1 for the sign and divide by 2. BTW, there's ALWAYS a sign, even if you don't put one in the PIC.
If there's a remainder add 1 to answer. For example:
1234 is 4 digits; add 1 for the sign; divide by 2 = 2 1/2; add 1 to the 2 in the ans = 3 bytes.
12345 is 5 digits; add 1 for the sign; divide by 2 = 3; no remainder, no add 1; the ans = 3 bytes. |
|
Back to top |
|
|
mdtendulkar
Active User
Joined: 29 Jul 2003 Posts: 237 Location: USA
|
|
|
|
Jack,
We remember it this way
Quote: |
For Even Digit Field formula is --> N /2 + 1
For Odd Digit Field formula is --> (N + 1)/2 |
Regards
Mayuresh |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Mayuresh,
But 1st, one must understand. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Mayuresh,
I should have added this to my previous post.
In my opinion the best way to calc the # of bytes in a comp-3 field is to total the # of 9s. If the total is even, divide by 2; if odd add 1 THEN divide by 2.
It eliminates playing w/the fraction and makes the division straightforward. |
|
Back to top |
|
|
mdtendulkar
Active User
Joined: 29 Jul 2003 Posts: 237 Location: USA
|
|
|
|
Very True Jack,
Its the same formula which I showed.
EVEN 9's --> (N/2 + 1)
ODD 9's --> ((N+1)/2)
N = Number of 9's
Regards,
Mayuresh |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
No, Mayuresh. Mine was a sentence; YOUR'S was a formula. |
|
Back to top |
|
|
|