FILTER Operator For Internal Tables in ABAP 7.4
FILTER Operator For Internal Tables in ABAP 7.4
4
02/06/2018
Dear saplearners, in this blog we all are going to learn about abap internal table filtering
using FILTER operator in ABAP 7.4
FILTER Operator
A new FILTER operator is available which can used on ABAP internal tables to filter the
data (or) to retrieve subset of data into a new internal table. As of ABAP 7.4 this keyword
is available to use in the system.
The result of FILTER operator is a new internal table with filtered data.
First of all, lets see how we can perform the internal table filtering in the system before
ABAP 7.4 version. I am sure that we all end up in creating a LOOP with a WHERE condition
and finally doing an APPEND to another internal table.
IF sy-subrc = 0.
x
LOOP AT lt_flights_all INTO DATA(ls_flight) WHERE carrid = 'LH'.
CLEAR: ls_flight.
ENDLOOP.
ENDIF.
that’s hell of a coding lines written for just simple task and if the complexity of filtering
logic increase we need to write more lines of ABAP code. We definitely need some change
here, is it ?
So, as of ABAP 7.4 , the FILTER keyword came into our world to save us from those extra
keyboard hits. Lets let get to know more about it with some examples.
COMPONENTS carrid,
IF sy-subrc = 0.
ENDIF.
as a result, the internal table LT_FLIGHTS_ALL is filtered on WHERE condition and filtered x
data will be available in the internal table LT_FLIGHT_LH.
Yes, that is just a line of statement to filter the data using FILTER keyword. Cool it is..!
The above example is a basic syntax form using FILTER keyword, now look at the another
syntax form with filter table
In previous example we performed the filter with a single value, now add some more filter
values. Sample code snippet will look like something below.
COMPONENTS carrid,
* Apply filters
cl_demo_output=>write_data( lt_flights_all ).
cl_demo_output=>write_data( lt_flight_final ).
cl_demo_output=>display( ).
So by using the help filter table you can apply FILTERing on internal tables. Output look
like below
Notes
Below are some points to keep in mind when using the FILTER operator
The internal table on which FILTER operator is used must have at least one sorted key
or one hash key used for access.
The row type of main internal table and result internal table do not need to be identical
The Boolean operators NOT, OR, and EQUIV cannot be used in the WHERE condition.
Congrats..! you have learned about FILTER operator, try this in you next ABAP program and x
let me know feedback. Please feel free to comment and let us know your feedback.
Subscribe for more updates.
Subscribe to our weekly newsletter and receive our latest tutorials in your inbox
email address
Subscribe
Stay Connected
Join our Telegram channel and Facebook Group