FILTER on Internal table using FILTER Internal Table

w13qcK1465380577New ABAP feature allows to filter one internal table based on another internal table content. 

 

 

Program

TYPESBEGIN OF ty_flt,
                  coun_from TYPE spflicountryfr,
                END OF ty_flt,
                  tt_flt TYPE HASHED TABLE OF ty_flt WITH UNIQUE KEY coun_from.
DATAlt_spfli1 TYPE TABLE OF spfli,
              lt_spfli2 TYPE TABLE OF spfli,
              lt_flt    TYPE tt_flt.
SELECT FROM spfli INTO TABLE lt_spfli1.

* Fill value on filter table LT_FLT
lt_flt VALUE tt_fltcoun_from 'US' )
                       coun_from 'DE' ).
* FILTERING apply on internal table LT_SPFLI1 based on filter table
lt_spfli2 =   FILTER #lt_spfli1 IN lt_flt
                        WHERE countryfr coun_from ).
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
  EXPORTING
    i_callback_program syrepid
    i_structure_name   ‘SPFLI’
  TABLES
    t_outtab           lt_spfli1.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
  EXPORTING
    i_callback_program syrepid
    i_structure_name   ‘SPFLI’
  TABLES
    t_outtab           lt_spfli2.


7

Output

LT_SPFLI1  table records.

8

LT_SPFLI2  records after filter. Only shows where COUNTRYFR is US or DE.

9


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s