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

Sorting the table inside a loop.

0 Likes
8,451

Hi everyone,

I am getting following warning in my report program: "You may not delete or overwrite table "IT_HCASE" within a LOOP over itself."

LOOP AT IT_HCASE.

SORT IT_HCASE BY VORNR.

. . .. .. . .

.. . .. .. . .

Endloop.

Please let me know how I can overcome this warning. Here IT_CASE is internal table of type local structure type.

Thanks and Regards

Deepika

8 REPLIES 8
Read only

Former Member
0 Likes
3,553

Hi,

This message will not be due to the SORT statement.

It is because you must be appending in the same table within the loop.

This will lead to an endless loop.

Check the same.

Regards,

Ankur Parab

Read only

0 Likes
3,553

Hi Ankur,

I commented the SORT statement and did a syntax check. This time there was no warnings.

So had concluded that problem lies with the SORT statement only.

This warning is appearing after we upgraded from ECC 4.6c to ECC 6.0.

Thanks and Regards

Deepika

Read only

0 Likes
3,553

Then u should keep the SORT statement outside the LOOP.

Regards,

Lakshman.

Read only

0 Likes
3,553

Have a look at this note.

Note 841997 - Mode termination after SORT within a LOOP statement.It says that SORT shuld be avoided inside a loop.

Regards,

Lakshman.

Read only

0 Likes
3,553

The sort stament should be outside the Loop statement.

Read only

Former Member
0 Likes
3,553

Hello,

Apart from the risk of inconsistent data access (see note 841997) SORTing an internal table inside the same loop where you are filling up that table is an extremely bad idea and could lead to truly monstrous performance problems. If you are adding records to the table but want the table to remain in sorted order, then you must use a SORTED TABLE.

Regards,

Mark

Read only

Former Member
0 Likes
3,553

It makes no sense to sort a table that you are looping through. Consider this: You loop through the table and sy-tabix is say 15. You then sort the table and then the record at index 15 is a different record and the record which would have been next before the sort (index 16) is also different.

Rob

Read only

Former Member
0 Likes
3,553

hi,

its better if u sort the internal table before using the loop statment using the field VORNR so dat u get the records in the internal table in sorted form n then u can do watever processing u wanna do within the loop statement.

rgds/

shivraj