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

Tuning performance for Loop inside loop

Former Member
0 Likes
1,156

Hi Friends,

I am writing a report to compare the uploaded legacy vendor data with that of existing vendor data in sap.

So one of the comparision is name, i am doing like below.


LOOP AT LT_SAP_DATA INTO LS_SAP_DATA.
IF NOT LS_SAP_DATA-NAME1 IS INITIAL.

 CONDENSE LS_SAP_DATA-NAME1 NO-GAPS.
 TRANSLATE LS_SAP_DATA-NAME1 TO 
 LOWER CASE.

  READ TABLE LT_LEGACY_DATA INTO
  LS_LEGACY_DATA
   WITH KEY VENDORNAME = LS_SAP_DATA-NAME1.

IF SY-SUBRC NE 0.
LOOP AT LT_LEGACY_DATA INTO LS_LEGACY_DATA
            WHERE VENDORNAME CS LS_SAP_DATA-NAME1.

Here i am capturing based on the comparison.

ENDLOOP.

ENDIF.
ENDIF.
ENDLOOP.

but for 15000 legacy data and 15000 SAP data if i am comparing with name, with loop inside loop, its going for time out error.

Is there any better way of doing this other than uploading legacy data in smaller chunks?

Any help on this is highly appreciated.

regards,

Simha

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
925

Hello Simha

At least you can do some tuning of your coding which might help to overcome the timeout:


DATA: ld_idx      TYPE i,
          ld_next     TYPE i.

SORT lt_legacy_data BY vendorname.  " for BINARY SEARCH

LOOP AT LT_SAP_DATA INTO LS_SAP_DATA
               WHERE NOT ( name1 IS INITIAL ). 
" IF NOT LS_SAP_DATA-NAME1 IS INITIAL.
 
 CONDENSE LS_SAP_DATA-NAME1 NO-GAPS.
 TRANSLATE LS_SAP_DATA-NAME1 TO 
 LOWER CASE.
 
  READ TABLE LT_LEGACY_DATA INTO
  LS_LEGACY_DATA
   WITH KEY vendorname = LS_SAP_DATA-NAME1
   BINARY SEARCH.
 
  IF SY-SUBRC NE 0.
    LOOP AT LT_LEGACY_DATA INTO LS_LEGACY_DATA
            WHERE VENDORNAME CS LS_SAP_DATA-NAME1.
 
"Here i am capturing based on the comparison.
 
  ENDLOOP.
 
  ENDIF.
"ENDIF.
ENDLOOP.

Regards

Uwe

7 REPLIES 7
Read only

uwe_schieferstein
Active Contributor
0 Likes
925

Hello Simha

Regarding nested loop the blog of Rob Burbank [SAP Network Blog: Performance of Nested Loops|] is a "Must Read".

Regards

Uwe

Read only

0 Likes
925

Hi Uwe,

Thanks for that input.

I read the blog from Rob Burbank and was quiet informative, but here in my case i can neither user Parallel cursor or Indexed loop as i am comparing the names with operator 'CS', so i can't neglect already looped iterations by catching the index.

Is there any other efficient way?

Thanks,

Simha

Read only

Former Member
0 Likes
925

Hi Simha,

You can do this way

LOOP AT LT_SAP_DATA INTO LS_SAP_DATA.
IF NOT LS_SAP_DATA-NAME1 IS INITIAL.
 
 CONDENSE LS_SAP_DATA-NAME1 NO-GAPS.
 TRANSLATE LS_SAP_DATA-NAME1 TO 
 LOWER CASE.
 
  READ TABLE LT_LEGACY_DATA INTO
  LS_LEGACY_DATA
   WITH KEY VENDORNAME = LS_SAP_DATA-NAME1.
 
 IF SY-SUBRC EQ 0. 
   Here i am capturing based on the comparison.
 ENDIF.

ENDIF.
ENDLOOP.

Best regards,

raam

Read only

0 Likes
925

Hi Raam,

there is a small change in my code which i didn't paste earlier.

I am taking if read is successful at fist instance and even if read is unsuccessful then only i am going for nested loop.


LOOP AT LT_SAP_DATA INTO LS_SAP_DATA.
IF NOT LS_SAP_DATA-NAME1 IS INITIAL.
 
 CONDENSE LS_SAP_DATA-NAME1 NO-GAPS.
 TRANSLATE LS_SAP_DATA-NAME1 TO 
 LOWER CASE.
 
  READ TABLE LT_LEGACY_DATA INTO
  LS_LEGACY_DATA
   WITH KEY VENDORNAME = LS_SAP_DATA-NAME1.
 
 IF SY-SUBRC EQ 0. 
   Here i am capturing based on the comparison.
 ELSE.
     LOOP AT LT_LEGACY_DATA_FRMT INTO LS_LEGACY_DATA
            WHERE VENDORNAME CS LS_SAP_DATA-NAME1.
      ENDLOOP.
 ENDIF.
 
ENDIF.
ENDLOOP.

Read only

Former Member
0 Likes
925

Hi,

This could be useful to u.

  • Entries: 100 (ITAB1), 1000 (ITAB2)

  • Line width: 100

  • Both tables sorted by key K

I = 1.

LOOP AT ITAB1 INTO WA1.

LOOP AT ITAB2 INTO WA2 FROM I.

IF WA2-K <> WA1-K.

I = SY-TABIX.

EXIT.

ENDIF.

" ...

ENDLOOP.

ENDLOOP.

Rgds.,

subash

Read only

uwe_schieferstein
Active Contributor
0 Likes
926

Hello Simha

At least you can do some tuning of your coding which might help to overcome the timeout:


DATA: ld_idx      TYPE i,
          ld_next     TYPE i.

SORT lt_legacy_data BY vendorname.  " for BINARY SEARCH

LOOP AT LT_SAP_DATA INTO LS_SAP_DATA
               WHERE NOT ( name1 IS INITIAL ). 
" IF NOT LS_SAP_DATA-NAME1 IS INITIAL.
 
 CONDENSE LS_SAP_DATA-NAME1 NO-GAPS.
 TRANSLATE LS_SAP_DATA-NAME1 TO 
 LOWER CASE.
 
  READ TABLE LT_LEGACY_DATA INTO
  LS_LEGACY_DATA
   WITH KEY vendorname = LS_SAP_DATA-NAME1
   BINARY SEARCH.
 
  IF SY-SUBRC NE 0.
    LOOP AT LT_LEGACY_DATA INTO LS_LEGACY_DATA
            WHERE VENDORNAME CS LS_SAP_DATA-NAME1.
 
"Here i am capturing based on the comparison.
 
  ENDLOOP.
 
  ENDIF.
"ENDIF.
ENDLOOP.

Regards

Uwe

Read only

0 Likes
925

Thanks Uwe, i will sort and read with binary search but can't loop with where condition as i am having other validations before comparing with Name so have to loop with out any conditions.

Thanks for your help.

I am closing this thread as answered.