IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Can s9(02) comp-3 contain a value 999?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
hey_its_me
Warnings : 1

New User


Joined: 23 Aug 2006
Posts: 14
Location: USA

PostPosted: Tue May 01, 2007 11:11 am
Reply with quote

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
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Tue May 01, 2007 5:27 pm
Reply with quote

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
View user's profile Send private message
manmadharasa

New User


Joined: 05 Mar 2007
Posts: 5
Location: Chennai

PostPosted: Mon May 28, 2007 3:09 pm
Reply with quote

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
View user's profile Send private message
pcoreddy

New User


Joined: 14 Mar 2007
Posts: 24
Location: Mysore

PostPosted: Mon May 28, 2007 4:17 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon May 28, 2007 5:14 pm
Reply with quote

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
View user's profile Send private message
raam2smart

New User


Joined: 31 May 2007
Posts: 19
Location: Chennai

PostPosted: Thu May 31, 2007 12:40 pm
Reply with quote

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
View user's profile Send private message
donevin

New User


Joined: 07 Jun 2005
Posts: 70
Location: South Africa

PostPosted: Thu May 31, 2007 4:56 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu May 31, 2007 5:13 pm
Reply with quote

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
View user's profile Send private message
donevin

New User


Joined: 07 Jun 2005
Posts: 70
Location: South Africa

PostPosted: Thu May 31, 2007 5:14 pm
Reply with quote

Thank you very much William.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
No new posts Cobol COMP-2 fields getting scrambled... Java & MQSeries 6
No new posts convert alphanumeric PIC X(02) to hex... COBOL Programming 3
Search our Forums:

Back to Top