Relational operators in SAP ABAP
Last Updated :
22 Dec, 2023
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
Similar Reads
SAP Advanced Business Application Programming (ABAP)
SAP ABAP stands for Advanced Business Application Programming. SAP ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP SE. ABAP is primarily used for developing and customizing applications within the SAP ecosystem, which i
6 min read
What is SAP ABAP: A Brief Overview
SAP ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP SE. ABAP is primarily used for developing and customizing applications within the SAP ecosystem, which includes enterprise resource planning (ERP) systems and other bu
9 min read
SAP ABAP | Basic Syntax & Statements
The German software company SAP created the high-level programming language, ABAP (Advanced Business Application Programming) primarily, this language serves as a tool for developing applications within the SAP R/3 system. Designed with simplicity and ease of learning in mind, ABAP syntax allows eff
9 min read
SAP ABAP | Understanding Variables
What is a Variable?Variable are named data objects that refer to the memory location allocated during the program execution for processing. As the name indicates, users can use refer to the range of values that may be stored inside and the range of actions that can be carried out on the variable. Sy
7 min read
SAP ABAP Keywords
The core of many global enterprises, SAP ABAP stands for Advanced Business Application Programming. It is the heart and soul of SAP systems. It gives users the ability to expand and modify SAP apps to satisfy particular business needs. The fundamental building blocks of SAP ABAP are its keywords, wh
5 min read
SAP ABAP | Constants & Literals Explained
In the world of SAP ABAP (Advanced Business Application Programming), the use of Constants and Literals is necessary for the effective handling of data. Literals are used to denote specific data types such as numbers, characters, strings, and boolean values. What are Literals?Literals in programming
7 min read
SAP ABAP | Data Types
Before Understanding the Data type first understand the Data object. Data objects are variables that we declare in the program. It occupies some memory where you can store the data from external sources. Data can be of different types, so data types are responsible for defining the type of data of t
6 min read
Relational operators in SAP ABAP
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 prog
6 min read
Operators in SAP ABAP
High-level programming languages like SAP ABAP (Advanced Business Application Programming) are used to create apps in the SAP environment. Operators are essential for the execution of many different operations in SAP ABAP, ranging from straightforward arithmetic computations to complex logical analy
7 min read