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

Integer Power Function ipow

This example demonstrates the integer power function ipow.

Source Code

REPORT demo_ipow.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.
    DATA n TYPE i.
    DATA arg1 TYPE p DECIMALS 1.
    DATA arg2 TYPE i.
*   DATA arg2 TYPE int8.

    n = 2.
    arg1 = `1.2`.
    DATA(out) = cl_demo_output=>new(
      )->write( |**  : { arg1 ** n }|
      )->write( |ipow: { ipow( base = arg1 exp = n ) }| ).

    cl_demo_output=>line( ).

    n = 30.
*   n = 62.
    arg2 = 2.
    out->write( |**  : { arg2 ** n }|
      )->write( |ipow: { ipow( base = arg2 exp = n ) }| ).

    out->display( ).
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  demo=>main( ).

Description

The program demonstrates that the integer power function ipow can be used to achieve more precise results than with the arithmetic operator **. In the cases shown here, the operator ** produces the calculation type f. If ipow is used, the calculation type is determined by the arguments arg1 and arg2.