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

Performance mach table

Former Member
0 Likes
795

Moved to correct forum by moderator

Hi to everybody

Sorry for my simple question.

I'm programming with abap to few time

I would kown if is more fast/performance use:

loop at itab1.

loop at itab2 where......

..........

endloop.

endloop.

*******************************************************

or

*******************************************************

loop at itab1

read table itab2- WITH KEY binary search.

endloop.

********************************************************

I ask this because I created a program and I must run in background otherwise it goes in dump time out.

Thanks e good work

Edited by: Matt on Dec 4, 2008 11:49 AM

7 REPLIES 7
Read only

Former Member
0 Likes
756

Hi

Always the 2nd option is preferred. Just keep in mind that table needs to be sorted by the same keys by which ur reading it when using BINARY SEARCH.

Cheers

Ravish

Read only

Former Member
0 Likes
756

HI,

Check this way....

REPORT zparallel_cursor.

TABLES:

likp,

lips.

DATA:

t_likp TYPE TABLE OF likp,

t_lips TYPE TABLE OF lips.

DATA:

w_runtime1 TYPE i,

w_runtime2 TYPE i,

w_index LIKE sy-index.

START-OF-SELECTION.

SELECT *

FROM likp

INTO TABLE t_likp.

SELECT *

FROM lips

INTO TABLE t_lips.

GET RUN TIME FIELD w_runtime1.

SORT t_likp BY vbeln.

SORT t_lips BY vbeln.

LOOP AT t_likp INTO likp.

LOOP AT t_lips INTO lips FROM w_index.

IF likp-vbeln NE lips-vbeln.

w_index = sy-tabix.

EXIT.

ENDIF.

ENDLOOP.

ENDLOOP.

GET RUN TIME FIELD w_runtime2.

w_runtime2 = w_runtime2 - w_runtime1.

WRITE w_runtime2.

Read only

Former Member
0 Likes
756

Thanks Ravish for your advice.

Read only

matt
Active Contributor
0 Likes
756

>

> I would kown if is more fast/performance use:

>

> loop at itab1.

> loop at itab2 where......

> ..........

> endloop.

> endloop.

> *******************************************************

> or

> *******************************************************

> loop at itab1

> read table itab2- WITH KEY binary search.

>

> endloop.

If itab2 has a unique key, define it as a HASHED table. Otherwise as a SORTED table. Then you can use:

loop at itab1
  read table itab2- WITH TABLE KEY...
endloop.

No "BINARY SEARCH" needed. This gives the best performance.

Read only

ThomasZloch
Active Contributor
0 Likes
756

It also depends whether there is just one or more entries in itab2 for every loop pass of itab1. If just one, go for READ. If more than one, you can use LOOP AT itab2 WHERE..., but make sure that itab2 is defined as sorted or hashed table with a key that corresponds to the WHERE-condition. Then there is no performance problem with loop inside loop, because implicit binary search is being used.

Thomas

Read only

Former Member
0 Likes
756

Hi,

Really try this blog from Siegfried about fast loop constructs - helped me a lot:

bye

yk

Read only

Former Member
0 Likes
756

simplest solution USE always SORTED Tables and you are happy!

+ no binary search

+ no hashed is anyway only for every large tables faster

+ Read is not the same as a loop, seems hard to understand ...

+ Fast loop at where on standard table, a bit complicated better read blog recommended above.

Siegfried