The Wayback Machine - https://web.archive.org/web/20240726195055/https://www.geeksforgeeks.org/relational-operators-in-sap-abap/
Open In App

Relational operators in SAP ABAP

Last Updated : 22 Dec, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

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-12

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

Operator

Function

=, EQ

returns true If two operands are equal to each other

<>, NE

returns true If two operands are not equal to each other

<, LT

returns true If first operand is less than second.

>, GT

returns true If first operand is greater than second.

<=, LE

returns true If first operand is less than or equal to second.

>=, GE

returns true If first operand is greater than or equal to second.

IS INITIAL

returns true if the variable declared is not modified

IS NOT INITIAL

returns true if the variable declared is modified

a BETWEEN b AND c (INTERVAL TEST)

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:

Operator

Function

CO (Contains Only)

returns true if A consists of only the characters in B.

CN (Not Contains ONLY)

returns true if A consists contains at least one character not present in B.

CA (Contains ANY)

returns true if A contains at least one character of B.

NA (NOT Contains Any)

 returns true if A does not contain any character present in B

CS (Contains a String)

returns true if A contains the entire string B

NS (NOT Contains a String)

returns  true if A does not contains the entire string B

CP (Contains a Pattern)

returns true if A contains the pattern in B

NP (NOT Contains a Pattern)

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


FAQs On Relational Operator in SAP ABAP

1. What is Between Operator in SAP ABAP?

Answer: Between Operator in SAP ABAP is a relational operator, it returns true if a lies in between b and c.

2. What are logical Operator in SAP ABAP?

Answer: Logical Operators are used in SAP ABAP for comparing the data. these are also known as conditional or relational operators. These operators include equal to (EQ), not equal to (NE), less than (LT), less than or equal to(LE) , greater than(GT) , and greater than or equal to (GE). Comparison operators in SAP ABAP are utilized to compare data and offer conclusions depending on the comparison’s results. Please refer the above mentioned table for more details.

3. What are Reduce Operator in SAP ABAP?

Answer: Reduce Operator in SAP ABAP is used to reduce a list of objects. it is generally used to reduce sets of data objects to a single data objects.

4. What are Ternary Operator in SAP ABAP?

Answer: There is no any Ternary Operator in SAP ABAP , but we have an alternative for doing this operation. by using the below syntax we can achieve this operation:

COND type( [let_exp]
               WHEN log_exp1 THEN [ let_exp] result1
             [ WHEN log_exp2 THEN [ let_exp] result2 ]
             ...
             [ ELSE [ let_exp] resultn ] ) ...


These relational operators are used in SAP ABAP within conditional statements (e.g., IF, CASE, etc.) to control the flow of the program based on the comparison results.



Previous Article
Next Article

Similar Reads

SAP ABAP: A complete Guide to Events in ABAP Report
SAP created the high-level programming language known as SAP ABAP (Advanced Business Application Programming) to be used for creating business applications. Reports are an essential tool for extracting and presenting data in SAP development. To manage the execution flow and improve the functionality of their systems, developers must comprehend the
5 min read
SAP S/4 HANA Vs SAP HANA | Difference between SAP S/4 HANA , SAP HANA
SAP S/4HANA is the most recent ERP suite, with advanced architecture allowing for real-time processing. SAP HANA is an in-memory database that supports S/4HANA, whereas SAP ECC is S/4HANA's traditional ERP predecessor. The distinctions are in the streamlined architecture and enhanced capabilities of S/4HANA. What is SAP S/4 HANA?SAP, which stands f
3 min read
SAP HANA Vs SAP ECC | Difference between SAP HANA and SAP ECC
SAP HANA is an in-memory database that supports S/4HANA, whereas SAP ECC is S/4HANA's traditional ERP predecessor. The distinctions are in the streamlined architecture and enhanced capabilities of S/4HANA. What is SAP HANA?SAP HANA stands for High-performance analytic appliance, which is faster than any other database management system that we use
2 min read
SAP MM Vs SAP SRM | Difference Between SAP MM and SAP SRM
SAP MM helps companies optimize their material and logistics management procedures, guaranteeing effective and economical handling of items. SAP SRM stands for Supplier Relationship Management and is an efficient tool that helps companies optimize procurement operations and helps to improve relationships with suppliers and other business vendors. W
2 min read
SAP EWM Vs SAP WM | Difference Between SAP EWM and SAP WM
SAP EWM is a version created by enhancing the SAP Warehouse Management (SAP WM) solution, one of the world’s most popular warehouse management applications, with new features. What is SAP EWM?The SAP EWM solution was created to organize and manage goods storage in warehouses, distribution centers, and logistical centers. Its primary goal is to impr
3 min read
Diffrence Between SAP and SAP ABAP(Advanced Business Application Programming)
In this article, we are going to learn the difference between an SAP and SAP ABAP. SAP ABAP is created by SAP which is a domain-specific language, it is 4th generation programming language. It is also called ABAP/4(Fourth Generation Language” or 4GL). What is SAP?SAP stands for Systems, Applications, and Products in Data Processing. It’s a German m
2 min read
Difference Between SAP ERP and SAP ABAP
In this article, we are going to learn the difference between an SAP ERP and SAP ABAP. SAP ABAP is created by SAP which is a domain-specific language, it is 4th generation programming language. It is also called ABAP/4(Fourth Generation Language” or 4GL). SAP Enterprise Resource Planning (ERP) systems are essential for simplifying and maximizing a
2 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 analyses. This article will examine the various SAP ABA
7 min read
Difference between SAP S/4 HANA , SAP HANA and SAP ECC
SAP S/4HANA is the most recent ERP suite, with advanced architecture allowing for real-time processing. SAP HANA is an in-memory database that supports S/4HANA, whereas SAP ECC is S/4HANA's traditional ERP predecessor. The distinctions are in the streamlined architecture and enhanced capabilities of S/4HANA. What is SAP S/4 HANA?SAP, which stands f
3 min read
SAP ABAP | Loop Control
Introduction to Loop Control in SAP ABAPIn SAP ABAP programming, loop control is an esse­ntial concept that allows you to execute­ a block of code multiple times. This is e­specially useful when proce­ssing data in an efficient manner. Loops help automate repetitive­ tasks and handle large datasets effectively. In ABAP, there are various types of l
4 min read
Article Tags :
three90RightbarBannerImg