ABAP 7.5 - FILTER Statement
There are two internal tables, say, itab1 and itab2. Both are of the same definition. If the entries in itab2 should not be present in itab1, we use FILTER function along with 'EXCEPT IN'.
There are two internal tables, say, itab1 and itab2. Both are of the same definition. If only the entries in itab2 should be present in itab1, we use FILTER function along with 'IN'.
FILTER required SORTED / HASHED internal tables.
Example program is below.
REPORT zag_75_filter1.
TYPES: BEGIN OF lty_filter,
field1 TYPE i,
field2 TYPE i,
END OF lty_filter,
ltt_filter TYPE SORTED TABLE OF lty_filter WITH NON-UNIQUE KEY field1 field2.
DATA: lt_main TYPE ltt_filter,
lt_filter TYPE ltt_filter,
lt_out TYPE ltt_filter.
lt_main = VALUE ltt_filter( ( field1 = 1 field2 = 2 )
( field1 = 1 field2 = 3 )
( field1 = 2 field2 = 4 ) ).
WRITE / 'Main data:'.
LOOP AT lt_main ASSIGNING FIELD-SYMBOL(<lfs_data>).
WRITE: / <lfs_data>-field1, space, <lfs_data>-field2.
ENDLOOP.
lt_filter = VALUE ltt_filter( ( field1 = 1 field2 = 3 ) ).
WRITE / 'Filter Input:'.
LOOP AT lt_filter ASSIGNING <lfs_data>.
WRITE: / <lfs_data>-field1, space, <lfs_data>-field2.
ENDLOOP.
*-> Applying filter to the main internal table
lt_out = FILTER ltt_filter( lt_main EXCEPT IN lt_filter
WHERE field1 = field1 AND
field2 = field2 ).
WRITE / 'Filter Output:'.
LOOP AT lt_out ASSIGNING <lfs_data>.
WRITE: / <lfs_data>-field1, space, <lfs_data>-field2.
ENDLOOP.
There are two internal tables, say, itab1 and itab2. Both are of the same definition. If only the entries in itab2 should be present in itab1, we use FILTER function along with 'IN'.
FILTER required SORTED / HASHED internal tables.
Example program is below.
REPORT zag_75_filter1.
TYPES: BEGIN OF lty_filter,
field1 TYPE i,
field2 TYPE i,
END OF lty_filter,
ltt_filter TYPE SORTED TABLE OF lty_filter WITH NON-UNIQUE KEY field1 field2.
DATA: lt_main TYPE ltt_filter,
lt_filter TYPE ltt_filter,
lt_out TYPE ltt_filter.
lt_main = VALUE ltt_filter( ( field1 = 1 field2 = 2 )
( field1 = 1 field2 = 3 )
( field1 = 2 field2 = 4 ) ).
WRITE / 'Main data:'.
LOOP AT lt_main ASSIGNING FIELD-SYMBOL(<lfs_data>).
WRITE: / <lfs_data>-field1, space, <lfs_data>-field2.
ENDLOOP.
lt_filter = VALUE ltt_filter( ( field1 = 1 field2 = 3 ) ).
WRITE / 'Filter Input:'.
LOOP AT lt_filter ASSIGNING <lfs_data>.
WRITE: / <lfs_data>-field1, space, <lfs_data>-field2.
ENDLOOP.
*-> Applying filter to the main internal table
lt_out = FILTER ltt_filter( lt_main EXCEPT IN lt_filter
WHERE field1 = field1 AND
field2 = field2 ).
WRITE / 'Filter Output:'.
LOOP AT lt_out ASSIGNING <lfs_data>.
WRITE: / <lfs_data>-field1, space, <lfs_data>-field2.
ENDLOOP.
Comments
Post a Comment