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.

TYPESBEGIN 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.

DATAlt_main   TYPE ltt_filter,
      lt_filter TYPE ltt_filter,
      lt_out    TYPE ltt_filter.

lt_main VALUE ltt_filterfield1 field2 )
                            field1 field2 )
                            field1 field2 ).

WRITE 'Main data:'.

LOOP AT lt_main ASSIGNING FIELD-SYMBOL(<lfs_data>).
  WRITE/ <lfs_data>-field1space<lfs_data>-field2.
ENDLOOP.

lt_filter VALUE ltt_filterfield1 field2 ).

WRITE 'Filter Input:'.

LOOP AT lt_filter ASSIGNING <lfs_data>.
  WRITE/ <lfs_data>-field1space<lfs_data>-field2.
ENDLOOP.

*-> Applying filter to the main internal table

lt_out FILTER ltt_filterlt_main EXCEPT IN lt_filter
                           WHERE field1 field1 AND
                                 field2 field2 ).

WRITE 'Filter Output:'.

LOOP AT lt_out ASSIGNING <lfs_data>.
  WRITE/ <lfs_data>-field1space<lfs_data>-field2.
ENDLOOP.

Comments

Popular posts from this blog

EWM PPF Trigger the existing PPF Action through Custom Program

Get Packaging Material of a Product in EWM