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

Rounding the value

Former Member
0 Likes
2,737

Can i know the Function Modules for rounding a value.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,022

Hi,

Use the Function Module is ROUND.

Example ;-

CALL FUNCTION 'ROUND'
EXPORTING

DECIMALS = 0 
input = w_data

SIGN = ' ' 
IMPORTING
OUTPUT = w_data.

Best of luck,

Bhumika

14 REPLIES 14
Read only

bpawanchand
Active Contributor
0 Likes
2,022

Hi

Regards

Pavan

Read only

Former Member
0 Likes
2,023

Hi,

Use the Function Module is ROUND.

Example ;-

CALL FUNCTION 'ROUND'
EXPORTING

DECIMALS = 0 
input = w_data

SIGN = ' ' 
IMPORTING
OUTPUT = w_data.

Best of luck,

Bhumika

Read only

0 Likes
2,022

Hi,

i need rounding for the currency and quantity field.

Read only

0 Likes
2,022

Chandrika,

yes round fm will work for both type.

Amit

Read only

0 Likes
2,022

Hi,

i tried with that but i did not get. does it works for currency fields.

Read only

Former Member
0 Likes
2,022

HI,

You can make use of FM ROUND and also try using Ceil and Floor statements.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
2,022

hi,

u can use it without using the function module . here 's d example of it:-

**********BEGIN - ROUND OFF EXAMPLE**********

DATA A TYPE P DECIMALS 3.

A = '123.456'.

WRITE: / A ROUND -2,

/ A ROUND -1,

/ A ROUND 1.

**********END - ROUND OFF EXAMPLE************

i hope it might be useful to you.

Read only

former_member787646
Contributor
0 Likes
2,022

Hi

You can use the ROUND function instead of a Function Module.

Eg... y = ROUND( x ).

Hope it helps.

Murthy

Read only

Former Member
0 Likes
2,022

Data num1 type p decimals 2 value '123456.78'.

Data num2 type p decimals 0.

Data num3 type p decimals 2.

num2 =num1.

num3=num2.

Write \ num3.

Regards

rajesh

Read only

Former Member
0 Likes
2,022

Hi Chandrika,

In one of my developments I had done rounding for quantity fields as follows.

*Data declarations

DATA : lv_planned_deliv_qnty TYPE jdelquantity....

*Rounding up

lv_planned_deliv_qnty = CEIL( lv_planned_deliv_qnty ).

Note : This will round up the quantity field to nearest upper integer.

In case you want to keep only the interger part you can do the following

lv_planned_deliv_qnty = TRUNC( lv_planned_deliv_qnty ).

Hope this helps.

<removed_by_moderator>

Regards,

Swati Patnaik

Edited by: Julius Bussche on Jul 29, 2008 9:12 PM

Read only

Former Member
0 Likes
2,022

Hi Chandrika ,

It worked for currency fields as well.

I wrote a dummy code to check...see the results

DATA : lv_curr1 TYPE WRBTR VALUE '234.87',

lv_curr2 TYPE WRBTR VALUE '687.23',

lv_curr3 TYPE WRBTR,

lv_int TYPE JDELQUANTITY.

write /2: ' Before TRUNC ' , lv_curr1.

lv_int = TRUNC( lv_curr1 ).

write /2: 'AFTER TRUNC lv_int' , lv_int.

write /2: ' before Ceil ' , lv_curr2.

lv_curr3 = CEIL( lv_curr2 ).

write /2: 'after Ceil ' , lv_curr3.

Output :

Before TRUNC

234,87

AFTER TRUNC lv_int

234,000

before Ceil

687,23

after Ceil

688,00

Edited by: Swati Patnaik on Jul 29, 2008 9:17 AM

Read only

0 Likes
2,022

if i give the value as 34.65 i should get the out as 35.

as after decimal value it is greater than .50 it should give the greater value.

and in my case ceil does not work.

Read only

Former Member
0 Likes
2,022

Hi Chandrika,

Is your field TYPE CURR ???

In my case it is working fine.I have already sent you the output.

Try to use a predefined Data element for your currency field.

Say , if your Currency field lv_curr is ( 13, 2 ) Then you can use the data element WRBTR.

You can search for a suitable predefined data element in se11.

se11 --> Data Type --> Search for Data Elements --> A popup window " Input help Personal value List " appears

Click the Information System button in the bottom right side of the window.

A popup window " Repository Info System : Find Data Elements" appears

for example

enter Data element = wb*

enter the data type ( i.e., CURR ) and the desired length ( say 10 ).

A list of data elements of required type and size will appear.You can choose the one which suits your requirement.

Regards,

Swati Patnaik