Thursday, 21 September 2017

ABAP: Comparison Operators

Below table summarizes the comparison operators supported by ABAP.

Operator
Description
= or EQ
Return true, if two variables are equal, else false
<> or NE
Return true, if two variables are not equal, else false
> or GT
var1 > var2. Return true, if var1 is greater than var2, else false
>= or GE
var1 > var2. Return true, if var1 is greater than or equal to var2, else false
< or LT
var1 > var2. Return true, if var1 is less than var2, else false
<= or LE
var1 > var2. Return true, if var1 is less than or equal to var2, else false
BETWEEN AND
‘var1 BETWEEN var2 AND var3’. Return true, if var1 is in between var2 and var2, else false.
IS INITIAL
The condition becomes true if the contents of the variable have not changed and it has been automatically assigned its initial value.
IS NOT INITIAL
The condition becomes true if the contents of the variable have changed.

Z_HELLO_WORLD
*&---------------------------------------------------------------------*
*& Report Z_HELLO_WORLD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_HELLO_WORLD.

DATA: var1 TYPE I VALUE 25,
      var2 TYPE I VALUE 10,
      var3 TYPE I VALUE 30,
      var4 TYPE I.

IF var1 = var2.
  Write 'var1 is equal to var2'.
ENDIF.

IF var1 <> var2.
  Write 'var1 is not equal to var2'.
ENDIF.

IF var1 < var2.
  Write / 'var1 is < var2'.
ENDIF.

IF var1 > var2.
  Write / 'var1 is > var2'.
ENDIF.

IF var1 <= var2.
  Write / 'var1 is <= var2'.
ENDIF.

IF var1 >= var2.
  Write / 'var1 is >= var2'.
ENDIF.

IF var2 BETWEEN var1 AND var3.
  Write / 'var2 is in between var and var3'.
ENDIF.

IF var1 IS INITIAL.
  Write / 'var1 is initialized with default value'.
ENDIF.

IF var4 IS INITIAL.
   Write / 'var4 is initialized wth default value'.
ENDIF.



Previous                                                 Next                                                 Home

No comments:

Post a Comment