ABAP Table Index
Suppose you have a million unsorted records and you want to perform search on the basis of non primary key. Then it will take a lot of time to process all the records. In this case you will make something called Secondary Indexes or ABAP Table Index.
An Index is a sorted copy of Database which contains pointer pointing to non-key fields which is used to increase the search speed of a table.
Types of Indexes
The Primary Index is an Index created by system itself just after the creation of table. It contains only key fields. It has ID 0.
When your search criteria are not fulfilled by Primary Index, then in this case we can create our own Indexes called Secondary Indexes. Its ID can be of max 3 digit alphanumeric value. The total length of Index Name can be of 13 digit which includes table name and Index ID.
The naming convention of Secondary Indexes:
<TABLE_NAME> ~ <INDEX_ID>
e.g. ZBARRY_ALLEN ~ A.
If we define an Index as Unique Index if we want only unique records or unique combination of field in the table.
e.g. If you have defined two field combination as Unique. Then only unique values will be inserted. For more visit ABAP Documentation.
A secondary Index is temporary index and needs recreation after every upgrade. If we create Extension Index it is upgrade protected. We don’t have to do anything new, just choose Extension Index in step 02 below.
How to Create a Secondary ABAP Table Index:
Step 01: Create a table and in the maintenance screen click on Indexes. [How to Create a table: Click here]
Step 02: Choose New Icon and click Create.
Step 03: Choose Index from Drop Down box. Enter Index ID and click CONTINUE.
Step 04: Enter an explanatory Short Description.
Step 05: Choose Table Fields, choose desired fields and choose COPY.
*NOTE: The order of the field is important.
Step 06: If the values in the index are always unique then choose Unique radio button else leave it.
Step 07: According to the use of Index choose one of the radio button:
|For all database systems||If it will be used across all database systems|
|For selected database systems||If only for selected database systems. You can select at max 4.|
|Not at all in the database||If it is an exclusive Index|
Step 08: Save it, Check for Errors and Activate it.
Disadvantages of Index
More the number of ABAP Table Index, the more load on the system, as it needs to adjust Indexes every time you Insert, Update or Delete a record. Due to which Table which is written frequently must have less indexes.