View previous topic :: View next topic
|
Author |
Message |
saagu
New User
Joined: 15 May 2008 Posts: 41 Location: Chennai
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
+2147483647 |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
saagu
New User
Joined: 15 May 2008 Posts: 41 Location: Chennai
|
|
|
|
Thanks Gnanas and O'Boyle for your reply.
Regards,
Saagu |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
Hi dbzTHEdinosauer,
Quote: |
how about the other one? |
Almost certainly he has to refer the manual as you suggested. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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.
Regards, |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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.
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 |
|
|
saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur
|
|
|
|
@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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
|