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

Round Function

Former Member
0 Likes
3,395

Hi,

I need to round of a value to the next number.My formula is

v_value = im_ekpo-menge/v_umrez.

v_value..i need to round off to next number. I tried using ROUND function in an enhancement. But doesn';t work .Getting msg as ROUND is unknow,protected or private

Pls help

Thanks

Ram

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,076

Hi ,,

Since you want the next number if there is a remainder , the use the mod function to determine if there is a remainder , if there is a remainder then add 1 to the result.

the code will look like this

Data : test type i.
v_value = im_ekpo-menge/v_umrez.
test = im_ekpo-menge mod v_umrez.
if test ne 0.
v_value = v_value  + 1.
endif.

Regards

Arun

6 REPLIES 6
Read only

andreas_mann3
Active Contributor
0 Likes
1,076

Hi,

use abap command write ... round:

DATA X TYPE P DECIMALS 2 VALUE '12493.97'.

WRITE: / X ROUND -2, "Ausgabe: 1.249.397,00

/ X ROUND 0, "Ausgabe: 12.493,97

/ X ROUND 2, "Ausgabe: 124,94

/ X ROUND 5. "Ausgabe: 0,12

A.

Read only

0 Likes
1,076

i want to round up total amount of invoice

from smartform where i need to write code

and what is the syntax of round statement

Read only

Former Member
0 Likes
1,076

hi,

please refer this code :

DATA:

L_MENGE_P5(16) TYPE P DECIMALS 5,

L_MENGE_P3(16) TYPE P DECIMALS 3,

L_ANDEC like T006-ANDEC value 0.

L_MENGE_P5 = '56.4456'.

CALL FUNCTION 'ROUND'

EXPORTING

DECIMALS = L_ANDEC

input = L_MENGE_P5 "over here u need to pass other than char

SIGN = '+'

IMPORTING

OUTPUT = L_MENGE_P3

EXCEPTIONS

INPUT_INVALID = 1

OVERFLOW = 2

TYPE_INVALID = 3

OTHERS = 4

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WRITE:/ L_MENGE_P3.

Read only

Former Member
0 Likes
1,076

Hi

Please check this link

-charitha

Read only

Former Member
0 Likes
1,077

Hi ,,

Since you want the next number if there is a remainder , the use the mod function to determine if there is a remainder , if there is a remainder then add 1 to the result.

the code will look like this

Data : test type i.
v_value = im_ekpo-menge/v_umrez.
test = im_ekpo-menge mod v_umrez.
if test ne 0.
v_value = v_value  + 1.
endif.

Regards

Arun

Read only

Former Member
0 Likes
1,076

Hello Prabha,

Declare v_value as TYPE i which will round it to the next number.