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 off the numeric fields

Former Member
0 Likes
1,034

Hi

I need a FM to round of the numeric field values

ex 13.89 should becomes 14.00

12.11 should becomes 12.00

Regards

Aditya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,000

Function Module is ROUND.

CALL FUNCTION 'ROUND'

EXPORTING

DECIMALS = 0

input = v_data

SIGN = ' '

IMPORTING

OUTPUT = v_data.

Also check the Funciton Modules:

ROUND_AMOUNT

FI_ROUND_AMOUNT

FM HR_IN_ROUND_AMT

~hitesh

8 REPLIES 8
Read only

bpawanchand
Active Contributor
0 Likes
1,000

Hi

USe CEIL

Check this snippet

DATA :
   w_p TYPE p DECIMALS 2 VALUE '13.89',
   w_p1 TYPE p DECIMALS 2 VALUE  '12.11',
   w_p2 TYPE p DECIMALS 2.



w_p2  = CEIL( w_p1 ).

WRITE :
  w_p2.
w_p2  = CEIL( w_p ).
WRITE /:
  w_p2.

Regards

Pavan

Read only

Former Member
0 Likes
1,000

Hi,

Use " ROUND " function module to round any values.

plz look at below code :

data input type F value '1.749'.
data output type p decimals 2.

CALL FUNCTION 'ROUND'
  EXPORTING
   DECIMALS            = 2
    input               = input
   SIGN                = 'X'
 IMPORTING
   OUTPUT              = output
* 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: output.

thanx.

Edited by: Dhanashri Pawar on Aug 28, 2008 7:06 AM

Read only

Former Member
0 Likes
1,000

Hi,

Please check the function module ROUND.

thanks,

Read only

Former Member
0 Likes
1,001

Function Module is ROUND.

CALL FUNCTION 'ROUND'

EXPORTING

DECIMALS = 0

input = v_data

SIGN = ' '

IMPORTING

OUTPUT = v_data.

Also check the Funciton Modules:

ROUND_AMOUNT

FI_ROUND_AMOUNT

FM HR_IN_ROUND_AMT

~hitesh

Read only

Former Member
0 Likes
1,000

Hi,

try this...

data : var(16) type p decimals 6 value '25478.36987',

val(16) type p decimals 4.

CALL FUNCTION 'ROUND'

EXPORTING

DECIMALS = 4

input = var

SIGN = '+'

IMPORTING

OUTPUT = val

  • EXCEPTIONS

  • INPUT_INVALID = 1

  • OVERFLOW = 2

  • TYPE_INVALID = 3

.

write : val.

Read only

Former Member
0 Likes
1,000

Hi Aditya,

Try the following funtion modules:

HR_NZ_ROUNDING_DECIMALS

ROUND

CALL FUNCTION 'ROUND'
    EXPORTING
      DECIMALS      = 0
      INPUT         = var1
      SIGN          = '-'
    IMPORTING
      OUTPUT        = var1
    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.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
1,000

Hi,

Regards

jana

Read only

Former Member
0 Likes
1,000

Hi,

Check out this also. Instead of using FM, simple way to convert....

DATA: a type p LENGTH 8 DECIMALS 2,
      b type i.

a = '17.25' .
b = a .

write b.

Regards,

Prem