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: 

Loops within loops

Former Member
0 Kudos

Greetings Abapers

I keep getting a runtime error where the system tells me that my program has terminated because it has exceeded the runtime limit. I suspect this is because i have a loop within another loop and they both take a while to execute. I was wondering if you could suggest how i can improve my code. Currently what i want to do is

Get all active sales codes and assign them to a table

Read org relationships for all BP's linked to Salescodes for all date ranges

The code is :

loop at lt_/ccdev01/a2scode.

  • Read all organisational relationships for all business partneru2019s linked to sales codes for all date ranges

select * from hrp1001 into table lt_hrp1001

where plvar = '01'

and relat = 'Z40'

or relat = '008'.

loop at lt_hrp1001.

.........

endloop.

endloop.

5 REPLIES 5

Former Member
0 Kudos

Hi try this!

sort lt_/ccdev01/a2scode by <keyfield>.

sort hrp1001 by <key field..

loop at lt_/ccdev01/a2scode.

Read all organisational relationships for all business partneru2019s linked to sales codes for all date ranges

select * from hrp1001 into table lt_hrp1001

where plvar = '01'

and relat = 'Z40'

or relat = '008'.

read table hrp1001 into wa_hrp1001 with key = lt_/ccdev01/a2scode-<key>.

endloop.

Former Member
0 Kudos

If your select statement is doing the same work in every loop, better place it outside the loop. And then do a loop within the loop. Just try if it helps.

Regards,

Yogesh Bhatia

Former Member
0 Kudos

Hrp1001 has huge data and that too UR executing this table

without proper key .. and in loop .. endloop.

Select data only once from HRP1001 ..

select * from hrp1001 into table lt_hrp1001

where plvar = '01'

and relat = 'Z40'

or relat = '008'.

loop at lt_/ccdev01/a2scode.

loop at lt_hrp1001.

.........

endloop.

endloop.

andr_klos
Explorer
0 Kudos

Hi,

try this:

...

select * from hrp1001 into table lt_hrp1001
where plvar = '01'
and relat = 'Z40'
or relat = '008'.

LOOP AT lt_/ccdev01/a2scode ASSIGNING <FS1>.

  LOOP AT LT_HRP1001 ASSIGNING <FS2>.

  ENDLOOP.

ENDLOOP.

...

Futher tipps:

TABLE LT_HRP1001: Sorted or Hashed table

Former Member
0 Kudos

write:

select * from hrp1001 into table lt_hrp1001

where plvar = '01'

and relat IN ('Z40','008').