Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Numeric Calculations →  arith_exp - Arithmetic Expressions →  arith_exp - Arithmetic Operators 

Arithmetic Calculations

This example demonstrates the function of arithmetic operators.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA num1 TYPE decfloat34.
    cl_demo_input=>add_field( CHANGING field = num1 ).
    DATA num2 TYPE decfloat34.
    cl_demo_input=>request(   CHANGING field = num2 ).

    TRY.
        cl_demo_output=>new(
          )->write( |{ num1 } +   { num2 } = { num1 +   num2 }|
          )->write( |{ num1 } -   { num2 } = { num1 -   num2 }|
          )->write( |{ num1 } *   { num2 } = { num1 *   num2 }|
          )->write( |{ num1 } /   { num2 } = { num1 /   num2 }|
          )->write( |{ num1 } DIV { num2 } = { num1 DIV num2 }|
          )->write( |{ num1 } MOD { num2 } = { num1 MOD num2 }|
          )->write( |{ num1 } **  { num2 } = { num1 **  num2 }|
          )->display( ).
      CATCH cx_sy_arithmetic_error INTO DATA(exc).
        cl_demo_output=>display( exc->get_text( ) ).
    ENDTRY.

Description

The possible arithmetic operators are applied to numbers that can be entered.