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
 

 

Issue in Comparing 2 Signed Comp Variables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Issue in Comparing 2 Signed Comp Variables
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Thu Jan 08, 2015 3:10 pm    Post subject: Reply to: Issue in Comparing 2 Signed Comp Variables
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: 1219
Location: Israel

PostPosted: Thu Jan 08, 2015 3:39 pm    Post subject: Reply to: Issue in Comparing 2 Signed Comp Variables
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: 7909
Location: Bellevue, IA

PostPosted: Thu Jan 08, 2015 6:22 pm    Post subject:
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    Post subject: Issue in Comparing 2 Signed Comp Variables
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    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 DFHRESPONSE returns issue divated CICS 3 Wed Nov 02, 2016 6:32 pm
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm
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


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