Original post address: http://blog.chinaunix.net/u1/40527/showart.php? Id = 336723
As we all know, SAP data is basically rounded up, but sometimes it is necessary not to rounding up or directly truncation. What should I do? Report z_barry_test_round. Data: PP1 type P decimals 3,
PP2 type P decimals 2,
PP3 type P decimals 2,
II1 type I.
PP1 = '1970. 100 '.
PP3 = PP1.
II1 = 2.
Perform noround using PP1 II1
Changing PP2.
Write: PP2, pp3 .*&--------------------------------------------------------------------*
* & Form noround
*&--------------------------------------------------------------------*
Form noround using P1 I1
Changing P2.
Data: tmpn1 (20) type N,
Tmpn2 (20) type N,
Tmpc1 (20) type C.
Tmpc1 = P1.
Split tmpc1 at '.' into tmpn1 tmpn2.
Concatenate tmpn1 '. 'tmpn2 + 0 (I1) into tmpc1.
P2 = tmpc1.
Endform. "noround or: Report
Z_barry_test.
Data
: P1 type
P Decimals
4
.
P1 = '3. 456'
.
Call
Function
'Round'
Exporting
Decimals
= 2
Input
= P1
Sign
= '-'
Importing
Output
= P1
Exceptions
Input_invalid = 1
Overflow = 2
Type_invalid = 3
Others
= 4
.
Write
P1. sign:
Space
|
: No rounding (input = output) |
'+' |
: Round Up |
'-' |
: Round down |
'X' |
: Commercial rounding |