View previous topic :: View next topic
|
Author |
Message |
hey_its_me Warnings : 1 New User
Joined: 23 Aug 2006 Posts: 14 Location: USA
|
|
|
|
Hi all,
I have a doubt regarding the packed decimal format of storage while using comp-3.
I guess in comp-3 each byte contain 2 digits, and the last nibble is used to store sign.
so here s9(02) comp-3 has (2/2+1) bytes = 2 bytes.
so altogether, first byte would store a two digits and the next one with a sign.
ie the maximum value it can store is 999.
I'm confused on the maximum value s9(02) can store, is it 2 digits value eg: 99 or as explained above.
Is this packed decimal concept only for storage, for better computation?
Advise me and correct me if I'm wrong
With Regards,
Anil Kumar |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
COBOL restricts your values to your PIC, so +/-99 is the max value here. The leftmost nibble will always be zero. MOVE 123 to VAR will result in a value of 23.
If you want the max according to your byte allocation, then use an odd number of digits. |
|
Back to top |
|
|
manmadharasa
New User
Joined: 05 Mar 2007 Posts: 5 Location: Chennai
|
|
|
|
S9(2) comp-3 &
S9(3) comp-3 both will take only 2 bytes. But maximum value stored in first field is 99 and in seconde field is 999. |
|
Back to top |
|
|
pcoreddy
New User
Joined: 14 Mar 2007 Posts: 24 Location: Mysore
|
|
|
|
S9(2) comp-3 &
S9(3) comp-3 both will take only 2 bytes
but both will store max 999 only... not 99 |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
With which compiler options did you test this?
Quote: |
but both will store max 999 only... not 99 |
Please post code of moving 999 to the 9(2) field and displaying that field after the move and the output from that test. |
|
Back to top |
|
|
raam2smart
New User
Joined: 31 May 2007 Posts: 19 Location: Chennai
|
|
|
|
Hi i tried your example as such in a program,
It gives 99 for s9(02) comp-3 & 999 for s9(03).
The program is something like this:
IDENTIFICATION DIVISION.
PROGRAM-ID. JUNK.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR1 PIC S9(02) COMP-3.
01 WS-VAR2 PIC S9(03) COMP-3.
PROCEDURE DIVISION.
MOVE 999 TO WS-VAR1.
DISPLAY 'WS-VAR1 :' WS-VAR1.
MOVE 999 TO WS-VAR2.
DISPLAY 'WS-VAR2 :' WS-VAR2.
STOP RUN.
The output is:
WS-VAR1 :99
WS-VAR2 :999
Thanks,
Raam |
|
Back to top |
|
|
donevin
New User
Joined: 07 Jun 2005 Posts: 70 Location: South Africa
|
|
|
|
If both declarations occupies 2 bytes and say half a byte is used to store a digit. What dictates that the Pic S9(02) comp-3 can only store 2 digits? Is it the digit 2 as opposed to 3 in the picture clause perhaps? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
donevin wrote: |
If both declarations occupies 2 bytes and say half a byte is used to store a digit. What dictates that the Pic S9(02) comp-3 can only store 2 digits? Is it the digit 2 as opposed to 3 in the picture clause perhaps? |
Yes, if you specify 9(2), COBOL will add code to insure the leading half byte is always zero. |
|
Back to top |
|
|
donevin
New User
Joined: 07 Jun 2005 Posts: 70 Location: South Africa
|
|
|
|
Thank you very much William. |
|
Back to top |
|
|
|