###### Summary -

In this topic, we described about the below sections -

Relational operators used to compare two or more operands of any data type. Relational operators and join two or more operands of any data type to form a relational expression or comparison expression. The result of the relational expression is true or false.

There are additional relational operators for specific data types. The predicate operator "IS" qualifying an operand. If operands are of different length and different type, then automatic conversion is performed.

Automatic type conversion is performed on either one of the operand. The automatic conversion can be decided by the data type and below list shows the data type order precedence.

• If one operand is of data type I, then the other operand is converted to I.
• If one operand is of data type P, then the other operand is converted to P.
• If one operand is of data type D, then the other operand is converted to D.
• C and N types are not converted and they are compared directly.
• If one operand is of data type N and the other operand is C or X, both operands are converted to P.
• If one operand is of data type C and the other operand is X, the X type is converted to C.

#### Relational operators for all data types -

Below are the list of relational operators for all data types -

OperatorDescriptionMeaning
=, EQEqualTrue when the value of operand1 matches the value of operand2, otherwise false.
<>, NENot EqualTrue when the value of operand1 does not match the value of operand2, otherwise false.
< LTLess ThanTrue when the value of operand1 is less than the value of operand2, otherwise false.
>, GTGreater ThanTrue when the value of operand1 is greater than the value of operand2, otherwise false.
<=, LELess EqualTrue when the value of operand1 is less than or equal to the value of operand2, otherwise false.
>=, GEGreater EqualTrue when the value of operand1 is greater than or equal to the value of operand2, otherwise false.
IS INITIALINITIALThe condition becomes true if the content of the variable not changes from the value initially assigned.
IS NOT INITIALNOT INTIALThe condition becomes true if the content of the variable changed from the value initially assigned.

#### Relational operators for character-like data types -

Below are the list of relational operators for character-like data types -

OperatorDescriptionMeaning
COContains OnlyTrue when operand1 only contains characters from operand2. It is case-sensitive and trailing blanks are respected in both operands.
CNContains Not OnlyTrue when a logical expression with CO is false, that is, if operand1 contains not only characters from operand2.
CAContains AnyTrue, when operand1 contains at least one character from operand2. It is case-sensitive and trailing blanks are respected in both operands.
NAContains Not AnyTrue, when a logical expression with CA is false, that is if operand1 does not contain any characters from operand2.
CSContains StringTrue, when the content of operand2 is contained in operand1. It is not case-sensitive and trailing blanks in the left operand are respected.
NSContains No StringTrue, when a logical expression with CS is false, i.e., if operand1 does not contain the content of operand2.
CPCovers PatternTrue, when the content of operand1 fits the pattern in operand2.
NPNo PatternTrue, when a logical expression with CP is false, i.e., if operand1 does not fit the pattern operand2.

#### Relational operators for byte-like data types -

Below are the list of relational operators for byte-like data types -

OperatorDescriptionMeaning
BYTE-COContains OnlyTrue when operand1 only contains bytes out of operand2.
BYTE-CNContains Not OnlyTrue when a logical expression with BYTE-CO is false.
BYTE-CAContains AnyTrue when operand1 contains at least one byte out of operand2.
BYTE-NAContains Not AnyTrue when a logical expression with BYTE-CA is false.
BYTE-CSContains StringTrue when the content of operand2 is contained in operand1.
BYTE-NSContains No StringTrue when a logical expression with BYTE-CS is false.

#### Example -

Below example shows how the relational operations coded in the program.

#### Code -

``````*&---------------------------------------------------------------------*
*& Report  Z_RELATIONAL_OPERATORS
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*

REPORT  Z_RELATIONAL_OPERATORS.

* Declaring variables
DATA: W_OP1 TYPE I VALUE 40,
W_OP2 TYPE I VALUE 60,
W_OP3 TYPE I.

* Verifying W_OP1 less than W_OP2
IF W_OP1 LT W_OP2.
WRITE 'W_OP1 LESS THAN W_OP2'.
ENDIF.

* Verifying W_OP2 IS NOT INITIAL
IF W_OP2 IS NOT INITIAL.
WRITE /'W_OP2 IS CHANGED'.
ENDIF.

* Verifying W_OP3 IS INITIAL
IF W_OP3 IS INITIAL.
WRITE /'W_OP3 IS NOT CHANGED'.
ENDIF.
``````

#### Explaining Example -

In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.

IF W_OP1 LT W_OP2, verifying W_OP1 is LESS THAN (LT) W_OP2. If yes, display 'W_OP1 LESS THAN W_OP2'.

IF W_OP2 IS NOT INITIAL, verifying W_OP2 is not initial. If yes, displays 'W_OP2 IS CHANGED'.

IF W_OP3 IS INITIAL, verifying W_OP3 is initial. If yes, displays 'W_OP3 IS NOT CHANGED'.