Relational operators in SAP ABAP
Last Updated :
23 Jul, 2025
Relational operators in SAP ABAP are symbols or combinations of symbols that compare values and return a Boolean result (either true or false). These operators allow developers to establish relationships between variables, constants, or expressions, facilitating decision-making processes in the program's logic. Relational operators in SAP ABAP are employed in conditional statements and expressions to control the flow of a program. They help determine whether a particular condition is true or false, guiding the program to execute specific code blocks accordingly. The relational operators in SAP ABAP include equality, inequality, greater than, less than, greater than or equal to, and less than or equal to.
Relational operators in SAP ABAP
What are Conditional/ Relational Operators in SAP ABAP?
Comparison operators in SAP ABAP are utilized to compare data and offer conclusions depending on the comparison’s results. These operators include equal to (EQ), not equal to (NE), less than (LT), less than or equal to(LT) , greater than(GT) , and greater than or equal to (GE). Here we are sharing you a table in which every comparison operator is discussed in detail.
Relational Operator for All data types in SAP ABAP
|
returns true If two operands are equal to each other
|
returns true If two operands are not equal to each other
|
returns true If first operand is less than second.
|
returns true If first operand is greater than second.
|
returns true If first operand is less than or equal to second.
|
returns true If first operand is greater than or equal to second.
|
returns true if the variable declared is not modified
|
returns true if the variable declared is modified
|
returns true if a lies in between b and c
|
Note: The above relational operators works for all data types in SAP ABAP.
Here’s an example:
DATA: value1 TYPE I VALUE 10,
value2 TYPE I VALUE 20,
result TYPE C LENGTH 1.
IF value1 EQ value2.
result = 'X'. " True
ELSE.
result = ' '. " False
ENDIF.4
Output:
False
Relational operator for char data types in SAP ABAP:
Here we are sharing you a table in which every Character string relational operator is explained:
|
returns true if A consists of only the characters in B.
|
returns true if A consists contains at least one character not present in B.
|
returns true if A contains at least one character of B.
|
returns true if A does not contain any character present in B
|
returns true if A contains the entire string B
|
returns true if A does not contains the entire string B
|
returns true if A contains the pattern in B
|
returns true if A does not contain the pattern in B
|
Example:
. DATA: P(10) TYPE C VALUE 'GFG',
Q(10) TYPE C VALUE 'GEEKS'.
IF P CA Q.
WRITE: / 'P contains at least one character of Q'.
ENDIF.
Output:
P contains at least one character of Q
Examples of Relational Operators in SAP ABAP:
Let's delve into each relational operator of SAP ABAP with examples:
Equals (=) Operator in SAP ABAP:
The Equals(=) operator in SAP ABAP Checks if two values are equal .
DATA(lv_variable1) TYPE i VALUE 5.
DATA(lv_variable2) TYPE i VALUE 5.
IF lv_variable1 = lv_variable2.
WRITE: 'Both variables are equal.'.
ENDIF.
Output:
Both variables are equal
Not Equals (<>) Operator in SAP ABAP:
The Not Equals(<>) operator in SAP ABAP Checks if two values are not equal to each other.
DATA(lv_variable1) TYPE i VALUE 5.
DATA(lv_variable2) TYPE i VALUE 10.
IF lv_variable1 <> lv_variable2.
WRITE: 'Both variables are not equal.'.
ENDIF.
Output:
Both variables are not equal
Less Than (<) Operator in SAP ABAP:
The less than (<) Operator in SAP ABAP Checks if the left operand is less than the right operand.
DATA(lv_variable1) TYPE i VALUE 5.
DATA(lv_variable2) TYPE i VALUE 10.
IF lv_variable1 < lv_variable2.
WRITE: 'Variable1 is less than Variable2.'.
ENDIF.
Output:
Variable1 is less than Variable2.
Greater Than (>) Operator in SAP ABAP:
The Greater than (>) Operator in SAP ABAP Checks if the left operand is greater than the right operand.
DATA(lv_variable1) TYPE i VALUE 15.
DATA(lv_variable2) TYPE i VALUE 10.
IF lv_variable1 > lv_variable2.
WRITE: 'Variable1 is greater than Variable2.'.
ENDIF.
Output:
Variable1 is greater than Variable2
Less Than or Equal To (<=) Operator in SAP ABAP:
The Less than or Equal to (<=) Operator in SAP ABAP Checks if the left operand is less than or equal to the right operand.
DATA(lv_variable1) TYPE i VALUE 10.
DATA(lv_variable2) TYPE i VALUE 10.
IF lv_variable1 <= lv_variable2.
WRITE: 'Variable1 is less than or equal to Variable2.'.
ENDIF.
Output:
Variable1 is less than or equal to Variable2
Greater Than or Equal To (>=) Operator in SAP ABAP:
The Greater than oe equal to (>=) Operator in SAP ABAP Checks if the left operand is greater than or equal to the right operand.
DATA(lv_variable1) TYPE i VALUE 10.
DATA(lv_variable2) TYPE i VALUE 5.
IF lv_variable1 >= lv_variable2.
WRITE: 'Variable1 is greater than or equal to Variable2.'.
ENDIF.
Output:
Variable1 is greater than or equal to Variable2
Explore
Software Engineering Basics
Software Measurement & Metrices
Software Development Models & Agile Methods
SRS & SPM
Testing & Debugging
Verification & Validation
Practice Questions