SAP NetWeaver AS ABAP Release 751, ©Copyright 2017 SAP AG. All rights reserved.
ABAP - Keyword Documentation → ABAP - Reference → Processing Internal Data → Internal Tables → Expressions and Functions for Internal Tables → FILTER - Filter Operator →FILTER - Filter Table
Syntax
... FILTER type( itab [EXCEPT] IN ftab [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 values from an internal table ftab. In the WHERE condition, the columns of itab are compared with the values of the columns of the table key of the rows of the filter table ftab. Those rows in itab are used for which at least one row in ftab meets the WHERE condition or for which there is no row in ftab when EXCEPT is specified.
Here, the filter table ftab must have at least one sorted key or one hash key used for access. This can be
This variant of the filter operator is not possible for an internal table ftab without a sorted key or hash key. This variant does not place any requirements on the table keys of itab. ftab is a functional operand position.
Note
The row types of itab and ftab do not need to be identical.
Example
Filtering three rows of the internal table carriers.
SELECT *
FROM scarr
INTO TABLE @DATA(carriers).
DATA filter TYPE SORTED TABLE OF scarr-carrid
WITH UNIQUE KEY table_line.
filter = VALUE #( ( 'AA ' ) ( 'LH ' ) ( 'UA ' ) ).
cl_demo_output=>display( FILTER #(
carriers IN filter WHERE carrid = table_line ) ).
... USING KEY keyname
Effect
Table key keyname specified with
which the WHERE condition is evaluated. A sorted key or a hash key of the
filter table ftab can be specified. If the primary key of ftab
is not a sorted key or hash key, ftab 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 filter is a standard table without a primary key.
SELECT *
FROM scarr
INTO TABLE @DATA(carriers).
DATA filter TYPE STANDARD TABLE OF scarr-carrid
WITH EMPTY KEY
WITH UNIQUE SORTED KEY line COMPONENTS table_line.
filter = VALUE #( ( 'AA ' ) ( 'LH ' ) ( 'UA ' ) ).
cl_demo_output=>display( FILTER #(
carriers IN filter USING KEY line
WHERE carrid = table_line ) ).
... 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 variant with the filter table, key components of the filter table ftab must be specified for the right operands f1, f2, and so on. On the left side, components of the internal table itab must be specified that are compatible with the right side.
Notes
Executable Examples