Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

What is the sort oder when using filter #() ?

jrgkraus
Active Contributor
0 Likes
1,062

I am wondering if filter #( ) produces a defined sort order in its result. If I use for example

types table_type type standard table of line_type<br>  with default key<br>  with non-unique sorted key date components date time.

filtered_table = filter #( full_table using key date where date = today ).
data(first_row) = filtered_table[ 1 ].

Will I get in first_row the entry with the earliest time for that day?

1 ACCEPTED SOLUTION
Read only

nabheetscn
SAP Champion
SAP Champion
969

Hello Jorg

Yes when you filter using the defined key it sorts and filters it. Try this dummy code

REPORT ztest_cr.
TYPES:BEGIN OF line_type,
        date TYPE sy-datum,
        time TYPE sy-uzeit,
      END OF line_type.
TYPES table_type TYPE STANDARD TABLE OF line_type
  WITH DEFAULT KEY
  WITH NON-UNIQUE SORTED KEY key1 COMPONENTS date time.
DATA:full_table TYPE table_type.
DATA(out) = cl_demo_output=>new( ).
INSERT VALUE #( date = '20181213' time = '071901' ) INTO full_table INDEX 1.
INSERT VALUE #( date = '20181213' time = '071001' ) INTO full_table INDEX 2.
INSERT VALUE #( date = '20181213' time = '071301' ) INTO full_table INDEX 3.
INSERT VALUE #( date = '20181214' time = '071301' ) INTO full_table INDEX 4.
INSERT VALUE #( date = '20181215' time = '071301' ) INTO full_table INDEX 5.
DATA(filtered_table) = FILTER #( full_table USING KEY key1 WHERE date = sy-datum ).
DATA(first_row) = filtered_table[ 1 ].
out->write( first_row ).
5 REPLIES 5
Read only

nabheetscn
SAP Champion
SAP Champion
970

Hello Jorg

Yes when you filter using the defined key it sorts and filters it. Try this dummy code

REPORT ztest_cr.
TYPES:BEGIN OF line_type,
        date TYPE sy-datum,
        time TYPE sy-uzeit,
      END OF line_type.
TYPES table_type TYPE STANDARD TABLE OF line_type
  WITH DEFAULT KEY
  WITH NON-UNIQUE SORTED KEY key1 COMPONENTS date time.
DATA:full_table TYPE table_type.
DATA(out) = cl_demo_output=>new( ).
INSERT VALUE #( date = '20181213' time = '071901' ) INTO full_table INDEX 1.
INSERT VALUE #( date = '20181213' time = '071001' ) INTO full_table INDEX 2.
INSERT VALUE #( date = '20181213' time = '071301' ) INTO full_table INDEX 3.
INSERT VALUE #( date = '20181214' time = '071301' ) INTO full_table INDEX 4.
INSERT VALUE #( date = '20181215' time = '071301' ) INTO full_table INDEX 5.
DATA(filtered_table) = FILTER #( full_table USING KEY key1 WHERE date = sy-datum ).
DATA(first_row) = filtered_table[ 1 ].
out->write( first_row ).
Read only

jrgkraus
Active Contributor
969

to nabheet.madan3: Your answer is correct - but since you posted it as comment and not as answer I am not able to accept it. Thanks a lot

Read only

matt
Active Contributor
0 Likes
969

I've asked the moderators to change it to an answer

Read only

969

Hey,

For some reason I can't convert the comment to an answer. I will keep this thread open in case nabheet.madan3 would transform it to an answer and then you can accept it.

Best,

Iftah

Read only

0 Likes
969

Converted it to an answer, Thanks.