‎2008 Sep 08 5:35 AM
HI Experts,
I have the variables.
var1 type i,
var2 type i value 19,
var3 type i value 12.
var1 = var2 / var3.
I must get '1' as the output but it is giving the output as '2'.
Please guide me experts.
Thank you very much.
‎2008 Sep 08 5:38 AM
Hi
DATA :
var1 TYPE i,
var2 TYPE i VALUE 19,
var3 TYPE i VALUE 12.
var1 = var2 div var3.
write :
var1.Regards
Pavan
‎2008 Sep 08 5:38 AM
Hi
DATA :
var1 TYPE i,
var2 TYPE i VALUE 19,
var3 TYPE i VALUE 12.
var1 = var2 div var3.
write :
var1.Regards
Pavan
‎2008 Sep 08 5:41 AM
Hi Saravannan,
Use DIV instead of '/'.
REPORT y_test33.
data:
var1 type i,
var2 type i value 19,
var3 type i value 12.
var1 = var2 DIV var3.
write: var1.Regards,
Chandra Sekhar
‎2008 Sep 08 5:42 AM
try like this
DATA : var1 type p decimals 2,
var2 type i value 19,
var3 type i value 12.
var1 = var2 / var3.
var1 = floor( var1 ).
write:/ var1.
‎2008 Sep 08 5:42 AM
Hi Saravanan,
When you do in this way, it rounds the value to 2 since 19/12 = 1.58.
so if you want the output to be 1 go with the option 'DIV'. If you want it in decimals then declare var1 as 'type p decimals 2'.
Regards,
Swapna.
‎2008 Sep 08 5:49 AM
you are defining field as integer thats why it is rounding off the decimal part , define field like
data : abc1(6) type p decimals 2.and continue with ur program it wil work for u
‎2008 Sep 08 5:52 AM
‎2008 Sep 08 6:00 AM
Hi,
19/12 gives you 1.58.
In such cases it gives the result by rounding as 2.
And if we want the output to be 1 give 'DIV' as operator.
i.e. var1 = var2 / var3.
or
we can use FLOOR with the var1 so that it gives 1.
example :
data: var1 type p decimals 2,
var2 type p decimals 2 value 19,
var3 type p decimals 2 value 12,
var4 type i.
var1 = var2 / var3.
var4 = floor( var1 ).
write: var4.
o/p : var4 = 1.
thanx.