Show TOC

Comparing Internal TablesLocate this document in the navigation structure

Like other data objects, you can use internal tables as operands in logical expressions.

If you are using internal tables with header lines, remember that the header line and the body of the table have the same name. If you want to address the body of the table in a comparison, you must place two brackets ([ ]) after the table name.

Tip

REPORT demo_int_tables_compare.

DATA: BEGIN OF line,        col1 TYPE i,        col2 TYPE i,      END OF line.

DATA: itab LIKE TABLE OF line,      jtab LIKE TABLE OF line.

DO 3 TIMES.  line-col1 = sy-index.  line-col2 = sy-index ** 2.  APPEND line TO itab.ENDDO.

MOVE itab TO jtab.

line-col1 = 10. line-col2 = 20.APPEND line TO itab.

IF itab GT jtab.  WRITE / 'ITAB GT JTAB'.ENDIF.

APPEND line TO jtab.

IF itab EQ jtab.  WRITE / 'ITAB EQ JTAB'.ENDIF.

line-col1 = 30. line-col2 = 80.APPEND line TO itab.

IF jtab LE itab.  WRITE / 'JTAB LE ITAB'.ENDIF.

line-col1 = 50. line-col2 = 60.APPEND line TO jtab.

IF itab NE jtab.  WRITE / 'ITAB NE JTAB'.ENDIF.

IF itab LT jtab.  WRITE / 'ITAB LT JTAB'.ENDIF.

The list output is:

ITAB GT JTAB

ITAB EQ JTAB

JTAB LE ITAB

ITAB NE JTAB

ITAB LT JTAB

Two tables itab and jtabare created. itab is then filled with 3 lines and assigned to jtab. Another line is added to itaband the first logical expression returns the result that itab is bigger than jtab. After appending the same line to jtab, the second logical expression tests whether both tables are equal. Then another line is appended to itab and the third logical expressions tests whether jtab is less than or equal to itab. Next, another line is appended to jtab. Its contents are different to the contents of the last line of itab. The next logical expressions test whether itab is not equal to jtab. The first table field whose contents are different in itab and jtabis col1 in the last line of the table: 30 in itab and 50 in jtab. Therefore, in the last logical expression, itab is less than jtab.