ABAP provides a rich set of operators to manipulate variables. All ABAP operators are classified into four categories −
Arithmetic Operators
Comparison Operators
Bitwise Operators
Character String Operators
一、Arithmetic Operators
Operators
Description
+
Addition
-
Subtraction
*
Multiplication
/
Division
MOD
Modulus
Example
1
2
3
4
5
6
REPORT YS_SEP_08.
DATA: A TYPE I VALUE 150,
B TYPE I VALUE 50,
Result TYPE I.
Result = A / B.
WRITE / Result.
Output
1
3
二、Comparison Operators
Operators
Description
= or EQ
Equality
<> or NE
Inequality
> or GT
Greater than
< or LT
Less than
>= or GE
Greater than or equals
<= or LE
Less than or equals
a1 BETWEEN a2 AND a3
Internal inclusive
IS INITIAL
CONTENTS NOT CHANGEDAND has been ASSIGNED ITS INITIAL VALUE
IS NOT INITIAL
CONTENTS CHANGED
NOTE - If the data type or length of the variables does not match then automatic conversion is performed. Automatic type adjustment is performed for either one or both of the values while comparing two values of different data types. The conversion type is decided by the data type and the preference order of the data type.
If one field is of type I, then the other is converted to type I.
If one field is of type P, then the other is converted to type P.
If one field is of type D, then the other is converted to type D. But C and N types are not converted and they are compared directly. Similar is the case with type T.
If one field is of type N and the other is of type C or X, both the fields are converted to type P.
If one field is of type C and the other is of type X, the X type is converted to type C.
Example 1
1
2
3
4
5
6
7
REPORT YS_SEP_08.
DATA: A TYPE I VALUE 115,
B TYPE I VALUE 119.
IF A LT B.
WRITE: / 'A is less than B'.
ENDIF
Output1
1
A is less than B
Example2
1
2
3
4
5
6
REPORT YS_SEP_08.
DATA: A TYPE I.
IF A IS INITIAL.
WRITE: / 'A is assigned'.
ENDIF.
Output2
1
A is assigned.
三、Bitwise Operators
Operators
Description
BIT-NOT
非
BIT-AND
与
BIT-XOR
与或
BIT-OR
或
四、Character String Operators
Operators
Description
CO
Contains Only Checks whether A is solely composed of the characters in B
CN
NOT Contains Only Checks whether A contains characters that are not in B
CA
Contains Any Checks whether A contains at least one character of B
NA
NOT Contains Any Checks whether A does not contain any character of B
CS
Contains a String Checks whether A contains the character string B
NS
NOT Contains a String Checks whether A does not contain the character string B
CP
Contains a Pattern Checks whether A contains the pattern in B
NP
NOT Contains a Pattern Checks whether A does not contain the pattern in B