ABAP - Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Internal Tables →  Internal Tables - Overview → 

Selection of Table Category

The category of table used in each individual case depends on the type of individual row access that is used most often on the table. These rules are made suitably relative to tables with secondary keys.

Example

A table scarr_tab_down intended for index access should be sorted by key field in descending order. This can only be a standard table. If you want a table in ascending order, you can and should use a sorted table, in this case scarr_tab_up. If only key access is required, then a hash table like scarr_tab_key can be used.

DATA scarr_tab_down
  TYPE STANDARD TABLE OF scarr
       WITH NON-UNIQUE KEY carrid.

DATA scarr_tab_up
  TYPE SORTED TABLE OF scarr
       WITH UNIQUE KEY carrid.

DATA scarr_tab_key
  TYPE HASHED TABLE OF scarr
       WITH UNIQUE KEY carrid.

SELECT *
       FROM scarr
       ORDER BY carrid DESCENDING
       INTO TABLE @scarr_tab_down.

scarr_tab_up = scarr_tab_down.

scarr_tab_key = scarr_tab_up.

cl_demo_output=>new(
)->write( scarr_tab_down[ 1 ]
)->write( scarr_tab_up[ 1 ]
)->write( scarr_tab_key[ carrid = 'UA' ]
)->display( ).