0% found this document useful (0 votes)
12 views6 pages

5 - SAP ABAP - Operators

The document provides an overview of operators in SAP ABAP, categorized into Arithmetic, Comparison, Bitwise, and Character String Operators. It details the functionality and examples of each operator type, including how they manipulate variables and perform operations. Additionally, it explains automatic type conversion during comparisons and provides sample code snippets for practical understanding.

Uploaded by

akhter
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

5 - SAP ABAP - Operators

The document provides an overview of operators in SAP ABAP, categorized into Arithmetic, Comparison, Bitwise, and Character String Operators. It details the functionality and examples of each operator type, including how they manipulate variables and perform operations. Additionally, it explains automatic type conversion during comparisons and provides sample code snippets for practical understanding.

Uploaded by

akhter
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Page 1 of 6

SAP ABAP - Operators


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
Arithmetic operators are used in mathematical expressions in the same way that they
are used in algebra. The following list describes arithmetic operators. Assume integer
variable A holds 20 and variable B holds 40.

S.No. Arithmetic Operator & Description

+ (Addition)
1
Adds values on either side of the operator. Example: A + B will give 60.

− (Subtraction)
2 Subtracts right hand operand from left hand operand. Example: A − B will give
-20.

* (Multiplication)
3
Multiplies values on either side of the operator. Example: A * B will give 800.

/ (Division)
4
Divides left hand operand by right hand operand. Example: B / A will give 2.

MOD (Modulus)
5 Divides left hand operand by right hand operand and returns the remainder.
Example: B MOD A will give 0.

Example

REPORT YS_SEP_08.
DATA: A TYPE I VALUE 150,
B TYPE I VALUE 50,
Result TYPE I.

https://www.tutorialspoint.com/sap_abap/sap_abap_operators.htm 1/6
Page 2 of 6

Result = A / B.
WRITE / Result.

The above code produces the following output −

Comparison Operators
Let’s discuss the various types of comparison operators for different operands.

S.No. Comparison Operator & Description

= (equality test). Alternate form is EQ.


1 Checks if the values of two operands are equal or not, if yes then condition
becomes true. Example (A = B) is not true.

<> (Inequality test). Alternate form is NE.


2 Checks if the values of two operands are equal or not. If the values are not
equal then the condition becomes true. Example (A <> B) is true.

> (Greater than test). Alternate form is GT.


3 Checks if the value of left operand is greater than the value of right operand.
If yes then condition becomes true. Example (A > B) is not true.

< (Less than test). Alternate form is LT.


4 Checks if the value of left operand is less than the value of right operand. If
yes, then condition becomes true. Example (A < B) is true.

>= (Greater than or equals) Alternate form is GE.


5 Checks if the value of left operand is greater than or equal to the value of right
Operand. If yes, then condition becomes true. Example (A >= B) is not true.

<= (Less than or equals test). Alternate form is LE.


6 Checks if the value of left operand is less than or equal to the value of right
operand. If yes, then condition becomes true. Example (A <= B) is true.

a1 BETWEEN a2 AND a3 (Interval test)


7 Checks whether a1 lies in between a2 and a3 (inclusive). If yes, then the
condition becomes true. Example (A BETWEEN B AND C) is true.

IS INITIAL
The condition becomes true if the contents of the variable have not changed
8
and it has been automatically assigned its initial value. Example (A IS INITIAL)
is not true

https://www.tutorialspoint.com/sap_abap/sap_abap_operators.htm 2/6
Page 3 of 6

IS NOT INITIAL
9 The condition becomes true if the contents of the variable have changed.
Example (A IS NOT INITIAL) is true.

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.

Following is the order of preference −

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

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

The above code produces the following output −

A is less than B

Example 2

REPORT YS_SEP_08.

DATA: A TYPE I.

https://www.tutorialspoint.com/sap_abap/sap_abap_operators.htm 3/6
Page 4 of 6

IF A IS INITIAL.
WRITE: / 'A is assigned'.
ENDIF.

The above code produces the following output −

A is assigned.

Explore our latest online courses and learn new skills at your own pace. Enroll and
become a certified expert to boost your career.

Bitwise Operators
ABAP also provides a series of bitwise logical operators that can be used to build Boolean
algebraic expressions. The bitwise operators can be combined in complex expressions
using parentheses and so on.

S.No. Bitwise Operator & Description

BIT-NOT
Unary operator that flips all the bits in a hexadecimal number to the opposite
1
value. For instance, applying this operator to a hexadecimal number having
the bit level value 10101010 (e.g. 'AA') would give 01010101.

BIT-AND
2 This binary operator compares each field bit by bit using the Boolean AND
operator.

BIT-XOR
3 Binary operator that compares each field bit by bit using the Boolean XOR
(exclusive OR) operator.

BIT-OR
4 Binary operator that compares each field bit by bit using the Boolean OR
operator.

For example, following is the truth table that shows the values generated when applying
the Boolean AND, OR, or XOR operators against the two bit values contained in field A
and field B.

Field A Field B AND OR XOR

0 0 0 0 0

0 1 0 1 1

https://www.tutorialspoint.com/sap_abap/sap_abap_operators.htm 4/6
Page 5 of 6

1 0 0 1 1

1 1 1 1 0

Character String Operators


Following is a list of character string operators −

S.No. Character String Operator & Description

CO (Contains Only)
1
Checks whether A is solely composed of the characters in B.

CN (Not Contains ONLY)


2
Checks whether A contains characters that are not in B.

CA (Contains ANY)
3
Checks whether A contains at least one character of B.

NA (NOT Contains Any)


4
Checks whether A does not contain any character of B.

CS (Contains a String)
5
Checks whether A contains the character string B.

NS (NOT Contains a String)


6
Checks whether A does not contain the character string B.

CP (Contains a Pattern)
7
It checks whether A contains the pattern in B.

NP (NOT Contains a Pattern)


8
It checks whether A does not contain the pattern in B.

Example

REPORT YS_SEP_08.
DATA: P(10) TYPE C VALUE 'APPLE',
Q(10) TYPE C VALUE 'CHAIR'.
IF P CA Q.

WRITE: / 'P contains at least one character of Q'.


ENDIF.

The above code produces the following output −

https://www.tutorialspoint.com/sap_abap/sap_abap_operators.htm 5/6
Page 6 of 6

P contains at least one character of Q.

https://www.tutorialspoint.com/sap_abap/sap_abap_operators.htm 6/6

You might also like