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

Function Module

Former Member
0 Likes
597

Hi Guys,

I have a condition where I need to round off the number:

1st case: 15/2= 7.5 then it should return 8

IInd cse : 13/3 = 4.3 then it should return 4

and IIIrd case: 17/3= 5.67 then it should return 6

So is tehre any function module that will help me out.

Thanks

Rajeev gupta

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
572

Rajeev,

<b>

J_1I6_ROUND_TO_NEAREST_AMT</b>.

Thanks

Aneesh.

6 REPLIES 6
Read only

Former Member
0 Likes
572

Check with below FM's :

ROUND_AMOUNT

ROUND

if you need any other FM's ,just goto SE37 Transaction -> search like round -> here you get list of FM's

Thanks

Seshu

Read only

Former Member
0 Likes
572

Hi,

Observe the below code which is useful for you .

**************************************************

REPORT RAMESH.

*trunc, ceil and

data:A TYPE P LENGTH 5 DECIMALS 2,

B TYPE P LENGTH 5 DECIMALS 2,

C TYPE P LENGTH 5 DECIMALS 2,

A1 TYPE I,

B1 TYPE I,

C1 TYPE I.

A = '7.5'.

A1 = CEIL( A ).

WRITE:/ A1.

B = '4.3'.

B1 = TRUNC( B ).

WRITE: / B1.

C = '5.67'.

C1 = CEIL( C ).

WRITE:/ C1.

************************************************

Regards

Ramesh mavilla.

Read only

Former Member
0 Likes
573

Rajeev,

<b>

J_1I6_ROUND_TO_NEAREST_AMT</b>.

Thanks

Aneesh.

Read only

0 Likes
572

Thanks for the reply Aneesh, can you be more specific about the function module. I mean can you help me out how to use it.

Thanks

Rajeev Gupta

Read only

0 Likes
572

DATA: out TYPE i.

DATA: input TYPE f.

DATA : v_input(10) TYPE c.

input = '10.1'.

DATA : v_dec(2) TYPE c,

v_value(10) TYPE c.

DATA : v_sign TYPE c.

v_input = input.

SPLIT v_input AT '.' INTO v_value v_dec.

IF v_dec GE 5.

v_sign = '+'.

ELSE.

v_sign = '-'.

ENDIF.

CALL FUNCTION 'ROUND'

EXPORTING

  • DECIMALS = 0

input = input

sign = v_sign

IMPORTING

output = out

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 out.

Read only

Former Member
0 Likes
572

Just use a integer to store the values:

DATA: I1 TYPE I.

DATA: I2 TYPE I.

DATA: I3 TYPE I.

I1 = 15 / 2.

I2 = 13 / 3.

I3 = 17 / 3.

WRITE:/ I1, I2, I3.

result: 8, 4 and 6.