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

Issue in Comparing 2 Signed Comp Variables


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

New User


Joined: 12 Jul 2010
Posts: 2
Location: Chennai

PostPosted: Thu Jan 08, 2015 1:55 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Jan 08, 2015 3:10 pm
Reply with quote

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

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Jan 08, 2015 3:39 pm
Reply with quote

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

Global Moderator


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

PostPosted: Thu Jan 08, 2015 6:22 pm
Reply with quote

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

New User


Joined: 12 Jul 2010
Posts: 2
Location: Chennai

PostPosted: Thu Jan 08, 2015 8:19 pm
Reply with quote

Thanks for taking time and answering the query.
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 Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Issue after ISPF copy to Linklist Lib... TSO/ISPF 1
No new posts Facing ABM3 issue! CICS 3
Search our Forums:

Back to Top