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

numeric values not getting compared properly

0 Likes
916

Hi All,

I have one parameter on my selection screen, and other is global variable of the type  Z-table field which is having a numeric value and the  parameter is of type char but can have only numeric values, therefore I applied a numeric check for that and applied condense statement so that it compares it with the numeric field correctly.

Declaration:

Data : gv_value type ZZVALUEL (it is the numeric field)

Parameters : p_days(5)  type c

The problem is when I am executing the statement :

if p_days LT gv_value .

Message 'the value should be greater or equal to <gv_value>' .

endif.

gv_value is 720 in the table

entering p_days = 999

error is not coming , but when entering 1000 or above it displays the error even though it is the greater value than gv_value.

1 ACCEPTED SOLUTION
Read only

0 Likes
866

Hi Tanya,

The use of Type C which is of length 5 is the real problem.

If you use Type C for variable p_days the it will internally convert 720 as 00999 where as your gt_value is 720 always as it is Numeric.

This can never be compared and your condition fails always.

Use Type N or take another variable

p_days2 type N.

P_days2 = p_days.

If p_days2 LT gt_value.

Message 'XXXXXXXXXXXXXXXXXXXXXXXXX'.

Endif.

This will help you.

Regards,

Veera

2 REPLIES 2
Read only

PeterJonker
Active Contributor
0 Likes
866

For me the solution is pretty obvious, but offcourse I don't know the restrictions you might have.

But if you want to compare two fields, why do you not declare them the same way ?

Parameters : p_days type ZZVALUEL.


And if that is not possible maybe you can declare another field where you move the parameter to before compare



data: lv_days type ZZVALUEL.

Parameters: p_days(5) type c


* do your checks for numeric and then


lv_days = p_days.


And now compare lv_days with the global variable in stead of p_days.

Read only

0 Likes
867

Hi Tanya,

The use of Type C which is of length 5 is the real problem.

If you use Type C for variable p_days the it will internally convert 720 as 00999 where as your gt_value is 720 always as it is Numeric.

This can never be compared and your condition fails always.

Use Type N or take another variable

p_days2 type N.

P_days2 = p_days.

If p_days2 LT gt_value.

Message 'XXXXXXXXXXXXXXXXXXXXXXXXX'.

Endif.

This will help you.

Regards,

Veera