Rounding Off - Function Modules (FMs) - SAP ABAP.

There are a lot of options in SAP ABAP for rounding off a particular amount or value.


1.  J_1I6_ROUND_TO_NEAREST_AMT:  - Its a standard SAP function module that performs Rounding off the excise value functionality. This FM is to be used only for Indian Values with 2 decimal digits.

For example it will help you to round off a value like 120.49 to 120.00 or 120.51 to 121.00.




2. HR_IN_ROUND_AMT:  It's used to compute the nearest rounded off amount with respect to an index. But again you are not allowed to have a value with ore than 2 decimal digit.

Example:

Round off amount 47.42 to the nearest five Paise

O/P : 47.40



Round off amount 47.42 to the nearest rupee

O/P : 47.00

Round Off Amount 47.42 to the nearest 5 Rupee.

O/P: 45.00

Round Off Amount 47.51 to the nearest 5 Rupee.

O/P: 50.00


3. Using ROUND function: It's the most simple way of rounding off the values or amount to the required nearest decimal places.

SYNTAX:

DATA: gwa_ekpo type ekpo.

gv_ekpo-netwr = round( val = gv_ekpo-netwr dec = N ).

N stands for nearest decimal place.


EXAMPLE:

DATA(lv_round) = round(  val = '5678.65800341' dec = 2  ).
WRITE: lv_round.

DATA(lv_round1) = round(  val = '5678.65300341' dec = 2  ).
WRITE:/ lv_round1.

DATA(lv_round2) = round(  val = '5678.65800741' dec = 5 ).
WRITE:/ lv_round2.

DATA(lv_round3) = round(  val = '5678.65800341' dec = 5 ).
WRITE:/ lv_round3.


DATA(lv_round4) = round(  val = '5678.65300341' dec = 3 mode = cl_abap_math=>round_up ).
WRITE:/ lv_round4.

DATA(lv_round5) = round(  val = '5678.653'      dec = 0 mode = cl_abap_math=>round_up ).
WRITE:/ lv_round5.

DATA(lv_round6) = round(  val = '5678.001'      dec = 0 mode = cl_abap_math=>round_up ).
WRITE:/ lv_round6.

DATA(lv_round7) = round(  val = '5678.65880341' dec = 3 mode = cl_abap_math=>round_down ).
WRITE:/ lv_round7.

DATA(lv_round8) = round(  val = '5678.999'      dec = 0 mode = cl_abap_math=>round_down ).
WRITE:/ lv_round8.

DATA(lv_round9) = round(  val = '5678.001'      dec = 0 mode = cl_abap_math=>round_down ).
WRITE:/ lv_round9.


MODE: ROUND_UP
Round away from zero. Always increments the digit prior to a nonzero discarded fraction.

MODE: ROUND_DOWN
Round towards zero. Never increments the digit prior to a discarded fraction, that is, truncates.



Comments

Also Read...