‎2008 Mar 24 6:00 AM
Hi,
How will the performance gets affected by using 'do in a loop' and also 'delete in loop'?
Will the performance increase or decrease in the above 2 cases and how?
Please let me know clearly?
Regards,
Pra
‎2008 Mar 24 6:36 AM
Hi,
Do loop : It first read the data and then check the condition.So reading the data effort is waste when condion is not satisfied.
In DO loop if you write delete statement for every loop it will go to the database table so performance of the program will decrease.....
Pls. reward if useful....
‎2008 Mar 24 9:59 AM
Hi
DELETE - Deleting from an Internal Table
Variants:
DELETE itab.
DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.
DELETE TABLE itab [FROM wa].
DELETE itab INDEX idx.
DELETE itab FROM idx1 TO idx2.
DELETE itab WHERE logexp.
DELETE ADJACENT DUPLICATES FROM itab.
See Short forms of line operations not allowed.
Effect
Deletes one or more lines from an internal table.
Note
If you delete lines within a LOOP ... ENDLOOP block, the deletion affects subsequent loop passes.
Variant 1
DELETE itab.
Effect
Deletes the current entry from an internal table in a LOOP. You can only use this variant with index tables (standard or sorted tables).
Return code is set to 0.
Note
Once you have deleted the current entry of an internal table in a LOOP, the effect of subsequent changes to the current entry without specifying the INDEX cannot be guaranteed, and the behavior may change in future releases.
Variant 2
DELETE TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn.
Effect
Deletes generically from an internal table. You can use this variant for any tables. The variant is a single command that deletes the table line with the key values k1 = v1 ....kn = vn. If there is more than one line with the specified key, only the first one is deleted. The table key must be specified fully, and each component of the key ki must be compatible with its corresponding value vi. If a component is not known until runtime, you can specify it dynamically as the contents of the field fi in the expression WITH TABLE KEY ... (fi) = vi ....
The costs for deleting one entry depend on the table type with which the table is defined:
STANDARD TABLE:
The system starts searching for the entry at the start of the table. This means that generic deletion has linear costs.
SORTED TABLE:
The system searches for the entry using the table key. Generic deletion for tables of this type has a logarithmic cost.
HASHED TABLE:
The system uses the hash algorithm and the table key to locate the entry. The time required is constant. Tables with deleted entries require a preceding/following administration. The first deletion operation has to set this up, and therefore has linear costs. After the deletion, the space required for each table entry increases by 8 bytes.
The Return code is set as follows:
SY-SUBRC = 0:
Entry deleted.
SY-SUBRC = 4:
Entry did not exist.
Variant 3
DELETE TABLE itab [FROM wa].
Effect
Behaves similarly to variant 2. The values for the table key are taken from the corresponding components of the (structured) field wa. The field must be compatible with the table line of itab. This method allows you to delete from a table without the table key having to be known in advance. If the internal table has a header line, you can leave out the FROM wa addition; the system then takes the eky values from the header line.
Variant 4
DELETE itab INDEX idx.
Effect
Deletes the idx-th entry of the internal table itab. This variant is only allowed with index tables (standard or sorted tables).
The Return code is set as follows:
SY-SUBRC = 0:
Entry deleted.
SY-SUBRC = 4:
Entry did not exist.
Variant 5
DELETE itab FROM idx1 TO idx2.
Effect
Deletes the range of lines from index idx1 to idx2 from the internal table itab. You can only use this variant with index tables (standard or sorted tables). You must specify at least one of the parameters FROM idx1 or TO idx2. If you omit the FROM parameter, the system deletes the lines from the start of the table to idx2. If you omit the TO parameter, the system deletes from line idx1 to the end of the table. The starting line idx1 must be greater than 0.
The Return code is set as follows:
SY-SUBRC = 0:
At least one entry deleted.
SY-SUBRC = 4:
No entries deleted.
Variant 6
DELETE itab WHERE logexp.
Extras:
... FROM idx1
... TO idx2
Effect
Deletes all of the entries from the internal table itab that satisfy the condition logexp. The condition logexp can be almost any logical expression. The only restriction is that the first field in each comparison must be a component of the line structure of the internal table itab.
The Return code is set as follows:
SY-SUBRC = 0:
At least one entry deleted.
SY-SUBRC = 4:
No entries deleted.
When you use the WHERE condition with a STANDARD or HASHED table, a full table scan is always required.
If you are working with a SORTED TABLE, the partial sequential processing can be optimized so that only the entries that actually satisfy the WHERE condition are processed. This optimization requires that the WHERE condition be specified in the form
WHERE k1 = v1 AND k2 = v2 AND ... AND kn = vn
where the components k1, ..., kn are in the same sequence as the beginning of the table key.
Each operand in the WHERE condition that is not a component of the corresponding internal table itab can be replaced by a functional method call. Functional methods are methods in ABAP Objects with any number of IMPORTING parameters and a single RETURNING parameter.
If the line type of the internal table contains object reference variables, or the entire line type is itself a reference variable, you can use the attributes of the object to which the reference is pointing as comparison values in the WHERE condition (see Attributes of objects as the key of an internal table).
You can only use the additions ... FROM idx1 and ... TO idx2 with index tables (standard or sorted tables).
Addition 1
... FROM idx1
Effect
Restricts the area searched to the set of lines beginning at index idx1. If you omit the addition FROM idx1, the system searches from the start of the table.
The FROM addition must occur before the WHERE condition.
Addition 2
... TO idx2
Effect
Restricts the area searched to the set of lines up to index idx2. If you omit the addition TO idx2, the system searches to the end of the table.
The TO addition must occur befor the WHERE condition.
Example
Example to delete all of the lines between 5 and 36 in a table of names where the entry begins with one of the letters 'A' to 'C'.
TYPES: BEGIN OF NAMETAB_TYPE,
NAME(30) TYPE C,
END OF NAMETAB_TYPE.
DATA: NAMETAB TYPE STANDARD TABLE OF NAMETAB_TYPE WITH
NON-UNIQUE DEFAULT KEY INITIAL SIZE 100.
...
DELETE NAMETAB FROM 5 TO 36 WHERE NAME CA 'ABC'.
Variant 7
DELETE ADJACENT DUPLICATES FROM itab.
Extras:
... COMPARING f1 f2 ...
... COMPARING ALL FIELDS
Effect
Deletes adjacent duplicate entries from the internal table itab. If there are n duplicate entries in succession, the first entry is retained, and the following n-1 entries are deleted.
Two lines are regarded as duplicates if their keys are identical.
The Return code is set as follows:
SY-SUBRC = 0:
At least one duplicate was found, and at least one entry was deleted.
SY-SUBRC = 4:
No duplicates found, no entries deleted.
Addition 1
... COMPARING f1 f2 ...
Effect
Two lines of the internal table itab are regarded as duplicates if they have identical contents in the fields f1, f2, ...
Addition 2
... COMPARING ALL FIELDS
Effect
Two lines of the internal table are regarded as duplicates if all of their field contents are identical.
Notes
The DELETE ADJACENT DUPLICATES statement works particularly well if you have sorted the internal table itab according to the fields that you want to compare when looking for duplicates. In this case, deleting adjacent duplicates is the same as deleting all duplicates. The direction of the sort is irrelevant.
If you do not know a comparison expression until runtime, you can specify it dynamically as the contents of the field name in the expression COMPARING ... (name) .... If name is empty at runtime, the comparison expression is ignored. If name contains an invalid component name, a runtime error occurs.
You can further restrict comparison expressions - both static and dynamic - by specifying offset and length.
Note
Performance:
When you delete a line of an internal table, index maintenance costs are incurred. These depend on the index of the table. The runtime is independent of the width of the table line.
Deleting a line from the middle of an internal table with 200 entries usually requires around 10 msn (standardized microseconds).
When you delete a set of entries using " DELETE itab FROM idx1 TO idx2." or " DELETE itab WHERE ...", index maintenance costs are only incurred once. This means that it is considerably more efficient than deleting entries in a LOOP.
If you want to delete adjacent duplicate entries from an internal table, use the variant " DELETE ADJACENT DUPLICATES FROM itab." instead of a LOOP construction.
Regards
sravani
‎2008 Mar 25 6:25 AM
Do itself is a loop - so using do inside a loop means loop inside loop. This should be avoided.
Delete inside loop only deletes the current record.
Major performance problem comes in select statements. For loop statement you can use field symbol to get slightly better performance.
‎2008 Mar 25 9:03 AM
do itself is a loop,
one of the major criteria in performance tuning is always you should avoid 1.any loop inside the loop,
2.loop with do statement,
3.select statement inside the loop,
4. select * insIde the loop.
EVEN delete inside the loop wil affect the performance as do itself will be reading all the data and it is time sonsuming
‎2008 Mar 25 9:03 AM
do itself is a loop,
one of the major criteria in performance tuning is always you should avoid 1.any loop inside the loop,
2.loop with do statement,
3.select statement inside the loop,
4. select * insIde the loop.
EVEN delete inside the loop wil affect the performance as do itself will be reading all the data and it is time consuming .
reward if usefull
mngowda
‎2008 Mar 25 9:08 AM
Hi
Do within loop will take more time and pass each value of loop the do will check muliptple times
if the no of entries are more then the system will take more time
delete within loop operates based on work area and it will delete one at a time based on the condition
so make use of delete table itab
Regards
Shiva