Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Character comparison.

rohit_trivedi
Product and Topic Expert
Product and Topic Expert
0 Likes
615

Hi Friends,

We have a scenario in which a database table field is of type CHAR10.

Selection screen parameter is as well defined using the same field.

Actually this represents a number but is defined as character.

Now, due to character comparison we get false results when user enters a number on that selection screen.

For ex: 133.33 is evaluated greater then 1000 and the like. This is because of character comparison.

Could someone help me how can i get correct result here?

Is there some way that i dont have to change the field type in DDIC to number, and still i can get number comparison instead of character comparison?

Thanks,

Rohit.

3 REPLIES 3
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
594

Hi,

I actually tried for what you asked.But even in comparing with character,I am getting the correct answer.If you have problem with character,just convert it into variable of type p as I am doing here.Kindly reward points by clicking the star on the left of reply,if it helps.

data : c1(10),

p1 type p decimals 2.

c1 = '133.33'.

p1 = c1.

if c1 le 1000.

write 'Correct'.

endif.

skip.

if p1 le 1000.

write 'Correct'.

endif.

Read only

rohit_trivedi
Product and Topic Expert
Product and Topic Expert
0 Likes
594

Hi,

The character comparison indeed gives the wrong result.

check this code:

-


data : x1 type char10, x2 type char10.

x1 = '133.35'.

x2 = '1000'.

if ( x2 > x1 ).

write ' successful'.

write x1.

endif.

if ( x1 > x2 ).

write 'unsuccessful'.

endif.

-


Also it wont be possible to assing char to num as you have mentioned, because comparison is done with database table field, which is character and not a number!

Thanks,

Rohit.

Read only

0 Likes
594

Hi,

If X2 is database field,keep it as such.Just change the comparing variable to type p.

Here is the sample.It gives correct result.Kindly reward points if it helps.

data : x1 type char10, x2 type char10, p1 type p decimals 2.

x1 = '133.35'.

p1 = x1.

x2 = '1000'.

if ( x2 > p1 ).

write ' successful'.

write x1.

endif.

if ( p1 > x2 ).

write 'unsuccessful'.

endif.