View previous topic :: View next topic
|
Author |
Message |
Direction
New User
Joined: 15 Sep 2005 Posts: 11
|
|
|
|
HI all
I have to compare two variables having different value.
Exp:
var1 contains value 'xxxxx '
var2 contains value 'xxxxx'
and
IF (VAR1 EQUALS TO VAR2 ) ----> IS NOT COMING TRUE.
How I can compare these two values other THAN DOING SUBSTRING.
Pls help!!!!!!!! |
|
Back to top |
|
|
donevin
New User
Joined: 07 Jun 2005 Posts: 70 Location: South Africa
|
|
|
|
Would this help?
Code: |
01 Var1 Pic x(6).
01 Var-red redefines Var1.
03 Val Pic x(5).
03 Filler Pic x.
01 Var2 Pic x(5). |
Then say : If Val = Var2 |
|
Back to top |
|
|
donevin
New User
Joined: 07 Jun 2005 Posts: 70 Location: South Africa
|
|
|
|
Reference modification would also be an option like so :
Code: |
IF Var1(1:5) = Var2 |
|
|
Back to top |
|
|
Direction
New User
Joined: 15 Sep 2005 Posts: 11
|
|
|
|
Thanx but I am looking for other solution. I know this why but it doesn't suit to my needs. |
|
Back to top |
|
|
donevin
New User
Joined: 07 Jun 2005 Posts: 70 Location: South Africa
|
|
|
|
More information would help. What kind of solution are you looking for. Give more detail please. |
|
Back to top |
|
|
Direction
New User
Joined: 15 Sep 2005 Posts: 11
|
|
|
|
Thanx for ur help.
I am comparing the two variable of different size, which may contain same value.
As variables had a different size, if I got same value for both variables my if condition doesnot satisfies.
How can I compare these to variables containing same value and having different size.
IF ( var1 EQUAL TO var2 )
var1 and var2 have same value but different size. |
|
Back to top |
|
|
donevin
New User
Joined: 07 Jun 2005 Posts: 70 Location: South Africa
|
|
|
|
These variables does not contain the same value as you know. Five x's plus a space can never be equal to five x's. I know numeric fields of different lengths but with the same value content would be equal, but there's no way string fields of different lengths can be equal. Are you comparing strings or numerics? |
|
Back to top |
|
|
KS
New User
Joined: 28 Feb 2006 Posts: 91 Location: Chennai
|
|
|
|
Hi,
If its string , you can use STRCMP function.
If its numeric , Use IF.
If its between a numeric and alpha numeric, then move the numeric to alpha numeric and then use string function.
Hope it helps you.Get back if am wrong.
Thanks,
KS |
|
Back to top |
|
|
martin9
Active User
Joined: 01 Mar 2006 Posts: 290 Location: Basel, Switzerland
|
|
|
|
look at the hex values of your variables and you know if
they are comparable...
martin9 |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Direction,
I have no problem with the comparison you are trying to make. The following code, and result, is what I get on my machine. What platform are you running on? Is it possible that the string in either field is not padded with spaces?
Code: |
WORKING-STORAGE SECTION.
01 WS-STR1 PIC X(20) VALUE 'DAVIDATK '.
01 WS-STR2 PIC X(8) VALUE 'DAVIDATK'.
PROCEDURE DIVISION.
IF WS-STR1 = WS-STR2
THEN
DISPLAY 'WS-STR1 = WS-STR2'
ELSE
DISPLAY 'WS-STR1 NOT = WS-STR2'
END-IF.
GOBACK.
|
give the result
Code: |
.SARPAGE 4
.
.WS-STR1 = WS-STR2
|
Dave |
|
Back to top |
|
|
Prajesh_v_p
Active User
Joined: 24 May 2006 Posts: 133 Location: India
|
|
|
|
Direction..
Are u sure u had a problem like that?..What my understandig is,it will truncate the excess field and then comapre..
Does anybody why it happens if so?.. I too had a problem like this in recently..and I have got the result just like DavidatK explained.. |
|
Back to top |
|
|
calspach
New User
Joined: 05 May 2006 Posts: 32 Location: USA
|
|
|
|
Perhaps you have low-values in that space instead of a space. Try initializing your variables before moving into them. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Can you please show us the PICs of the 2 variables inquestion? |
|
Back to top |
|
|
GeneNorman
New User
Joined: 26 May 2006 Posts: 8 Location: Madison, Wisconsin USA
|
|
|
|
For alphanumeric operands of unequal size
Quote: |
Operands of
unequal size If the operands are of unequal size, the comparison is made as though the shorter operand were extended to the right with enough spaces to make the operands equal in size.
|
In other words if the longer operance has ANY value but space in the positions that don't exist in the shorter operand the comparison is UNEQUAL |
|
Back to top |
|
|
|