Description: Filter expression is part of ABAP 7.4 syntax, which is used to filter internal tables based on requirement.
- For example: You are updating data in IDOC segments, and you need to update only 2 segments. Then, you must LOOP every segment, which is not good in terms of performance.
- However, with filter you can filter out those 2 segments and run loop on them, which is quite useful.
Syntax:
- Basic Form:
FILTER type( itab [EXCEPT] [USING KEY keyname]
WHERE c1 op f1 [AND c2 op f2 [...]] )
Note: If EXCEPT is not specified, rows from internal table that satisfy the WHERE condition are selected. If EXCEPT is specified, rows that do not satisfy the WHERE condition are selected.
- Example:
*&---------------------------------------------------------------------*
*& Report ZSAN_FILTER
*&---------------------------------------------------------------------*
*& Purpose: Filter Example
*& Author : Sangeeta Singh
*&---------------------------------------------------------------------*
REPORT zsan_filter.
"Data Declarations
DATA: lt_vbak TYPE SORTED TABLE OF vbak WITH NON-UNIQUE KEY auart.
"Fetch data
SELECT * FROM vbak
INTO TABLE @lt_vbak
WHERE erdat > '20201107'.
IF sy-subrc = 0.
"Filter
lt_vbak = FILTER #( lt_vbak WHERE auart = 'ZYOR').
ENDIF.
2. Filter Table:
FILTER type( itab [EXCEPT] IN ftab [USING KEY keyname]
WHERE c1 op f1 [AND c2 op f2 [...]] )
- Example:
*&---------------------------------------------------------------------*
*& Report ZSAN_TAB_FILTER
*&---------------------------------------------------------------------*
*& Purpose: Filter Table Example
*& Author : Sangeeta Singh
*&---------------------------------------------------------------------*
REPORT zsan_tab_filter.
"Data Declarations
DATA: lt_filter TYPE SORTED TABLE OF auart WITH UNIQUE KEY table_line,
lt_vbak TYPE SORTED TABLE OF vbak WITH NON-UNIQUE KEY auart.
"Fill Filter Table
lt_filter = VALUE #( ( 'ZYOR' ) ( 'AEBO' ) ( 'OR ' ) ).
"Fetch data
SELECT * FROM vbak
INTO TABLE @lt_vbak
UP TO 100 ROWS.
IF sy-subrc = 0.
"Filter Table
lt_vbak = FILTER #( lt_vbak IN lt_filter WHERE auart = table_line ).
ENDIF.
Conclusion:
In SAP ABAP, FILTER expressions simplify data selection from internal tables. Using WHERE includes matching rows, while adding EXCEPT excludes them. This provides a clean, efficient way to handle both inclusion and exclusion in data filtering.
Thanks for Visiting!
Sangeeta Singh

Leave a Reply