‎2010 Aug 19 2:29 PM
Hi,
I have a requirement where in i have to check for amount field should be between -1 and 1.
I have kept the condition as amount_field LE 1 and amount_field GT -1. But the problem is it is passing any thing less between -1.5 to 1.5. Pls let me know how to put this condition so it will take between -1 and 1.
Thanks,
Raju
‎2010 Aug 19 2:53 PM
TYPES : BEGIN Of TP_VAL1,
val1 TYPE p DECIMALS 2,
end of tp_val1.
DATA: wl_val1 type tp_val1,
t_val1 TYPE STANDARD TABLE OF tp_val1,
w_custom TYPE int2.
l_val1-val1 = '1.2'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '0.9'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '-0.6'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '1.9'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '-1.6'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '1.49'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '-1.46'. APPEND wl_val1 to t_val1.
clear w_custom.
LOOP AT t_val1 INTO wl_val1.
IF wl_val1-val1 LE '1' AND wl_val1-val1 GT '1'. "Same as what you have given
ADD 1 TO w_custom.
ENDIF.
ENDLOOP.
The output i'm getting is 2 ( which is correct )
Can you check again? I don't believe there is a problem in the IF statement. Problem could be in the data type of amount_field.
Thanks
Sujay
‎2010 Aug 19 2:34 PM
Hi,
Try this,
If amount_field gt '-1' and amount_field lt '1'.
Thanks,
Venkat
Edited by: venkatramana k on Aug 19, 2010 7:05 PM
‎2010 Aug 19 2:52 PM
you have decimals in the field? You're being affected by the rounding for that data type? Try something like:
data: lv_low(5) type p decimals 1 value '-1.0', "or same type as your data.
lv_high(5) type p decimals 1 value '1.0'.
If <field> gt lv_low and <field> lt lv_high.
‎2010 Aug 19 2:53 PM
TYPES : BEGIN Of TP_VAL1,
val1 TYPE p DECIMALS 2,
end of tp_val1.
DATA: wl_val1 type tp_val1,
t_val1 TYPE STANDARD TABLE OF tp_val1,
w_custom TYPE int2.
l_val1-val1 = '1.2'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '0.9'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '-0.6'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '1.9'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '-1.6'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '1.49'. APPEND wl_val1 to t_val1.
wl_val1-val1 = '-1.46'. APPEND wl_val1 to t_val1.
clear w_custom.
LOOP AT t_val1 INTO wl_val1.
IF wl_val1-val1 LE '1' AND wl_val1-val1 GT '1'. "Same as what you have given
ADD 1 TO w_custom.
ENDIF.
ENDLOOP.
The output i'm getting is 2 ( which is correct )
Can you check again? I don't believe there is a problem in the IF statement. Problem could be in the data type of amount_field.
Thanks
Sujay
‎2010 Aug 19 6:42 PM
I dont think you need a lt and gt
if lv_val between '-1' and '1'.
endif.
Also check the decimals places, type i will just convert the decimal value to its nearest integer.
‎2010 Aug 19 9:34 PM
Nothing wrong with the IF condition.
Amount type declaration is converting the amount to the nearest integer that is one. In debugging you will see the value and understand why the IF condition is failing
‎2010 Aug 19 10:47 PM
nothing wrong with the if the problem can be the rounding try using 1 decimal or use
DATA: ZM_PRUEBA(3) TYPE P DECIMALS 2 VALUE '1.2'.
IF ZM_PRUEBA BETWEEN 1 and -1.
WRITE: 'fail'.
ELSE.
WRITE: 'done'.
ENDIF.