View previous topic :: View next topic
|
Author |
Message |
deepaannjohn
New User
Joined: 23 Feb 2006 Posts: 19 Location: Bangalore
|
|
|
|
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 |
|
|
deepaannjohn
New User
Joined: 23 Feb 2006 Posts: 19 Location: Bangalore
|
|
|
|
Sorry..the heading is incorrect..It shud be 'need to compare comp and char' |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
TG Murphy
Active User
Joined: 23 Mar 2007 Posts: 148 Location: Ottawa Canada
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
deepaannjohn
New User
Joined: 23 Feb 2006 Posts: 19 Location: Bangalore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
nagasri83
New User
Joined: 20 May 2005 Posts: 15 Location: chennai
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
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 |
|
|
nagasri83
New User
Joined: 20 May 2005 Posts: 15 Location: chennai
|
|
|
|
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 631 Location: Wisconsin
|
|
|
|
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 |
|
|
|