Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Numerical Calculations →  Numerical Functions →  Examples of numerical functions 

Rounding Function: Round

This example demonstrates the following rounding function: Round.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: number  TYPE decfloat34,
          rounded TYPE decfloat34,
          off     TYPE i.
    get_modes( ).
    SKIP TO LINE 1.
    LOOP AT modes INTO mode.
      off = sy-tabix  * 18 + 2.
      WRITE AT off mode-name LEFT-JUSTIFIED.
    ENDLOOP.
    SKIP TO LINE 3.
    DO 21 TIMES.
      number = - ( sy-index - 11 ) / 10.
      WRITE /(4) number.
      LOOP AT modes INTO mode.
        rounded = round( val = number dec = 0 mode = mode-value ).
        off = sy-tabix * 18.
        WRITE AT off(4) rounded.
      ENDLOOP.
    ENDDO.

Description

For fraction numbers between 1 und -1, the program depicts the effect of all rounding types from the CL_ABAP_MATH class in a classic list. The program reads the possible rounding types using the RTTI and sorts them by name.