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

reading multiple records

ABAPER_P
Participant
0 Likes
2,716

I have two internal tables it_0008 and it_0035 and I have many records in first itab as well as second table

how to read the multiple records in second itab .


present code is


  LOOP AT it_0008 INTO wa_0008.

endloop.


now I have to loop second itab (it_0035) based on condition pernr of first itab must match with pernr with second itab and also there are multiple records present in it_0035 with same perner number


condition should match wa_008-pernt = it_0035 pernr


if we use loop inside loop there will be performance issue

how to solve this.


17 REPLIES 17
Read only

soumik_de2
Participant
0 Likes
1,806

use parallel cursor.

Read only

0 Likes
1,806

can u elaborate how to use ?

Read only

0 Likes
1,806

Hi,

Parallel cursor is the technique to increase the performance of the program, when there are nested loops. A mandatory prerequisite before using the approach is that the internal tables are sorted by the respective key fields.

Please use the code mentioned below in the thread.

Regards

Gangadhar

Read only

Former Member
0 Likes
1,806

Hi,

if it is possible to make it_0035 of type sorted table with a unique key, where PERNR is the 1st key field, or to make it of type sorted table with a non-unique key PERNR the performance will increase strongly.

Regards,

Klaus

Read only

0 Likes
1,806

i don't want to use loop inside the loop  is there ant other solution . How to read the multiple records ?

Read only

0 Likes
1,806

Your mission should not be "avoid loop inside loop" but rather "avoid performance bottlenecks".

Try out Klaus' advice, if done correctly, it should solve the issue without complicating the code like a parallel cursor algorithm would.

Thomas

Read only

matt
Active Contributor
0 Likes
1,806

I'd use a HASHED table for preference over a SORTED table. (If the key is unique and you're not using an index - which might well be what you do with parallel cursor...)

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,806

Matthew Billingham wrote:

I'd use a HASHED table for preference over a SORTED table. (If the key is unique)

I have been using HASHED tables of late as well.

Sometimes i miss the index operations which i could do on SORTED tables, e.g., deleting inside the loop. I'm sure i'll get more comfortable as i continue to use them.

BR,

Suhas

Read only

ABAPER_P
Participant
0 Likes
1,806

i don't want to use loop inside the loop  is there ant other solution . How to read the multiple records ?

Read only

matt
Active Contributor
0 Likes
1,806

Thomas Zloch wrote:

Your mission should not be "avoid loop inside loop" but rather "avoid performance bottlenecks".

Try out Klaus' advice, if done correctly, it should solve the issue without complicating the code like a parallel cursor algorithm would.

Do you understand that? It is entirely correct.

Read only

former_member223133
Active Participant
0 Likes
1,806

Hi,

Make use of parallel cursor technique. Sample code is below.

DATA : lv_tabix TYPE sy-tabix.

SORT IT_0008 by PERNR.

SORT IT_0035 by PERNR.

LOOP AT IT_0008 INTO WA_0008.

READ TABLE IT_0035 TRANSPORTING NO FIELDS WITH KEY

   PERNR = WA_0008-PERNR BINARY SEARCH

IF sy-subrc EQ 0.

lv_tabix = sy-tabix.

LOOP AT it_0035 INTO wa_0035 FROM lv_tabix.

IF WA_0008-PERNR NE WA_0008-PERNR.

EXIT.

ENDIF.

Logial ABAP statements ………..

ENDLOOP.

ENDIF.

ENDLOOP.

Regards

Gangadhar

Read only

0 Likes
1,806

READ TABLE IT_0035 will read only one record but it has multiple records with same perner


like


8 SALY 2008.12.31 2008.01.01 2009.01.21

8 SALY 2009.12.31 2009.01.01 2009.08.27

Read only

0 Likes
1,806

Hi

that read statement used to get the index number where pernr = wa_008-pernt  matches.

then the inside loop statement starts the loop from the respective pernr..

no problem if ur having multiple records in it_0035.

you can write ur Logial ABAP statements inside loop as gangadhar suggested.

Read only

0 Likes
1,806

Do not use SORT and BINARY SEARCH. Use a SORTED table.


Or a HASHED one.


These were introduced over FIFTEEN years ago. Why does everyone go on about BINARY SEARCH!

Read only

former_member192842
Participant
0 Likes
1,806

This message was moderated.

Read only

gurunathkumar_dadamu
Active Contributor
0 Likes
1,806

This message was moderated.

Read only

Former Member
0 Likes
1,806

This message was moderated.