Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Can s9(02) comp-3 contain a value 999?
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

Active Member


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

PostPosted: Tue May 01, 2007 5:27 pm    Post subject:
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    Post subject:
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    Post subject: Re: Can s9(02) comp-3 contain a value 999?
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

Site Director


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

PostPosted: Mon May 28, 2007 5:14 pm    Post subject:
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    Post subject: Re: Can s9(02) comp-3 contain a value 999?
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Thu May 31, 2007 5:13 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm
No new posts Need help to populate date in COMP-3 ... chetanambi DFSORT/ICETOOL 3 Tue Jun 21, 2016 12:25 pm
No new posts comparing comp-3 and unpacked numbers juares castro COBOL Programming 3 Mon May 30, 2016 6:46 pm
No new posts SIGNED DECIMAL TO COMP-3 using cobol ... ram_vizag COBOL Programming 1 Tue Mar 01, 2016 11:32 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us