English 中文(简体)
How to round a sum for the swiss currency (francs)
原标题:

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
最佳回答

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).

问题回答
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.





相关问题
Helicopterview of ABAP [closed]

I don t know a thing about ABAP, apart from it has an OO side, and I would like to have some kind of helicopterview of it before I start to look at it in detail. I know I can find all of this when ...

How to round a sum for the swiss currency (francs)

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 select performance hints?

Are there general ABAP-specific tips related to performance of big SELECT queries? In particular, is it possible to close once and for all the question of FOR ALL ENTRIES IN vs JOIN?

Determine current MM periods?

The standard SAP MM advice is that only two periods can be open simultaneously. How to determine them from within the program (FM to call/table to read)?

ABAP create object

Below is a code snippet that is creating object. Form userexit_save_document_prepare. data: /bks/exitmanager type ref to /bks/exit_manager. create object /bks/exitmanager exporting ...

Parsing XML with other solution than XSLT

My company is working on a project that needs to read XML files within ABAP. When the XML file has no data for a particular tag it omits that data. Some tags are self closing. e.g. <tag /> The ...

热门标签