Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Select statement for Secondary Index?

Former Member
0 Likes
807

How do u write the Select statement for Primary Index and Secondary Index?

How do u write the Select statement for Primary Index and Secondary Index?

4 REPLIES 4
Read only

Former Member
0 Likes
782

I think the determination is done by SAP at runtime. The best way is to make sure all the fields in your secondary index are used in the where condition of the select statement.

-Cheers

Read only

0 Likes
782

Hi,

Order of the fields is also important in the where clause.

Lets say you are selecting from vbap

the primay key is VBELN and POSNR. you should mention VBELN first then POSNR in the where clause.


select * from vbap into it_vbap
where vbeln = p_vbeln   " parameter on selection screen
and    posnr = p_posnr.  " parameter on selection screen

Similarly for any secodnary index also you should specify the order of the fields in the same order as mentioned in the index.

Read only

Former Member
0 Likes
782

Database optimizer will decide on usage of the index based on the where clause. We cant force the system to use selected index.

Read only

Former Member
0 Likes
782

Hi Krishna,

You provide columns(on which indexing is done) in the where clause of select statement.

However, the order is important here because filtering of records based on your where clause will be done in the order you provide your filtering conditions.

Good practice is to provide all the indexes first and then other filtering criteria in your where clause.

G@urav.