‎2007 Feb 08 8:58 AM
I have 2 character fields , Lenght 10
1 is havin data as d1 = '00000000001' and other d2 = '1' .Mathematically they are equal. How can i compare them to get resuly as equal.
‎2007 Feb 08 8:59 AM
refer this demo code -
data: d1(10),
d2(10),
c1 type i,
c2 type i,
d3(10) type n.
d1 = '0000000001'.
d2 = '1'.
c2 = strlen( d2 ).
d3 = '0000000000'.
c1 = strlen( d3 ) - c2.
d3+c1(c2) = d2.
if d1 = d3 .
write 'Equal'.
else.
write 'not equal'.
endif.
‎2007 Feb 08 8:59 AM
refer this demo code -
data: d1(10),
d2(10),
c1 type i,
c2 type i,
d3(10) type n.
d1 = '0000000001'.
d2 = '1'.
c2 = strlen( d2 ).
d3 = '0000000000'.
c1 = strlen( d3 ) - c2.
d3+c1(c2) = d2.
if d1 = d3 .
write 'Equal'.
else.
write 'not equal'.
endif.
‎2007 Feb 08 8:59 AM
use conversion_exit_alpha_output FM to remove leading zeroes.
suppose your variable contains '00000000001'.
data: var(10).
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = var
IMPORTING
OUTPUT = var.
now u can do comparison as all the leading zeroes are removed.
mark helpful answers
‎2007 Feb 08 9:00 AM
Cast/assign them temporarily to integer variables. Then compare those integer variables.
data: i1 type i, i2 type i.
i1 = d1.
i2 = d2.
if i1 eq i2.
...
endif.
Manoj
‎2007 Feb 08 9:01 AM
data: d1(10),
d2(10),
d3(10) type n.
d1 = '0000000001'.
d2 = '1'.
d3 = d2.
if d1 = d3 .
write 'Equal'.
else.
write 'not equal'.
endif.
‎2007 Feb 08 9:02 AM
<b>CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = d2
IMPORTING
OUTPUT = d2.
now compare
d1 and d2</b>
‎2007 Feb 08 9:01 AM
Hi,
Assign them to two data variables of type 'N' and then assign them to type I.
Then you can compare.
DATA: var1(10) type N value '0000000001'.
DATA: var2 type N value '1'.
DATA: var3 type I,
var4 type I.
var3 = var1.
var4 = var2.
if var3 = var4.
endif.
Regards,
Sesh
‎2007 Feb 08 9:01 AM
‎2007 Feb 08 9:03 AM
I dont think FM CONVERSION_EXIT_ALPHA_INPUT is useful in this case. U need to use FM CONVERSION_EXIT_ALPHA_OUTPUT which converts any number with zeroes right into a simple integer
Import parameters Value
INPUT 0000000001
Export parameters Value
OUTPUT 1
Then you can compare both the values.
I hope it helps.
Best Regards,
Vibha
*Please mark all the helpful answers
‎2007 Feb 08 9:07 AM
Hi,
use CONVERSION_EXIT_ALPHA_OUTPUT
and pass the value of D1 and the leading zeroes will be removed.
then compare
regards
Shiva