ABAP Keyword Documentation → ABAP - Reference → Program Flow Logic → Expressions and Functions for Conditions → log_exp - Logical Expressions → rel_exp - Comparison Expressions → rel_exp - Comparison Rules → rel_exp - Comparing Internal Tables
Comparing Internal Tables
This example demonstrates how internal tables are compared.
Other versions: 7.31 | 7.40 | 7.54
Source Code
TYPES: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.
DATA: itab TYPE TABLE OF line WITH EMPTY KEY,
jtab TYPE TABLE OF line WITH EMPTY KEY.
DATA(out) = cl_demo_output=>new( ).
itab = VALUE #( FOR j = 1 UNTIL j > 3
( col1 = j col2 = j ** 2 ) ).
jtab = itab.
itab = VALUE #( BASE itab
( col1 = 10 col2 = 20 ) ).
IF itab > jtab.
out->write( 'ITAB > JTAB' ).
ENDIF.
jtab = VALUE #( BASE jtab
( col1 = 10 col2 = 20 ) ).
IF itab = jtab.
out->write( 'ITAB = JTAB' ).
ENDIF.
itab = VALUE #( BASE itab
( col1 = 30 col2 = 80 ) ).
IF jtab <= itab.
out->write( 'JTAB <= ITAB' ).
ENDIF.
jtab = VALUE #( BASE jtab
( col1 = 50 col2 = 60 ) ).
IF itab <> jtab.
out->write( 'ITAB <> JTAB' ).
ENDIF.
IF itab < jtab.
out->write( 'ITAB < JTAB' ).
ENDIF.
out->display( ).
Description
Two standard tables, itab
and jtab
, are created.
itab
is filled with three rows and assigned to jtab
.
A further row is added to itab
and the first relational expression returns
the result that itab
is greater than jtab
. After
the same row has been added to jtab
, the second relational expression returns
the result that both tables are the same. Another row is added to itab
and
the third relational expression returns the result that jtab
is less than
or equal to itab
. Next, a further row is added to jtab
,
the content of which is different from the final row of itab
. The next relational
expression returns the result that itab
is not equal to jtab
.
The first table field where the contents of itab
and jtab
differ is col1
in the last row of the table, namely 30 for itab
and 50 for jtab
. In the last relational expression, itab
is therefore less than jtab
.