‎2008 Dec 04 10:19 AM
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
‎2008 Dec 04 10:21 AM
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
‎2008 Dec 04 10:22 AM
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.
‎2008 Dec 04 10:23 AM
‎2008 Dec 04 10:52 AM
>
> 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.
‎2008 Dec 04 10:56 AM
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
‎2008 Dec 04 10:57 AM
‎2008 Dec 04 12:04 PM
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