ABAP Rounding function
There are a number of function methods for processing data in ABAP , involving rounding of two (and possibly more):ROUND and hr_nz_rounding_decimals
The former is located in the basis function development package Szme inside, in the standard for the calculation of units of measurement;
The latter is mainly used in the HR module, located in the PB43 development Package, processing the master data in the HR module.
hr_nz_rounding_decimals The function can enter a numeric value directly and then enter a decimal point to be preserved in the conv_dec parameter to output.
The ROUND function is somewhat flexible and can be controlled up or down by the sign parameter (' + ', '-').
For example:
Enter 88.54350, if sign = ' + ', retain 2 decimal places, will get: 88.55000; if sign = '-', you will get: 88.54000
Input-88.54350, if sign = ' + ', retains 2 decimal places, will get:-88.54000; if sign = '-', you will get:-88.55000
To view an example:
| 01020304050607080910111213141516171819202122232425262728293031323334353637383940 |
DATA : dat TYPE p DECIMALS 9 VALUE ‘12.5445‘ , dat1 TYPE p DECIMALS 9 . DATAdat2 TYPE p DECIMALS 9 VALUE ‘12.540‘. * 方法一 CALL FUNCTION ‘HR_NZ_ROUNDING_DECIMALS‘ EXPORTING value_in = dat conv_dec = 2" 设置保留几位小数 IMPORTING value_out = dat1 EXCEPTIONS no_rounding_required = 1 decimals_greater_than_10 = 2 rounding_error = 3 OTHERS= 4. WRITE: /‘方法一(保留2位小数):‘. WRITE: / dat, ‘ => ‘ ,dat1. WRITE: / ‘----------------------------------------------------‘. * 方法二 CALL FUNCTION ‘ROUND‘ EXPORTING decimals = 0" 保留多少位小数 input = dat2 sign = ‘+‘" + 向上取舍 - 向下取舍 (负数也一样) IMPORTING output = dat1" 输出返回结果 EXCEPTIONS input_invalid = 1 overflow = 2 type_invalid = 3 OTHERS= 4. WRITE: /‘方法二(保留0位小数):‘. WRITE: / dat2, ‘ => ‘ ,dat1. WRITE: / ‘----------------------------------------------------‘. |
ABAP Rounding function