‎2009 Jul 06 1:24 PM
Dear All,
Please see the below code.
tables : LFM1.
data : w_menge(16) type c.
LFM1-LFABC = 'X'.
W_MENGE = '0.499'.
IF LFM1-LFABC NE SPACE AND W_MENGE NE 0.
write :'SUCCESS'.
else.
write : 'FAIL'.
endif.
In the above code if the value of W_MENGE >= 0.5, the If condition gets satisfied and SUCCESS is displayed on screen.
But if the value of W_MENGE < 0.5, the codtion fails, and FAIL is displayed on screen.
Can any one please tell me the reason?
Regards
Arindam
‎2009 Jul 06 1:27 PM
Dear,
You are using Data Type C for Your Qualityt field.
How could it do comparisons?
Regds,
Anil
‎2009 Jul 06 1:28 PM
U use the below code.---
if it_table-menge GT 0.5.
write 'SUCCESS'.
else.
write 'FAIL'.
endif.
‎2009 Jul 06 1:30 PM
Hi,
Check whther you have selected 'Fixed Point Arithmetic' while creating the program.
To check it Open the program - > Goto -> Attributes. Check it is not selected.
Regards,
Ni3
‎2009 Jul 06 1:32 PM
Hi,
Declare W_MENGE as follows.
DATA: W_MENGE type P DECIMALS 3. " NOTE dont use FLOAT because the value will be changed
This will work
Regards,
Smart Varghese
Edited by: smartvarghese on Jul 6, 2009 2:42 PM
‎2009 Jul 06 1:32 PM
Hi,
define w_menge as float ie f.
LFABC = 'x'.
W_MENGE = '0.499'.
IF LFABC NE SPACE AND W_MENGE NE 0.
write :'SUCCESS'.
else.
write : 'FAIL'.
endif.
thanks.
‎2009 Jul 06 1:32 PM
HI,
" Have 0 in quotes then you get the success message..
IF LFM1-LFABC NE SPACE AND W_MENGE NE '0'.But still it is wrong..instead taking the char take the float type and compare the field. This is the right way.
‎2009 Jul 06 1:43 PM
Thanks Avinash. I did the same put quotes.
But it looks strange why it is working fine with value 0.5 or any value greater than that.
‎2009 Jul 06 1:44 PM
Hi,
You try using 'NOT INITIAL' instead of NE 0 which is shown below
tables : LFM1.
data : w_menge(16) type c.
LFM1-LFABC = 'X'.
W_MENGE = '0.499'.
IF LFM1-LFABC NE SPACE AND W_MENGE IS NOT INITIAL."this works if the value is not blank
" if you wish to check value non zero, then you can do as said above that is
"IF LFM1-LFABC NE SPACE AND W_MENGE NE '0'.
write :'SUCCESS'.
else.
write : 'FAIL'.
endif.Regards,
Manne.
‎2009 Jul 06 2:01 PM
I got the solution for this, BUt still dont understand reason behind it.
Why is it working fine with value 0.5 or any value greater than that?
Can anyone please let me know.
Regards
Arindam
‎2009 Jul 06 2:08 PM
That is because first you were trying to compare a character field with an integer value.
if v1 ne 0.
here 0 is taking as integer and for char variable v1 it is automatically converting to integer value for comparision.
so < 0.5 convert to integer is always 0.
and > 0.5 is convert to integer as 1.
so it is converting '0.499' to 0 and give you the wrong result.
But when you add qoutes ( '0') it became a comparision between two characters field so no conversion was made between character to int.
Now for that reason you are getting the correct result.
Regards
Shiba Prasad Dutta
‎2009 Jul 06 2:11 PM
The answer is easy: rounding.
With values smaller than 0.5 it rounds to 0. Values greater than 0.5 round to 1.