Use FILTER when the key supports your condition
The dispatch table contains many rows, but a work queue needs only the open ones. FILTER constructs a new internal table from matching rows. It is not a general replacement for every LOOP or WHERE; the source table needs a compatible sorted or hashed key for the filter condition.
Name the key explicitly
DATA(open_dispatches) = FILTER ty_dispatches(
dispatches
USING KEY by_status
WHERE status = 'OPEN' ).
Here, the non-unique sorted secondary key covers status, so several open rows can match. The result is a separate table; the source remains unchanged. If you need complex calculations or side effects while selecting, a loop may be more readable.
FILTER is a modern constructor expression. Check exact syntax and feature availability for the target ABAP release and language version; practice snippets are not compiled in the browser.
Sources
Developer practice · ABAP
Practice: build a table of open dispatches
Use a sorted secondary key by_status to create a new table containing only OPEN dispatches.
This choice changes the output pattern checked here: WRITE belongs in a classic executable report, while out->write( ) uses the supplied output reference in an ABAP Cloud class-run method. It does not switch the language version of the other code; check release and API availability in your target system.
Complete the task and include the output statement shown for your selected environment. Variable names can differ if you use them consistently. This browser checker checks structure only; it does not compile or run ABAP.
0 required structures detected · 0 checks
Write your solution, then check its structure.
One possible solution
TYPES: BEGIN OF ty_dispatch,
dispatch_id TYPE string,
status TYPE string,
END OF ty_dispatch.
TYPES ty_dispatches TYPE STANDARD TABLE OF ty_dispatch WITH EMPTY KEY
WITH NON-UNIQUE SORTED KEY by_status COMPONENTS status.
DATA(dispatches) = VALUE ty_dispatches( ( dispatch_id = 'D-1501' status = 'OPEN' ) ( dispatch_id = 'D-1502' status = 'CLOSED' ) ).
DATA(open_dispatches) = FILTER ty_dispatches( dispatches USING KEY by_status WHERE status = 'OPEN' ).
DATA(result) = lines( open_dispatches ).
WRITE result.out->write( result ).These are context-specific output examples. In your own program, use the result variable from your solution and the output mechanism available in that program.