ABAP Keyword Documentation → ABAP − Reference → Processing Internal Data → Internal Tables → Expressions and Functions for Internal Tables
FILTER - Filter Operator
Other versions:
7.31 | 7.40 | 7.54
Syntax Forms
Basic form
1. ... FILTER type( itab [EXCEPT] [USING KEY
keyname]
WHERE c1 op f1 [AND c2 op f2 [...]] ) ...
Filter table
2. ... FILTER type( itab [EXCEPT] IN ftab [USING KEY
keyname]
WHERE c1 op f1 [AND c2 op f2 [...]] ) ...
Addition
Effect
A constructor expression with the component
operator FILTER
creates a result of a table type specified using type
.
The rows are taken from an existing internal table itab
in accordance with
the condition after WHERE
, converted to the row type of type
, and inserted into the target table in accordance with the rules of
INSERT ... INTO TABLE.
- In the basic form the condition is created with single values.
- When using a filter table, the condition is created with values from the filter table
ftab
.
The following can be specified for type
:
- A non-generic table type.
- The
#
character as a symbol for the operand type. If the data type required in an operand position is not unique and not known completely, the type ofitab
is used if known.
itab
is a
functional operand position. The row type of itab
must be convertible
to the row type of the target type type
. USING KEY
can (or must) be used to specify a table key for evaluating itab
or ftab
(depending on the variant).
Notes
- Table filtering can also be performed using a
table comprehension or a
table reduction with an
iteration expression for
table iterations with
FOR
. The operatorFILTER
provides a shortened format for this special case and is more efficient to execute.
- A table filter constructs the result row by row. If the result contains almost all rows in the source table, this method can be slower than copying the source table and deleting the surplus rows from the target table.
Addition
... EXCEPT
Effect
If EXCEPT
is not specified, those rows from itab
are used that meet the WHERE
condition. If EXCEPT
is specified, those rows from itab
are used that do not meet the WHERE
condition.
Note
The addition EXCEPT
is not the same as a negation of the WHERE
condition, particularly in the variant with a
filter table.
Example
Uses the addition EXCEPT
in the basic form of the FILTER
operator.
DATA messages TYPE SORTED TABLE OF t100 WITH NON-UNIQUE KEY sprsl.
SELECT *
FROM t100
WHERE arbgb = 'SABAPDEMOS'
ORDER BY msgnr
INTO TABLE @messages.
cl_demo_output=>display(
FILTER #( messages EXCEPT WHERE sprsl = 'D' ) ).