When you are looping a main table and getting entries from other table based on it , the performance gets hampered as we are doing loop inside a loop. There is one solution to reduce the performance burden. That is Parallel cursor.
Suppose you are displaying the delivery of SD items using LKIP and LIPS tables. In normal approach you will loop into LIKP (Delivery Header) and get the delivery items data (LIPS data) 


The code will look like this:


LOOP AT it_likp INTO wa_likp.
   LOOP AT it_lips INTO wa_lips WHERE vbeln EQ wa_likp-vbeln.
      " Do Something
   ENDLOOP.
ENDLOOP.
Now the problem is not with first loop. It’s with second loop. The search criteria wa_likp-vbeln will be scanned each time till it’s found in it_lips table.



But we can optimize it like this:

Sort each table based on primary key.

Then if it_lips is sorted, we can use binary search to retrieve the first occurrence of entry in second table and then from that position we can loop in second table.
The code will look like this.
LOOP AT it_likp INTO wa_likp.
    READ TABLE it_lips TRANSPORTING NO FIELDS WITH KEY vbeln = wa_likp-vbeln BINARY SEARCH.
    lv_index = sy-tabix.
   LOOP AT it_lips INTO wa_lips FROM lv_index WHERE vbeln EQ wa_likp-vbeln.
   " Do Something
  ENDLOOP.
ENDLOOP.
This will save a lot of processing time in case of huge entries in likp and lips internal table. But make sure you are sorting the table properly.



Serkan AKKAVAK
Computer Engineer
serkurumsal@yandex.com