SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Program Flow Logic → Expressions and Functions for Conditions → log_exp - Logical Expressions → rel_exp - Relational Expressions → rel_exp - Comparison Rules → rel_exp - Comparing Internal Tables →Comparing Internal Tables
This example demonstrates how internal tables are compared.
Source Code
REPORT demo_int_tables_compare .
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.
DATA: itab LIKE TABLE OF line,
jtab LIKE TABLE OF line.
DATA(out) = cl_demo_output=>new( ).
DO 3 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
APPEND line TO itab.
ENDDO.
jtab = itab.
line-col1 = 10. line-col2 = 20.
APPEND line TO itab.
IF itab > jtab.
out->write( 'ITAB > JTAB' ).
ENDIF.
APPEND line TO jtab.
IF itab = jtab.
out->write( 'ITAB = JTAB' ).
ENDIF.
line-col1 = 30. line-col2 = 80.
APPEND line TO itab.
IF jtab <= itab.
out->write( 'JTAB <= ITAB' ).
ENDIF.
line-col1 = 50. line-col2 = 60.
APPEND line TO jtab.
IF itab <> jtab.
out->write( 'ITAB <> JTAB' ).
ENDIF.
IF itab < jtab.
out->write( 'ITAB < JTAB' ).
ENDIF.
out->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
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.