Hello,
Check this sample:
DATA: WA_INPUT TYPE P DECIMALS 8,
WA_OUTPUT TYPE P DECIMALS 2.
WA_INPUT = '5678.65800341'.
*
CALL FUNCTION 'ROUND'
EXPORTING
INPUT = WA_INPUT
IMPORTING
OUTPUT = WA_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: WA_OUTPUT.
Regards,
Vasanth
Hi All
Use the below code and it is so simple
For 2 decimal places
data(lv_round) = round( val = '5678.65800341' dec = 2 ).
lv_round will be 5678.66
data(lv_round) = round( val = '5678.65300341' dec = 2 ).
lv_round will be 5678.65
For 5 decimals
data(lv_round) = round( val = '5678.65800741' dec = 5 ).
lv_round will be 5678.65801
data(lv_round) = round( val = '5678.65800341' dec = 5 ).
lv_round will be 5678.65800
Thanks,
Murugan
Message was edited by: murugan bavani
Include RV64A601
rounding rule for closest interger value
FORM FRM_KONDI_WERT_601.
data: da_xkwerx(15).
unpack xkwert to da_xkwerx.
*
move '00' to da_xkwerx+13.
*
*
*
pack da_xkwerx to xkwert.
data : lgort1 like lips-lgort .
data : d1(13) , d6(13) .
data : d2 type p decimals 2 .
data : d3 type p decimals 0 .
data : d4 type p decimals 2 .
data d5(2) .
data : d8(3) .
unpack xkwert to d1 .
d2 = d1 .
d3 = d2 .
unpack d3 to d6.
d5 = d6+11(2) .
if d5 >= 50 .
d8 = 100 - d5 .
d1 = d6 + d8 .
else .
d1 = d6 - d5 .
endif .
*pack d1 to xkwert .
select single lgort into lgort1 from lips where
vbeln = komp-vgbel and
posnr = komp-vgpos .
IF SY-SUBRC = 0 .
if lgort1 = 'JSTO'.
d1 = 0 .
pack d1 to xkwert.
else .
pack d1 to xkwert.
endif .
ELSE .
pack d1 to xkwert.
ENDIF .
Hi Pradeep,
see this code..
DATA : Num1 TYPE p DECIMALS 8,
Num2(16) TYPE p DECIMALS 2,
C Type CHAR10.
Num1 = '19.64632333'.
CALL FUNCTION 'ROUND'
EXPORTING
decimals = 2
input = Num1
IMPORTING
output = Num2
EXCEPTIONS
input_invalid = 1
overflow = 2
type_invalid = 3
OTHERS = 4.
MOVE Num2 to C.
WRITE C.
Reward points if helpful..
Regards,
Goutham.
Add comment