‎2018 Dec 13 6:38 AM
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?
‎2018 Dec 13 7:21 AM
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 ).
‎2018 Dec 13 7:21 AM
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 ).
‎2018 Dec 13 9:06 AM
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
‎2018 Dec 13 12:47 PM
‎2018 Dec 16 9:26 AM
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
‎2018 Dec 16 12:09 PM