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: 

Optimize a loop in a SAP standard program

Former Member
0 Kudos
349

Hi gurus,

Iv been optimizing this code.. inlcude workarea but still the same. It has 1000 records after retrieving the data from the select statement for less than 1 minute. It takes 10-12 mins in looping. I already debug it and PERFORM takes half a minute or less. So, I need to focus with the loop.

See the codes below.

[code]

SELECT (FIELD_LIST)

INTO CORRESPONDING FIELDS OF TABLE I_ZZUWT PACKAGE SIZE 1000

FROM ZZUWT CLIENT SPECIFIED

WHERE KUNNR IN SELR_KUNNR

AND RACCT IN SELR_RACCT

AND RASSC IN SELR_RASSC

AND RBUKRS IN SELR_RBUKRS

AND RDATLT IN SELR_RDATLT

AND RLDNR IN SELR_RLDNR

AND RPMAX IN SELR_RPMAX

AND RRCTY IN SELR_RRCTY

AND RVERS IN SELR_RVERS

AND RYEAR IN SELR_RYEAR

AND RCLNT IN MANDTTAB

GROUP BY (GROUP_LIST).

LOOP AT I_ZZUWT INTO ZZUWT .

  • ZZUWT = I_ZZUWT .

PERFORM PZZUWT USING I_ZZUWT-_COUNTER.

CLEAR: $RWTAB, ZZUWT .

CLEAR GLDBZ .

ENDLOOP.

ENDSELECT.

[/code]

1 ACCEPTED SOLUTION

Former Member
0 Kudos
132

hi,

1: avoid looping within a select statement,

2: try to read the database with an array fetch,

3: loop over internal table with field-symbols rather than workareas.

10 REPLIES 10

Former Member
0 Kudos
133

hi,

1: avoid looping within a select statement,

2: try to read the database with an array fetch,

3: loop over internal table with field-symbols rather than workareas.

Former Member
0 Kudos
132

can u paste the code what the perform is doing??

PERFORM PZZUWT USING I_ZZUWT-_COUNTER

may be u can optimise this.

former_member194613
Active Contributor
0 Kudos
132

Check SQL Trace of your problem

/people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy

How long does the SELECT take, how many records are read, what is the minimal time per record. Check the explain, is an index used? or is it a full table scan?

A full table scan is o.k., if you read more the 10% of the table. If less then add

the client to the WHERE condition, if you really need all clients.

Read all clients from the T000 and add WHERE mandt in (...).

Siegfried

dev_parbutteea
Active Contributor
0 Kudos
132

Hi,

do not use select and end-select!, try out the folowing:

SELECT (FIELD_LIST)

INTO CORRESPONDING FIELDS OF TABLE I_ZZUWT PACKAGE SIZE 1000

FROM ZZUWT CLIENT SPECIFIED

WHERE KUNNR IN SELR_KUNNR

AND RACCT IN SELR_RACCT

AND RASSC IN SELR_RASSC

AND RBUKRS IN SELR_RBUKRS

AND RDATLT IN SELR_RDATLT

AND RLDNR IN SELR_RLDNR

AND RPMAX IN SELR_RPMAX

AND RRCTY IN SELR_RRCTY

AND RVERS IN SELR_RVERS

AND RYEAR IN SELR_RYEAR

AND RCLNT IN MANDTTAB

GROUP BY (GROUP_LIST).

<b>if sy-subrc = 0.

LOOP AT I_ZZUWT INTO ZZUWT .

  • ZZUWT = I_ZZUWT .

PERFORM PZZUWT USING I_ZZUWT-_COUNTER.

CLEAR: $RWTAB, ZZUWT .

CLEAR GLDBZ .

ENDLOOP.

endif.</b>

Thanks and Regards,

sooness

Former Member
0 Kudos
132

To optimize this loop please follow these steps

1) remove the loop from the select and after the select use the loop.

2) don't use the CORRESPONDING FIELDS command, create the internal table as fields are selected from database table . It will increase the select performance.

Please send the code of PERFORM PZZUWT USING I_ZZUWT-_COUNTER.

Former Member
0 Kudos
132

Hi,

Avoid using SELECT...ENDSELECT.

Use FOR ALL ENTRIES rather or/ and put it into an internal table and use that internal table in the loop.

VJ

Former Member
0 Kudos
132

Hi,

Do a select into table statement. - This will fetch the entire content in one single go. Select-endselect will hit the database for every record!

then call the perform statement by passing the table content of the select statement.

You can loop inside the perform and do your modifications to the internal table.

Regards,

Shruthi

Former Member
0 Kudos
132

maui bayog,

The problem is most likely your subroutine (PERFORM). By your own admission it takes half a minute (30 seconds) to execute. For 1000 records this is multiplied by 1000. For all the 1000 records, execution of the subroutine itself should take 30,000 seconds.

If you post the subroutine code we could help you.

0 Kudos
132

Hi Mark,

I wanted to but It's too long to paste it... perform has several perform routines a I go through the inner routines these programs are SAP Standards. That's why I'm hesitant to edit the affected areas.

0 Kudos
132

Use transaction SE30 to analyse the persormance of the subroutine. It will give you a good idea which of the subroutine called withing the subroutine in question causes the performace to degrade. You can then send us the code in that subroutine and we could help you.