Indexes

You can search a table for data records which satisfy certain search criteria faster using an index.

An index can be considered to be a copy of a database table which 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.

The primary index is distinguished 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 primary index is created automatically when the table is created. You can also create further indexes on a table in the ABAP Dictionary. These are called secondary indexes.

Table SBOOK in the Flight Model contains the flight bookiings. The primary index of the table consists of all the key fields of the table.

A booking can be made by a travel agency. In this case the number of the travel agency is entered in field AGENCYNUM.

Table SBOOK contains a large number of entries. When making enquiries, it is often necessary to look for the bookings made by a certain travel agency. Such enquiries can be processed faster if a secondary index is created with field AGENCYNUM.

When you define the index in the ABAP Dictionary, you can define the databases on which it should be created. Such a restriction makes sense for example if the index only provides a gain in performance for certain database systems.

All the indexes existing in the ABAP Dictionary for a table are normally created on the database when the table is created if this possibility was not excluded in the index definition for this database system.

Index Identifier

Several indexes on the same table are distinguished using a three-place index identifier. The index identifier may only contain letters and digits. The value ‘0 ‘ is reserved for the primary index.

The index name on the database follows the convention <table name>~<index name>. TEST ~A is the name of the corresponding database index for table TEST and index identifier A.

Since the convention for defining the index name on the database has changed several times, some of the indexes on the database might not follow this convention.

Indexes created prior to Release 3.0 can have an 8-place name, the first 7 places (possibly filled with underlining) for the table names and the eighth place for the (one-place) index identifier (for example TEST___A).

Indexes introduced in Release 3.0 can have a 13-place name on the database, the first 10 places (possibly filled with underlining) for the table names and the 11th to 13th places for the 3-place index name (for example TEST______A).

Unique Index

An entry in an index can refer to several records which have the same values for the index fields. A unique index does not permit these multiple entries. The index fields of a unique index thus have key function, that is they already uniquely identify each record of the table.

The primary index of a table is always a unique index since the index fields form the key of the table, uniquely identifying each data record.

You can define a secondary index as a unique index when you create it. This ensures that there are no double records in the table fields contained in the index. An attempt to maintain an entry in the table which violates this condition results in termination due to a database error.

The accessing speed does not depend on whether or not an index is defined as a unique index. A unique index is simply a means of defining that certain field combinations of data records in a table are unique.

A unique index for a client-dependent table must contain the client field.

See also:

When should Secondary Indexes be Created?

Creating Secondary Indexes