ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Internal Tables → Expressions and Functions for Internal Tables → FILTER - Filter Operator → Examples of Table Filtering
Table Filtering, Filter Table.
This example demonstrates various types of table filtering using a filter table.
Other versions:
7.31 | 7.40 | 7.54
Source Code
cl_demo_output=>new(
)->next_section( 'itab'
)->write( itab
)->next_section( 'ftab'
)->write( ftab
)->next_section(
'FILTER #( itab IN ftab WHERE table_line = table_line )'
)->write(
FILTER #( itab IN ftab WHERE table_line = table_line )
)->next_section(
'FILTER #( itab EXCEPT IN ftab WHERE table_line = table_line )'
)->write(
FILTER #( itab EXCEPT IN ftab WHERE table_line = table_line )
)->next_section(
'FILTER #( itab IN ftab WHERE table_line > table_line )'
)->write(
FILTER #( itab IN ftab WHERE table_line > table_line )
)->next_section(
'FILTER #( itab IN ftab WHERE table_line <> table_line )'
)->write(
FILTER #( itab IN ftab WHERE table_line <> table_line )
)->next_section(
'FILTER #( itab IN ftab WHERE table_line <= table_line )'
)->write(
FILTER #( itab IN ftab WHERE table_line <= table_line )
)->display( ).
Description
A table itab
contains five random numbers between 1 and 7, a table
ftab contains five random numbers between 3 and 10. Various types of table filter for itab
are performed using the table ftab
as a filter table:
- The first filtering creates a table of all rows from
itab
for which there is at least one row with the same value inftab
.
- The second filtering creates a table of all rows from
itab
for which there is no row with the same value inftab
.
- The third filtering creates a table of all rows from
itab
for which there is at least one row with a lesser value inftab
.
- The fourth filtering creates a table of all rows from
itab
for which there is at least one row with a non-equal value inftab
.
- The fifth filtering creates a table of all rows from
itab
for which there is at least one row with a greater or lesser value inftab
.
When merged, the results from the first and second filtering are all rows from itab
.
The first filtering creates the union and the second filtering the difference of the two tables itab
and ftab
.
The fourth filtering does not produce the same result as the second filtering. The fifth filtering does not produce the rows from itab
that remain after the third filtering.