Show TOC

 IndexesLocate this document in the navigation structure

Use

You use indexes to speed up searching a table for data records that satisfy certain search criteria.

An index can be considered a copy of a database table that has been reduced to certain fields. This copy is always in sorted form. Sorting provides faster access to the data records of the table, for example using a binary search. The index also contains a pointer to the corresponding record of the actual table so that the fields not contained in the index can also be read.

Features

The system distinguishes the primary index from the secondary indexes of a table. The primary index contains the key fields of the table and a pointer to the non-key fields of the table. The system creates the primary index automatically when the table is created in the database.

Tip

Table SCOUNTER in the flight model contains the assignment of the carrier counters to airports. The primary index on this table consists of the key fields of the table and a pointer to the original data records. This is explained in the figure below.

You can also create further indexes on a table in the ABAP Dictionary. These are called secondary indexes. This is necessary if the table is frequently accessed in a way that does not take advantage of the sorting of the primary index for the access. Different indexes on the same table are distinguished with a three-place index identifier .

Tip

You want to search all the counters of carriers at a certain airport for flight bookings. The airport ID is used to search for counters for such an access. Sorting the primary index is of no use in speeding up this access. Since table SCOUNTER has a large number of entries, a secondary index on the field AIRPORT (ID of the airport) must be created to support access using the airport ID. This is explained in the following figure.

The optimizer of the database system decides whether an index must be used for a concrete table access (see How to Check if an Index is Used? ). This means that an index can result in a gain in performance only for certain database systems. You can define the database systems on which an index must be created when you define the index in the ABAP Dictionary (see Creating Secondary Indexes .)

The system creates in the database all the indexes existing in the ABAP Dictionary for a table when the table is created if this was not excluded in the index definition for this database system.

If the index fields have a key function, that is, if they already uniquely identify each record of the table, an index can be defined as a unique index .

See also:

What to Keep in Mind when Creating Secondary Indexes