Application Development 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: 

Division

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

bpawanchand
Active Contributor
0 Kudos

Hi

DATA :
  var1 TYPE i,
var2 TYPE i VALUE 19,
var3 TYPE i VALUE 12.

var1 = var2 div var3.

write :
  var1.

Regards

Pavan

7 REPLIES 7

bpawanchand
Active Contributor
0 Kudos

Hi

DATA :
  var1 TYPE i,
var2 TYPE i VALUE 19,
var3 TYPE i VALUE 12.

var1 = var2 div var3.

write :
  var1.

Regards

Pavan

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Thanks a lot experts.

Former Member
0 Kudos

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.