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
 

 

Need to compare COMP and CHAR variables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
deepaannjohn

New User


Joined: 23 Feb 2006
Posts: 19
Location: Bangalore

PostPosted: Fri Jun 29, 2007 2:22 pm    Post subject: Need to compare COMP and CHAR variables
Reply with quote

Hi,

05 c-id1 pic x(10)
05 c-id2 pic s9(9) comp

05 c-id-temp1 pic 9(10)
05 c-id-temp2 pic s9(9) comp

Need to do compare c-id1 with cid-2.
so the following was done.

Move c-id1 to c-id-temp1
Move c-id-temp1 to c-id-temp2


PERFORM UNTIL c-id-temp2 > c-id2

IF (c-id-temp2 = c-id2)
.....
end-if

end-perform

But, when this is run using Xpeditor, it shows that '1111111111' when moved from c-id1 to c-id-temp2, truncates the last byte.

Please advice how i can handle this.

Also, I tried moving c-id2 directly to s 9(10) comp. But then it does not pass PERFORM UNTIL c-id-temp2 > c-id2 .

Regards,
Deepa
Back to top
View user's profile Send private message

deepaannjohn

New User


Joined: 23 Feb 2006
Posts: 19
Location: Bangalore

PostPosted: Fri Jun 29, 2007 2:23 pm    Post subject: Re: need to compare comp and varchar
Reply with quote

Sorry..the heading is incorrect..It shud be 'need to compare comp and char'
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Jun 29, 2007 8:58 pm    Post subject:
Reply with quote

Hello,

You cannot move 10 digits into a 9-digit receiving field and not expect truncation.

You don't want to compare 10 filled digits to 9 as that will not yeld the results you want.

What code is going to increment/decrement one of the fields so that the UNTIL becomes true?

It looks like you have only posted a bit of the code and not necessarily all that is needed to move forward.
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 149
Location: Ottawa Canada

PostPosted: Fri Jun 29, 2007 9:26 pm    Post subject:
Reply with quote

Not exactly sure about what you need but how about this:

05 c-id1 pic x(10)
05 c-id1-N redefines c-id1 pic 9(10).
05 c-id2 pic s9(9) comp

IF c-id1-N is numeric
IF c-id1-N = c-id2
SET WS-THE-SAME TO TRUE
ELSE
SET WS-NOT-THE-SAME TO TRUE
END-IF
ELSE
SET WS-NOT-THE-SAME TO TRUE
END-IF
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Jun 29, 2007 9:57 pm    Post subject:
Reply with quote

Hello TG,

I'm not sure that will get it. . .

The original post shows 10 meaningful digits and as long as there is an atempt to work with fields defined as 9 is made, i expect there will be problems due to a field with 10 digits will just not work with another field defined as 9.

Also, i read it as when a value went greater as opposed to not equal.
Back to top
View user's profile Send private message
deepaannjohn

New User


Joined: 23 Feb 2006
Posts: 19
Location: Bangalore

PostPosted: Fri Jun 29, 2007 10:46 pm    Post subject: Re: need to compare comp and char
Reply with quote

Hi,

My requirement is to compare an x(10) variable against an s9(9) comp variable.

Currently, I am moving x(10) to s9(10) and then s9(10) to s9(9) comp. But one byte get truncated when i move to s9(9) comp.
The value I am using is 1111111111. Since, s9(9) comp should be able to handle the range 2,147,483,648 to 2,147,483,647, I am wonderign , why thr truncation is happening?

Please let me know teh ideal way to handle this.

Thanks,
Deepa
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Jun 29, 2007 11:42 pm    Post subject:
Reply with quote

Hello,

Why do you think that
Quote:
s9(9) comp should be able to handle the range 2,147,483,648 to 2,147,483,647 (looks like the minus sign is missing)
this is true? 10 digits cannot be stored in a field defined as a 9-digit field. What can the system do but truncate the "extra" digit?

Have you tried using s9(10) comp for your fields?
Back to top
View user's profile Send private message
nagasri83

New User


Joined: 20 May 2005
Posts: 15
Location: chennai

PostPosted: Thu Jul 12, 2007 7:05 am    Post subject:
Reply with quote

I agree with Dick. We cannot expect the result without truncation when there is mismatch in from and to fields.

We can compare only 9 characters according to the code given.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Jul 12, 2007 7:44 am    Post subject:
Reply with quote

Why not move c-id2 to an X(10) field as follows

Code:

05 c-id1 pic x(10)
05 c-id2 pic s9(9) comp

05 c-temp-id2 pic x(10)

IF cid2 < 0
   move '-' to c-temp-id2(1:1)
end-if

move c-id2 to c-tempid2(2:9)



Then do your compare.
Back to top
View user's profile Send private message
nagasri83

New User


Joined: 20 May 2005
Posts: 15
Location: chennai

PostPosted: Thu Jul 12, 2007 7:49 am    Post subject:
Reply with quote

Hi Stodolas,

If we do as you said, it mean we are decided to have '-' in the first character. But it can be any character in the c-id1. By doing this way, you will not arrive at expected result.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu Jul 12, 2007 8:01 am    Post subject:
Reply with quote

dick scherrer wrote:
Hello,

Why do you think that
Quote:
s9(9) comp should be able to handle the range 2,147,483,648 to 2,147,483,647 (looks like the minus sign is missing)
this is true? 10 digits cannot be stored in a field defined as a 9-digit field. What can the system do but truncate the "extra" digit?


That depends on the compiler options for binary items.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Jul 12, 2007 7:19 pm    Post subject:
Reply with quote

I'd just like to be sure that I understand. Deepa (or anybody), if the 2 fields are equal what would those fields look like in memory?

Or to put it another way, what numeric data type does the PIC X field represent?
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Jul 12, 2007 10:12 pm    Post subject:
Reply with quote

nagasri83,

I am making no assumptions about the c-id1 field. What I am showing is that we need to put a - in front of a negative number in order to be able to compare. The value of c-id2 is signed numeric, therefore the first postion in an X(10) field would be the sign for that value. Therefore it would fail in the first example below and succeed in the second and third.
Code:

ex1
c-id1 = AAABBBCCCD
c-id2 = -123456789

ex2
c-id1 =  123456789
c-id2 = 123456789

ex3
c-id1 = -123456789
c-id2 = -123456789



Code:

05 c-id1 pic x(10)
05 c-id2 pic s9(9) comp

05 c-temp-id2 pic x(10)

IF cid2 < 0
   move '-' to c-temp-id2(1:1)
   move c-id2 to c-tempid2(2:9)
else
   move ' ' to c-temp-id2(1:1)
   move c-id2 to c-tempid2(2:9)
end-if


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 Storing huge volume of data, compare ... Pradeep K M All Other Mainframe Topics 3 Mon Jan 16, 2017 5:08 pm
No new posts Match or compare two files in VB Format anatol DFSORT/ICETOOL 14 Thu Nov 03, 2016 7:41 pm
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
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