Application Development 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: 

reading multiple records

mahabaleshwar_patil
Participant
0 Kudos

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

soumik_de2
Participant
0 Kudos

use parallel cursor.

0 Kudos

can u elaborate how to use ?

0 Kudos

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

former_member195402
Active Contributor
0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

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...)

0 Kudos

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

mahabaleshwar_patil
Participant
0 Kudos

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

0 Kudos

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.

former_member223133
Active Participant
0 Kudos

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

0 Kudos

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

0 Kudos

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.

0 Kudos

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!

former_member192842
Participant
0 Kudos

This message was moderated.

gurunathkumar_dadamu
Active Contributor
0 Kudos

This message was moderated.

Former Member
0 Kudos

This message was moderated.