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

improving loop performance

sudha_naik
Product and Topic Expert
Product and Topic Expert
0 Likes
454

Hello,

I have a nested loop which loops through two itabs. Since there are too many records in both the itabs it is taking too much of time. Could anyone please suggest some ways to improve this code so that it takes less time.

Two itabs are itab1 and itab2.

LOOP AT itab1.

CLEAR L_TABIX.

APPEND itab1 TO vsel.

READ TABLE itab2 WITH KEY cuobj = itab1-cuobj binary search.

IF sy-subrc NE 0.

CONTINUE.

ELSE.

l_tabix = sy-tabix.

LOOP AT itab2 FROM l_tabix.

IF itab2-cuobj NE itab1-cuobj.

EXIT.

ENDIF.

READ TABLE ymodes WITH KEY mode = itab2-mode.

IF sy-subrc EQ 0.

IF itab2-wtsta NE ' ' AND

CLEAR itab2-wtsta.

ENDIF.

APPEND itab2 TO wsel.

ENDIF.

ENDLOOP.

ENDIF.

ENDLOOP.

Thanks in advance

Sudha Naik

1 ACCEPTED SOLUTION
Read only

former_member194669
Active Contributor
0 Likes
434

Hi,



sort itab2 by cuobj.
sort ymodes by mode.

LOOP AT itab1.
APPEND itab1 TO vsel.
READ TABLE itab2 WITH KEY cuobj = itab1-cuobj binary search.
if sy-subrc eq 0.
READ TABLE ymodes WITH KEY mode = itab2-mode
if sy-subrc eq 0.
 LOOP AT itab2 itab2-cuobj eq itab1-cuobj.
 if itab2-wtsta NE ' '.
   cLEAR itab2-wtsta.
  ENDIF.
  APPEND itab2 TO wsel.
 endif.
 ENDLOOP.
ENDIF.
endif.
endloop.

aRs

2 REPLIES 2
Read only

Former Member
0 Likes
434

hi Sudha,

1. Sort the internal tables with all the key fields

2. use Binary Search for your second read statement too.

3. Include all the key fields in the read statement.

Regards,

Santosh

Read only

former_member194669
Active Contributor
0 Likes
435

Hi,



sort itab2 by cuobj.
sort ymodes by mode.

LOOP AT itab1.
APPEND itab1 TO vsel.
READ TABLE itab2 WITH KEY cuobj = itab1-cuobj binary search.
if sy-subrc eq 0.
READ TABLE ymodes WITH KEY mode = itab2-mode
if sy-subrc eq 0.
 LOOP AT itab2 itab2-cuobj eq itab1-cuobj.
 if itab2-wtsta NE ' '.
   cLEAR itab2-wtsta.
  ENDIF.
  APPEND itab2 TO wsel.
 endif.
 ENDLOOP.
ENDIF.
endif.
endloop.

aRs