SAP ABAP — Operators
Logical Operators
Bellow table shows a list of logical operators for all data types.
Example
REPORT Z_ABAP_DEVELOPER_TEST.
DATA : GV_OP1 TYPE I VALUE 4,
GV_OP2 TYPE I VALUE 5,
GV_OP3 TYPE I VALUE 4,
GV_OP4 TYPE I VALUE 6.
IF GV_OP1 < GV_OP2.
WRITE:/ GV_OP1,’<’, GV_OP2.
ENDIF.
IF GV_OP2 GT GV_OP3.
WRITE:/ GV_OP2,’>’, GV_OP3.
ENDIF.
IF GV_OP1 = GV_OP3.
WRITE:/ GV_OP1,’EQ’, GV_OP3.
ENDIF.
IF GV_OP1 <> GV_OP4.
WRITE:/ GV_OP1,’NE’,GV_OP4.
ENDIF.
Output:
Arithmetic Operators
Arithmetic operators are used in mathematical expressions to find out the solutions. We could make an example as bellow, assume integer variable A as 10 and variable B as 20.
Example
REPORT Z_ABAP_DEVELOPER_TEST.
DATA: a TYPE i,
b TYPE i,
c TYPE i,
d TYPE i.
*Using Mathematical Statement
a = 10 + 30.
b = 20–10.
c = 10 * 2.
d = 100 / 2.
WRITE:/ ‘Using Statement’.
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:
Assigning values to ABAP variables
Use ‘=’ or MOVE keyword to assign a value to a variable.
Example
REPORT Z_ABAP_DEVELOPER_TEST.
DATA: X TYPE i,
Y TYPE i,
Z TYPE i,
A TYPE i.
X = 10.
Y = X.
MOVE 40 TO Z.
MOVE Z TO A.
WRITE:/ X, Y, Z, A.
Output: