‎2009 Aug 14 11:08 AM
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
‎2009 Aug 14 12:12 PM
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
‎2009 Aug 14 12:17 PM
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
‎2009 Aug 14 12:22 PM
Then u should keep the SORT statement outside the LOOP.
Regards,
Lakshman.
‎2009 Aug 14 12:25 PM
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.
‎2009 Aug 14 1:12 PM
‎2009 Aug 14 12:42 PM
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
‎2009 Aug 14 2:46 PM
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
‎2009 Aug 15 3:14 PM
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