Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 7314

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: 1250
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: 8199
Location: East Dubuque, Illinois, USA

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 Comparing dates in different formats migusd SYNCSORT 4 Sat Nov 18, 2017 3:02 am
No new posts CONDITIONAL USING COMP-2 WITH PROBLEMS. JOSUEGENTIL COBOL Programming 7 Wed Nov 08, 2017 11:13 pm
No new posts how can i move s9(9) to s9(9) usage comp HARENDRA CHOUDHARY COBOL Programming 3 Mon Nov 06, 2017 12:10 am
This topic is locked: you cannot edit posts or make replies. Need help how to pass the ESP variabl... Venkichaitu JCL & VSAM 12 Thu Nov 02, 2017 3:53 am
This topic is locked: you cannot edit posts or make replies. Comparing current time with the time ... arunsoods SYNCSORT 1 Mon Oct 30, 2017 4:07 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us