Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Internal Tables →  Expressions and Functions for Internal Tables →  FILTER - Filter Operator 

FILTER - Basic Form

Other versions: 7.31 | 7.40 | 7.54

Syntax


... FILTER type( itab [EXCEPT] [USING KEY keyname] 
                       WHERE c1 op f1 [AND c2 op f2 [...]] ) ...

Extras

1. ... USING KEY keyname

2. ... WHERE c1 op v1 [AND c2 op v2 [...]]

Effect

This variant of the filter operator FILTER filters itab using single values. The columns of a table key of itab are compared with single values in the WHERE condition. Those rows of itab are used that meet the WHERE condition or do not meet it when EXCEPT is specified.

Here, the internal table itab must have at least one sorted key or one hash key used for access. This can be

  • either the primary table key used without specifying USING KEY or by specifying its name primary_key after USING KEY,

This variant of the filter operator is not possible for an internal table itab without a sorted key or hash key.


Example

Filters the messages of a work area from the database table T100 by language.

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=>write( FILTER #( messages WHERE sprsl = 'D' ) ). 
cl_demo_output=>write( FILTER #( messages WHERE sprsl = 'E' ) ). 
cl_demo_output=>display( ). 

Addition 1

... USING KEY keyname

Effect

Table key keyname specified with which the WHERE condition is evaluated. A sorted key or a hash key of the table itab can be specified. If the primary key of itab is not a sorted key or hash key, itab must have a secondary key of this type and it must be specified using USING KEY.


Example

Like the preceding example, but here a secondary table key must be specified explicitly since the internal table messages is a standard table without a primary key.

DATA messages TYPE STANDARD TABLE OF t100 
                  WITH NON-UNIQUE SORTED KEY langu COMPONENTS sprsl. 
SELECT * 
       FROM t100 
       WHERE arbgb = 'SABAPDEMOS' 
       ORDER BY msgnr 
       INTO TABLE @messages. 

cl_demo_output=>write( FILTER #( messages USING KEY langu 
                                        WHERE sprsl = 'D' ) ). 
cl_demo_output=>write( FILTER #( messages USING KEY langu 
                                        WHERE sprsl = 'E' ) ). 
cl_demo_output=>display( ). 

Addition 2

... WHERE c1 op f1 [AND c2 op f2 [...]]

Effect

A condition for the table key used in the FILTER expression must be specified after WHERE:

Multiple comparisons can be joined using AND only. There can be no further comparisons alongside those mentioned for key components. In the basic form, key components of the internal table itab must be specified for the left operands c1, c2, ... On the right side, data objects f1, f2, ... must be specified that are compatible with the left side. f1, f2, ... are general expression positions.


Notes

  • The Boolean operators NOT, OR, and EQUIV cannot be used in the WHERE condition.

Executable Example

Table Filtering, Single Values