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

Nested loop Performance issue

Former Member
0 Likes
971

Hi Friends,

I need to change the coding because of taking more times when in nested loopsand below is the sample code

loop at itab.

loop at itab1

loop at itab2.

..........

endloop.

endloop.

loop at itab3.

loop at itab4.

...................

endloop.

endloop.

loop at itab5.

loop at itab6.

...................

endloop.

endloop.

endloop.

Here before this loop it took only 5 seconds in compared with total 941 seconds.after that loop it took almost of time is spend on this big nested loop statement.so how to solve this this issue and what are the possible ways to reduce the time by changing the coding.pls help me to come out this issue.

Thanks,

Regards,

Rajendra Kumar.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
836

Hi,

try to read the internal tables. check the commality in different loops and try to merge the loop.

if wud be better if u can post the code here.

pls go through the below links:

/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/improvingPerformanceinNestedLoopsforInternal+Tables&

**reward if helpful

Regards,

Madhu

7 REPLIES 7
Read only

Former Member
0 Likes
837

Hi,

try to read the internal tables. check the commality in different loops and try to merge the loop.

if wud be better if u can post the code here.

pls go through the below links:

/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/improvingPerformanceinNestedLoopsforInternal+Tables&

**reward if helpful

Regards,

Madhu

Read only

Former Member
0 Likes
836

Hi..,

You can use READ TABLE statement instead of the nested LOOP ENDLOOP..

regards,

sai ramesh

Read only

Former Member
0 Likes
836

Hi Kumar,

I think if possible try joining tables during selection from the database tables to

avoid so many internal tables.

Then as mentioned above, try using read with binary search option to make it faster.

Thanks,

Babu

Read only

Former Member
0 Likes
836

Without knowing how you are using the data in these loops we cannot give you the best reply.

MattG.

Read only

0 Likes
836

HI Kumar,

T best way to avoid the Nested Loop and EndLoop.try to read the tables in place of the Loop.

Thanks & Regards,

Nelson

Read only

Sathish
Product and Topic Expert
Product and Topic Expert
0 Likes
836

What is the purpose of so many Loops. It would be better to explain the scenario with small piece of coding.

Just writing 10 loop and endloop would not help.

What are the tables used, can there be joins possible. And lot more need to be analysed.

Read only

Former Member
0 Likes
836

I am sending u some of the performence issues that to be kept in mind when coding.

1.Use appropriate Tabletype according to the requirement i.e. standerd ,hashed,sorted.

2.Avoid using Nested loops. Instead of Nested loops use READ TABLE.......WITH KEY ..........BINARY SEARCH for SINGLE RECORD access.

HASHED table has higher performance for single record access.

3.When ever using nested loops try to provide as many KEYS as possible in the where clause.

4.Always use TRANPORTING addition in READ/MODIFY statements.

5. Avoid using Control Break statements cantaining where/from/to clauses.

6.Always loop the table cantaining more records to get correct output.

7.APPEND LINES/INSERT LINES has higher performance than APPEND/INSERT

STATEMENT.