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

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.

Choose your ABAP environment

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