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

Adequate index for select

Former Member
0 Kudos
219

Hello,

I have this code :

...........................................

SELECT emkey FROM okk00

INTO TABLE gt_ods_okk

WHERE eloekz = 'X'.

IF sy-subrc EQ 0.

  • loop on the resulting internal table

LOOP AT gt_ods_okk ASSIGNING <wa_ods_okk>.

  • OKP processing

CLEAR gt_ods_okp[] .

  • for each order -> select not deleted positions (REASON_REJ EQ '' )

SELECT * FROM okp00

INTO TABLE gt_ods_okp

WHERE emkey = <wa_ods_okk>-emkey

AND reason_rej = ' '.

...................................................................................................

The problem is that if I select records from a table and have in the where clause a field which is not part of the index of the table (eloekz in my case ) , I will read all the records of the table (sequential access). So I have to be sure that there is an adequate index for my select.

I have to leave the where condition, because I need the records with eloekz = 'X'.

How can I do this ?

Suggestion ? (I can't use cursor..so other option, please ).

Many thanks.

4 REPLIES 4
Read only

Former Member
0 Kudos
184

Table okk00 doesn't exist in our system. What release are you on?

How many records in this table?

Rob

Read only

0 Kudos
184

It is not a system table.

I don't know... a few thousands....Why is this relevant?

Read only

0 Kudos
184

Because if the table is small, then it just doesn't matter if you use an index. If you just do this SELECT once in the program, it might not be much of an issue.

Rob

Read only

RaymondGiuseppi
Active Contributor
0 Kudos
184

No it shouldn't read the whole table if this table is not a cluster type, the sql "engine" will create a temporary index on the database server. (Else change database...)

What can make your program "heavy" in resource is the fact that you LOOP on the read records and then do a select one by one to read the secondary table.

You have done part of the job, checking sy-subrc after the first table read, better use a

SELECT FROM okp00 FOR ALL ENTRIES IN gt_ods_okk.

Regards