Basic Operations

Assigning values to ABAP variables
Use ‘=’ or MOVE keyword to assign a value to a variable.

DATA: a TYPE i,
      b TYPE i,
      c TYPE i,
      d TYPE i.

a = 10.
b = a.
MOVE 20 TO c.
MOVE c TO d.

WRITE:/ a, b, c, d.

Output
Basic-Operations-1

Basic Arithmetic Operations

DATA: a TYPE i,
      b TYPE i,
      c TYPE i,
      d TYPE i.

*Using Mathematical Expressions
a = 10 + 20.
b = 20 - 10.
c = 10 * 2.
d = 100 / 2.

WRITE:/ 'Using Expressions'.
WRITE:/ a, b, c, d.

*Using Keywords
add 10 to a.
subtract 5 from b.
multiply c by 2.
divide d by 2.

WRITE:/ 'Using Keywords'.
WRITE:/ a, b, c, d.

Output
Basic-Operations-2

Clear ABAP variables

Use keyword CLEAR to set the variables to default values.

DATA: a TYPE i,
      b TYPE i.

a = 10 + 20.
b = 20 - 10.

WRITE:/ 'Before Clear'.
WRITE:/ a, b.

clear: a, b.

WRITE:/ 'After Clear'.
WRITE:/ a, b.

Output

Basic-Operations-3


5 Comments

  1. REPORT ZHP_VAL_ASSIGN_MATH_OPER.

    DATA: a TYPE I,

    b TYPE I,

    c TYPE I,

    d TYPE I.

    a = 10 + 20.

    b = 20 – 10.

    c = 10 * 10.

    d = 20 / 10.

    WRITE :/’Using Mathematical Operation’.

    WRITE:/ a,/ b,/ c,/ d.

    WRITE:/ ‘Using Expressions’.

    Add 10 TO a.

    SUBTRACT 5 FROM b.

    MULTIPLY C BY 9.

    DIVIDE D BY 2.

    WRITE:/ a,

    / b,

    / c,

    / d.

    *Now While Using Expressions’ When I multiply by 10 then it shows O/P for c = 1.000

    Why it’s not showing 1000?

    Thanks & Regards

Leave a Reply

Your email address will not be published.


*