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

Division

Former Member
0 Likes
909

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
Read only

bpawanchand
Active Contributor
0 Likes
878

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
Read only

bpawanchand
Active Contributor
0 Likes
879

Hi

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

var1 = var2 div var3.

write :
  var1.

Regards

Pavan

Read only

Former Member
0 Likes
878

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

Read only

Former Member
0 Likes
878

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.

Read only

Former Member
0 Likes
878

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.

Read only

Former Member
0 Likes
878

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

Read only

Former Member
0 Likes
878

Thanks a lot experts.

Read only

Former Member
0 Likes
878

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.