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

maximum value in S9(09) COMP


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

New User


Joined: 15 May 2008
Posts: 41
Location: Chennai

PostPosted: Fri Apr 10, 2009 3:42 pm
Reply with quote

Hi,

What is the maximum value that can be fit in "ws-var1 S9(09) COMP".

Value 2145555555 (10 digits) is also able to fit in above variable. Is maximum value for s9(9) is not '999999999'???

Plz let me know on this.

Regards,
Saagu
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 10, 2009 3:59 pm
Reply with quote

Saagu,

one of the things you will have to learn is how to look-up such questions in the documentation.

to start with, COBOL (why post this in the JCL forum?)

does not really matter what release of cobol, data definitions have been rather consistent.

top of the page, manuals button.

might as well read about numerics in general as well as binary and you will learn why s9(9) COMP is not 999999999.
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Fri Apr 10, 2009 4:01 pm
Reply with quote

+2147483647
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Apr 10, 2009 4:07 pm
Reply with quote

Depending on the compile option TRUNC, the maximum 'signed' value is 2147483647, because this is represented internally as a binary fullword (X'7FFFFFFF'). An unsigned maximum value would be 4294967295 (X'FFFFFFFF').

IIRC, TRUNC(OPT) limits the maximum (in your example) to 999999999, because truncation is based upon the picture clause.

TRUNC(BIN) always allows the maximum value. The other TRUNC option (STD) is similar to BIN, but not quite the same.

However, if your compiler supports COMP-5 (Native Binary), then you should use this as the TRUNC option has no effect.

Fullwords occupy 4-Bytes.

Regards,
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 10, 2009 4:10 pm
Reply with quote

Gnanas N.,

The OP has the answer to one of his questions.
how about the other one?
you have saved him some research and any potential exposure to any other knowledge.

But, then again, I may be too harsh.

This is probably the only thing that he does not understand.
Back to top
View user's profile Send private message
saagu

New User


Joined: 15 May 2008
Posts: 41
Location: Chennai

PostPosted: Fri Apr 10, 2009 4:14 pm
Reply with quote

Thanks Gnanas and O'Boyle for your reply.

Regards,
Saagu
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Fri Apr 10, 2009 4:17 pm
Reply with quote

Hi dbzTHEdinosauer,
Quote:
how about the other one?
Almost certainly he has to refer the manual as you suggested.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Apr 10, 2009 4:50 pm
Reply with quote

I agree that the manual should be the initial source of information and I won't dispute this.

In the case of the TRUNC option and how it deals with binary data, it can be rather "dicey" for newbies and perhaps, a basic overview as to how COBOL interacts with the TRUNC option was warranted.

TRUNC is probably the most confusing and convoluted option in IBM's list of COBOL compiler options. It's been around since OS/VS COBOL (perhaps, even earlier) and it's gone through many different definitions of usage over the years, that someone could write a thesis on it. icon_wink.gif

Regards,
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 10, 2009 5:50 pm
Reply with quote

Bill,

I will be the last to complain of your posts.

I took issue with just providing a value without providing the type of info that you gave.

also, as I was composing my little ditty, you posted first.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Apr 10, 2009 6:32 pm
Reply with quote

Dick said -
Quote:

I took issue with just providing a value without providing the type of info that you gave.

Dick,

I usually (but not always) just give them enough to spark their interest and force a review from the manual. icon_wink.gif

If I receive a reply saying that they're not too sure, I generally let a sleeping dog lie (and don't reply) because this indicates that they've not taken the time to look it up in the manual (or outright tell them) as I tried to imply and figure it out on their own.

I understand your frustration with some of these posts....

Regards,
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Sat Aug 07, 2010 12:40 am
Reply with quote

Hi,

I was going through the TRUNC example given in the manual.
For the first example, when I was working using binary, i was able to get the answer as -7621.

And when I tried to reach the same result using, hex, i understood it will be E23B, but how E23B will represent -7621, i couldn't find out the answer.

Please help.

I am talking about the example given in

link -

Regards,
Tushar
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sat Aug 07, 2010 12:57 am
Reply with quote

Hex E = binary 1110, flip the bits to get 0001
Hex 2 = binary 0010, flip the bits to get 1101
Hex 3 = binary 0011, flip the bits to get 1100
Hex B = binary 1011, flip the bits to get 0100 plus 1 gives 0101

1DC5 converted from hex is 7621. Since the bits were flipped, the number is -7621.
Back to top
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Sat Aug 07, 2010 10:01 pm
Reply with quote

@Robert - Thanks again.

I understood, that the Complement of the truncated value should be found, to get the correct value. and even link says & i quote
Quote:
Because the new truncated value overflowed into the sign bit of the binary halfword, the value becomes a negative number.


Now the question arises, how did COBOL knew, that negative value is to be printed, and also, from the IBM link's quote, I feel whenever these type of truncation or this situation arises, only negative number will be displayed, as everytime truncated value will overflow into sign bit.

Please let me know, If my question is not clear
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sat Aug 07, 2010 11:49 pm
Reply with quote

You are misunderstanding the text and its application. The sign bit of a COMP variable is merely the first bit. When the truncated (half-word) move is done, and the moved result has the first bit turned on, the value is negative -- there' is nothing for COBOL to "know" since this is inherent in the way COMP variables are defined and work.

If you try the TRUNC(BIN) example from the text with 94779 instead of 123451, the resulting value will be positive (I haven't tested with the compiler but the value should be 29243).
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 SORT ERROR PARAMETER VALUE EXCEEDS M... DFSORT/ICETOOL 12
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
Search our Forums:

Back to Top