如何在ABAP中舍入瑞士货币(法郎)的总和

时间:2010-01-21 20:48:17

标签: sap currency abap rounding

瑞士这里的货币是法郎,最小的硬币是5生丁,即0.05法郎。在SAP R / 3系统中使用编程语言ABAP来汇总金额的最佳方法是什么?

示例:

" 4.48 should round to 4.50
" 2746.24 should round to 2746.25

2 个答案:

答案 0 :(得分: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.

...如果你想根据最接近的值来向上或向下舍入。

答案 1 :(得分:1)

看起来有一个标准模块:

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控制它是向上舍入(+),向下( - )还是商业(空格)。