Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com

Index in SAP ABAP



Purpose: Index makes the data base search faster.


How it works:


Index can be considered as a copy of the database reduced to certain fields.  The copy generated at the time of creation of index is always in sorted form which makes the search faster. This index table also contains a field which contains the pointer to the actual record in the table.


Types of Index:

  1. Primary Index.
  2. Secondary Index.



Primary Index:

  1. Primary index contains all the key fields of the table and a pointer to the non key fields.
  2. It is automatically created at the time of creation of table.


Let us take an example table scounter.


The structure of the table is as shown below.





The primary index created at the time of creation of table will contains all primary key and a pointer to the non key fields. The primary index table will contains field like mandt carrid countnum and pointer in a sorted order.




The above example demonstrates how the primary index table will look like and the pointer refers to position where the same record in the sorted primary table is available in the actual database table which you can see with the highlighted Red line.


Secondary Index:

We can also add our own index to the table known as secondary index. We create secondary index for the non key fields. The secondary indexes are only to be created when these fields are used extensively in search.


In the above mentioned table consider a scenario where I wanted to fetch the record from the database based on the airport code which is actually a non-key field.  Sorting of the primary keys will not be of any use as the airport code will still be scattered. A secondary index for the field airport code needs to be created to support the faster access.



Creating a secondary index:


Step 1: Go to the Tcode SE11. Enter the table name and choose display mode.





Step 2:


Click on the indexes button.








Step 3 :


Click on the create index button.





Step 4:


Enter the name for the index in the popup and press enter.







Step 5:


Enter the short description and the field name in the displayed screen,




Save and activate.


The secondary index for the field airport is now created.


The structure of the secondary index which we created now will contain mandt airport and  pointer column which will be in the sorted form as shown below.



Now when I select the records using the airport code, then the system will identify the list of records for the airport code in the index table and fetch the corresponding records using the pointer which you can see through the highlighted color red for the airport search LCY.


There are two types of secondary indexes.


  1. Non-Unique Index
  2. Unique Index


Which you can choose through option





Unique Index:


An entry in an index can refer to several records that 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.


Suppose if I create the index as a Unique index for the field airport then the system will not allow the duplication of the record similar to LCY highlighted in the red in the secondary index table.


The use of unique index does not influence the speed it simply means that certain combinations of the fields in the table are unique.


Note: A unique index for client dependent table must contain the field mandt.



The optimizer of the database decides whether the index has to be used for search so index may only result in gaining the performance.








Key Points when creating the secondary index.


* The first field in the index must be the one which have constant value for the large number of selections.


Suppose if I have four fields in the index field1 field2 field3 and field4 for the table “TABLE” then field1 has more constant values than other fields.


My index table structure will be like field1, field2, field3 field4 and pointer in a sorted form by the four fields and I specify a select query like.


Select * from table TABLE into table IT_TABLE where field1 = condition

                                                                                      and Field2 = condition

                                                                                    and field4 = condition.


Since the third field of the index has not been mentioned, sorting the index table only to two fields will be of use. 


The system will select the set of records for the field1 and field2 quickly and then finds the record for the field4 from the selected set.



* Only those fields that significantly restrict the set of results in a selection are rational for an index.


Suppose if I create an index for the address table ADRTAB with field’s tile, first name and last name and if I write my select query like.

Select * from adrtab into table it_adrtab where title = “Mr” and first name = “X” and last name = “Y”.

Since there won’t be many peoples with the same name and same title, it is not sensible to create an index in a combination like this where as title can be considered as there will be may people with the same title.




About Arun


  1. For organizations betting their business programming application stages, nonstop insight is an absolute necessity have. Data Analytics Courses

  2. wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and also add rss. keep us updated.

  3. very well explained. I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Logistic Regression explained
    Correlation vs Covariance
    Simple Linear Regression
    data science interview questions
    KNN Algorithm


  4. Way cool! Some admirable sentiments! I appreciate you writing this article and furthermore the remainder of the site is great.

  5. Terrific post thoroughly enjoyed reading the blog and more over found to be the tremendous one. In fact, educating the participants with it's amazing content. Hope you share the similar content consecutively.
    Data Analytics Course in Raipur

  6. Thanks for posting the best information and the blog is very helpful.data science interview questions and answers

  7. Extremely overall quite fascinating post. I was searching for this sort of data and delighted in perusing this one. Continue posting. A debt of gratitude is in order for sharing. data analytics course in delhi

  8. This is good site and nice point of view.
    Data science course in pune


Powered by Blogger.