View previous topic :: View next topic
|
Author |
Message |
elango Paulraj
New User
Joined: 12 Jul 2010 Posts: 2 Location: Chennai
|
|
|
|
Hi All,
When i am trying to compare two signed COMP variables i am getting an un-expected result. Need some pointers to understand the issue
Declaration:
01 Variable-1.
03 Var-1 S9(9) USAGE COMP.
03 Var-2 S9(9) USAGE COMP.
01 Variable-2.
03 Var-3 S9(9) USAGE COMP.
03 Var-4 S9(9) USAGE COMP.
Data in Variables
When we have Var-1 & Var-2 (+Ve) values say 000000001 & 000000001
and Var-3 & Var-4 (-ve) values say -000000001 & -000000001
Comparision as follows
IF Variable-1 < Variable-2
Do processing
END-IF
Expectation
We expect this condition to fail as Variable-1 is having +ve value that is Greater that the Variable-2 that contains the -ve value.
Actual Result
But this comparision is getting successful stating the -Ve values are actually Greater than the Positive Value.
I tried to search for an answer but not able to narrow down to the issue. So posting the query for some pointers.[/u] |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
In terms of a logical, or character, compare, negative binary values are larger than positive ones. Don't do that.
Only compare group items with subordinate computational fields of any type (including packed-decimal) if you know what you are doing. And then don't do it, because it would mean assuming that all your colleagues and people who work on the program in the future know what they are doing. So don't do it. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
In other words: don't be lazy, compare fields separately:
Code: |
IF (Var-1 < Var-3) AND (Var-2 < Var-4) THEN
... |
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Despite what your post title says, you are NOT comparing two signed COMP variables -- you are comparing two group variables (which contain signed COMP variables). Review your COBOL -- group compares are ALWAYS done as alphanumeric, hence you must look at the hexadecimal representations of the data to understand why the compare returns the results it does. |
|
Back to top |
|
|
elango Paulraj
New User
Joined: 12 Jul 2010 Posts: 2 Location: Chennai
|
|
|
|
Thanks for taking time and answering the query. |
|
Back to top |
|
|
|