1

here in switzerland our currency is francs and the smallest coin is 5 centimes which is 0.05 francs. what is the best way to round amounts to be payable with our money using the programming language ABAP in a SAP R/3 system?

examples:

" 4.48 should round to 4.50
" 2746.24 should round to 2746.25
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

2 Answers2

1
REPORT  zwvtest.

PARAMETERS: p_in  TYPE dec11_4,
            p_out TYPE dec11_4.

DATA: l_fraction    TYPE dec11_4,
      l_upper       TYPE dec11_4,
      l_delta_upper TYPE dec11_4,
      l_lower       TYPE dec11_4,
      l_delta_lower TYPE dec11_4.

AT SELECTION-SCREEN.
  l_fraction = FRAC( p_in * 10 ) / 10.
  l_upper = CEIL( l_fraction * 20 ) / 20.
  l_delta_upper = l_upper - l_fraction.
  l_lower = FLOOR( l_fraction * 20 ) / 20.
  l_delta_lower = l_fraction - l_lower.
  IF l_delta_lower < l_delta_upper.
    p_out = p_in - l_delta_lower.
  ELSE.
    p_out = p_in + l_delta_upper.
  ENDIF.

...if you want it rounded up or down depending on what's the closest value.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • thank you, but is this the only way? I thought that this kind of problem would be a common problem in the SAP world and there must be a less manually way... I have found the ROUND function-module but this didn't work. –  Jan 23 '10 at 12:51
  • If there is one, I haven't found it either. :-) – vwegert Jan 23 '10 at 12:59
1

it looks like there IS a standard module:

DATA: result TYPE dec11_4.

CALL FUNCTION 'FIMA_NUMERICAL_VALUE_ROUND'    
  EXPORTING
    i_rtype     = space
    i_runit     = '0.05'
    i_value     = '4.48'
  IMPORTING
    e_value_rnd = result.

i_rtype controls whether it is rounded up (+), down (-) or commercial (space).

  • hi flurin, is there a function from HR module? I only find rounding functions for SD and FIMA like you write. Or some kind of generic rounding function? I dont want to use a function from another module (and dont want to code it) :-) Thanks – dotchuZ Mar 08 '13 at 12:18
  • sorry, don't know the HR module –  Mar 20 '13 at 09:34