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

Need to compare COMP and CHAR variables


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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

Moderator Emeritus


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

PostPosted: Fri Jun 29, 2007 8:58 pm
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: 148
Location: Ottawa Canada

PostPosted: Fri Jun 29, 2007 9:26 pm
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

Moderator Emeritus


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

PostPosted: Fri Jun 29, 2007 9:57 pm
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
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

Moderator Emeritus


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

PostPosted: Fri Jun 29, 2007 11:42 pm
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
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Compare two files with a key and writ... SYNCSORT 3
Search our Forums:

Back to Top