Keep a sequence and still support another lookup
A standard table can be convenient for sequential work. If the same collection also needs repeated lookups by status, a secondary key can offer that access path without changing the table’s primary category.
Declare and use the secondary key
TYPES ty_dispatches TYPE STANDARD TABLE OF ty_dispatch
WITH EMPTY KEY
WITH NON-UNIQUE SORTED KEY by_status COMPONENTS status.
READ TABLE dispatches
WITH TABLE KEY by_status COMPONENTS status = 'OPEN'
INTO DATA(found).
The secondary key is non-unique because many dispatches can share a status. A sorted key is appropriate for ordered or partial-key access; a hashed secondary key requires a complete unique lookup. The key must reflect actual use, not a speculative optimization.
Secondary keys have maintenance and memory costs, and some are built lazily when first used. Measure representative workloads before adding them. Key components also have update constraints while that key is being used.
Sources
- SAP Samples: Internal Tables — secondary table keys
- ABAP Keyword Documentation: secondary table keys
Developer practice · ABAP
Practice: read a table by status key
Declare a standard dispatch table with a non-unique sorted secondary key on status and use that key to read OPEN rows.
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-1401' status = 'OPEN' ) ).
READ TABLE dispatches WITH TABLE KEY by_status COMPONENTS status = 'OPEN' INTO DATA(found).
DATA(result) = found-dispatch_id.
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.