Round values up to nears valueThe ROUND' command only rounds to nearest value whether it be up or down. Therefor the following code demonstrates how to always round a number DOWN ( exmaple shows from 2 decimal places to 1dp ).
*Rounds a value DOWN to 1 decimal using function module 'ROUND'
DATA: dec2 TYPE p DECIMALS 2 VALUE '22.23',
dec1 TYPE p DECIMALS 1,
ld_str(50) TYPE c.
CALL FUNCTION 'ROUND'
EXPORTING
decimals = 1
input = dec2
sign = '-' "Negative Rounding Concept
IMPORTING
output = dec1 "result will be 22.2
EXCEPTIONS
input_invalid = 1
overflow = 2
type_invalid = 3
OTHERS = 4.
*Rounds a value DOWN to 1 decimal using char manipulation
DATA: dec2 TYPE p DECIMALS 2 VALUE '22.23',
dec1 TYPE p DECIMALS 1,
ld_str(50) TYPE c.
ld_str = dec2.
SHIFT ld_str RIGHT DELETING TRAILING ' '.
SHIFT ld_str RIGHT BY 1 PLACES.
SHIFT ld_str LEFT DELETING LEADING ' '.
dec1 = ld_str. "result will be 22.2
|
||||