ABAP - Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Internal Tables →  Expressions and Functions for Internal Tables → 

FILTER - Filter Operator

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:

... EXCEPT

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.

The following can be specified for type:

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

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

Using 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'
       INTO TABLE @messages.

cl_demo_output=>display(
  FILTER #( messages EXCEPT WHERE sprsl = 'D' ) ).



Continue
FILTER - Basic Form
FILTER - Filter Table
Examples of Table Filtering