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

Index in ABAP program

Former Member
0 Likes
2,944

Hi Guys,

I have a problem with index. I created index on VBRK table with fieldsd VKORG & FKDAT and in selection query i am using only these two fields in where condition.

Most of the times the application is running perfectly. But some times it is running too long and giving a dump.

I checked with basis & dba team, they are saying it is running on different index when it is giving a dump i.e., it is executing on different index some times.

Can anybody give me a suggestion why it is taking a different index?

Or is there any chance to give a HINT in select statement in ABAP or specifically mension the index name in select statement?

regards,

shylesh

1 ACCEPTED SOLUTION
Read only

ThomasZloch
Active Contributor
0 Likes
1,704

Hi,

this may occur when you are selecting on several different fields, not only those in the secondary index.

If too many fields are involved, the optimizer may not find the best index any more.

Possible reasons:

- table statistics are not up to date

- bug in the database software (Oracle 10 had some of those...)

- bad ABAP coding

Yes, you can use a hint to force the database to use a certain index, if you know what you're doing. But keep in mind that you are not database-independent any more with your code.

I have done this successfully with the BKPF table (90 million entries in our box...)

Greetings

Thomas

9 REPLIES 9
Read only

matt
Active Contributor
0 Likes
1,704

You can use database hints in ABAP. See OSS note 129385 for details.

matt

Read only

ThomasZloch
Active Contributor
0 Likes
1,705

Hi,

this may occur when you are selecting on several different fields, not only those in the secondary index.

If too many fields are involved, the optimizer may not find the best index any more.

Possible reasons:

- table statistics are not up to date

- bug in the database software (Oracle 10 had some of those...)

- bad ABAP coding

Yes, you can use a hint to force the database to use a certain index, if you know what you're doing. But keep in mind that you are not database-independent any more with your code.

I have done this successfully with the BKPF table (90 million entries in our box...)

Greetings

Thomas

Read only

0 Likes
1,704

Hi Thomas,

Thanks for quick reply.

Can you give me a sample code for this?

Shylesh

Read only

0 Likes
1,704

here's the code for BKPF and Oracle:

      SELECT ...
             INTO TABLE ...
             FROM BKPF
             WHERE ...
               %_HINTS ORACLE 'INDEX("BKPF" "BKPF~5")'.

replace with your table VBRK and the name of your index, e.g. VBRK~Z01.

If your DB is not Oracle, you'll have too lookup the syntax in SAP notes or online documentation.

Cheers

Thomas

Read only

JozsefSzikszai
Active Contributor
0 Likes
1,704

hi Sailesh,

did you include the MANDT field (client) into your index? It matters, when you have several clients in the system.

ec

Read only

Former Member
0 Likes
1,704

There are only two SAP delivered indexes on this table - the primary index (VBELN) and a secondary on LCNUM. It seems unlikly that any SELECT you may be using will use either of these. So I suspect that the problem is that the values you are using in the WHERE would pick up too many records to use your index effectively, so it is going for a full table scan instead.

So in this case, my guess that using Oracle HINTS would do more harm than good. Try being more restrictive in the date range.

Rob

Read only

0 Likes
1,704

Hi

I used MANDT as field in Index.

Rob, but why it is going to different index when i am using a custom one? Is SAP or Oracle will automatically use different Optimization process if it is taking long time?

Shylesh

Read only

0 Likes
1,704

The query analyser makes the decision of which index to use (if any at all) based on your where clause and the statistical distribution of the field entries (which is why the statistics need to be up to date) If the where clause is too long or complex, it may decide that it is easier to table scan.

Read only

0 Likes
1,704

See Chris's answer.

Rob