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

Loop inise loop performance affected

Former Member
0 Likes
834

Dear Friends,

In my report we used loop inside the loop so the performance is affecting much worse. so Kindly help me to resolve this issue.

{LOOP AT it_part.

IF it_part-belnr NE it_part-rebzg AND it_part-augbl EQ ' '.

CLEAR w_count.

LOOP AT it_pos WHERE belnr = it_part-rebzg and konto = it_part-konto. " and blart = 'DZ' and blart = 'AB'.

it_part-dmshb = it_part-dmshb * -1.

it_pos-dmshb = it_pos-dmshb - it_part-dmshb.

MODIFY it_pos.

w_count = w_count + 1.

ENDLOOP.

IF w_count EQ 0.

APPEND it_part TO it_pos.

ENDIF.

ENDIF.

IF it_part-belnr EQ it_part-rebzg AND it_part-augbl NE ' '.

APPEND it_part TO it_part_filter.

ENDIF.

IF it_part-belnr EQ it_part-rebzg AND it_part-augbl EQ ' '.

CLEAR w_on_acc_total.

wa_on_acc-konto = it_part-konto.

wa_on_acc-dmshb = it_part-dmshb.

APPEND wa_on_acc TO it_on_acc.

ENDIF.}

Thanks and regards,

Karthik

Edited by: karthikani on Jun 28, 2010 4:39 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
807

Hey,

use read instead of inner loop.

LOOP AT it_part.

read it_pos with belnr = it_part-rebzg and konto = it_part-konto. " and blart = 'DZ' and blart = 'AB'.

if sy-subrc = 0.

ur code

endif.

endloop.

Hope this will help you.

Regards,

Uma Dave

7 REPLIES 7
Read only

Former Member
0 Likes
808

Hey,

use read instead of inner loop.

LOOP AT it_part.

read it_pos with belnr = it_part-rebzg and konto = it_part-konto. " and blart = 'DZ' and blart = 'AB'.

if sy-subrc = 0.

ur code

endif.

endloop.

Hope this will help you.

Regards,

Uma Dave

Read only

0 Likes
807

Hi Friend,

Itz really been very much thankful for your reply. But would you plz mention wer shud i make the changes.

Thanks and Regards,

Karthik

Read only

0 Likes
807

Hi,

Use the following logic.

{LOOP AT it_part.

IF it_part-belnr NE it_part-rebzg AND it_part-augbl EQ ' '.

CLEAR w_count.

read table it_pos with key belnr = it_part-rebzg

konto = it_part-konto.

it_part-dmshb = it_part-dmshb * -1.

it_pos-dmshb = it_pos-dmshb - it_part-dmshb.

MODIFY it_pos.

w_count = w_count + 1.

IF w_count EQ 0.

APPEND it_part TO it_pos.

ENDIF.

ENDIF.

IF it_part-belnr EQ it_part-rebzg AND it_part-augbl NE ' '.

APPEND it_part TO it_part_filter.

ENDIF.

IF it_part-belnr EQ it_part-rebzg AND it_part-augbl EQ ' '.

CLEAR w_on_acc_total.

wa_on_acc-konto = it_part-konto.

wa_on_acc-dmshb = it_part-dmshb.

APPEND wa_on_acc TO it_on_acc.

ENDIF.}

Regards,

Preetham

Read only

0 Likes
807

Hi friend preetham and dave,

Your both answer worked. But wen i checked in se30(runtime analysis) the performance criteria was still little bit high. Is anyother solution which should increase more.

If you find any plz let me know.\

Thanka and regards,

Karthik

Read only

0 Likes
807

Hi,

Check whether have you sorted the internal tables with key fields.

Regards,

Preetham

Read only

RaymondGiuseppi
Active Contributor
0 Likes
807

The LOOP where can only be optimized with an internal table of type SORTED, if the criteria of the WHERE are the keys of the table. (ref: [WHERE log_exp|http://help.sap.com/abapdocu_70/en/ABAPLOOP_AT_ITAB_COND.htm#!ABAP_ADDITION_3@3@])

If you dont want or cannot use such a type, you can use a SORT statement before the external loop, insure that the table stay sorted when you insert/update record, and replace the LOOP with a READ TABLE statement, and reading next records incrementing index, checking that the criteria is valid.

Regards,

Raymond

Read only

Former Member
0 Likes
807

Hi karthik,

Observe the changes in your code.

I am using parallel cursor approach to improve the performance of nested loop.

{LOOP AT it_part.

IF it_part-belnr NE it_part-rebzg AND it_part-augbl EQ ' '.

CLEAR w_count.

read table it_pos with key belnr = it_part-rebzg and konto = it_part-konto

IF sy-subrc = 0.

LOOP AT it_pos FROM sy-tabix. " and blart = 'DZ' and blart = 'AB'.

it_part-dmshb = it_part-dmshb * -1.

it_pos-dmshb = it_pos-dmshb - it_part-dmshb.

MODIFY it_pos.

w_count = w_count + 1.

ENDLOOP.

endif.

IF w_count EQ 0.

APPEND it_part TO it_pos.

ENDIF.

ENDIF.

IF it_part-belnr EQ it_part-rebzg AND it_part-augbl NE ' '.

APPEND it_part TO it_part_filter.

ENDIF.

IF it_part-belnr EQ it_part-rebzg AND it_part-augbl EQ ' '.

CLEAR w_on_acc_total.

wa_on_acc-konto = it_part-konto.

wa_on_acc-dmshb = it_part-dmshb.

APPEND wa_on_acc TO it_on_acc.

ENDIF.}

Regards,

Vinod