Nested loops

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply

Nested loops

Post by Abapherion » Wed Sep 14, 2005 10:36 pm

Hi all,

Can anyone help with that? I'm currently developing a program that needs to do a 'loop' within another 'loop'? Our standards just doesn't allow this, but as of now, its the only method that I can think of. Can anybody provide me with another method?
Thanks in advance.

Posts: 929
Joined: Tue Oct 22, 2002 3:19 am
Location: The Hague

Post by ocvantol » Thu Sep 15, 2005 1:50 am

A standard that does not allow a loop within a loop is not a good standard. Sometimes you just cannot avoid it.

Look at SM30, Tips&Tricks, Internal tables, Nested loops. There you'll find the parallel cursor algorithm that speeds up the process quite a bit.


Post by Guest » Thu Sep 15, 2005 1:55 am

Are you looping on the same internal table or totally different internal tables? If your inner loop is on the same table, it is safe to check when to exit or you'll get the endless loop problem .. otherwise, make a copy of the internal table. And what is the different between nested select and nested loop (or I guess your standard disapprove using nested select too?).

Posts: 10
Joined: Wed Apr 13, 2005 7:33 am

Post by klaasvaak » Thu Sep 15, 2005 2:46 am

Anonymous wrote: And what is the different between nested select and nested loop
a nested select normally works efficient enough because of the restricted search in the second select (where key-field = field from first select).
a nested loop must be programmed efficient (you have to put effort in doing so) to avoid a complete loop of the second table with each pass of the first table.


Sark E. Get

Post by Sark E. Get » Thu Sep 15, 2005 3:34 am


If your standards simply forbid nested loops completely then they are stupid, as is the person who wrote them. (I'm assuming they really are loops and not selects).

Sure there are bad things you can do as mentioned by other people here - but standards written by a competent developer would have forbidden those specfically.

I suggest something like:

Code: Select all

loop at t_outer.
  perform myform.
form myform.
  loop at t_inner.
If the people responible for checking the standards are of similar quality to the ones who wrote them they'll never notice.

Post Reply