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

delete

Former Member
0 Likes
1,057

hi,

1) point a) just a single statement can do the delete in a single process as compared to point b) and c) where they need to do looping, right? so with a WHERE condition it can delete in a single process, right?

2) point b) and c) any difference? the TABLE is meant for?

thanks

a)

delete lt_mseg1 where dmbtr = 0.

b)

loop at lt_mseg1 into lw_mseg1.

if lw_mseg1-dmbtr = 0.

delete TABLE lt_mseg1 from lw_mseg1.

endif.

endloop.

c)

loop at lt_mseg1 into lw_mseg1.

if lw_mseg1-dmbtr = 0.

delete lt_mseg1 from lw_mseg1.

endif.

endloop.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
943

hi,

point 1. yes a & ( b and c ) are same. approach a is better.

point 2. yes there is a difference in b & c.

you use table when the loop of the table and the deleted table are different.

e.g. - loop at itab1 into wa_itab1.

if wa_itab2-dmbtr = wa_itab1-dmbtr

delete table itab2 from wa_itab2.

endif.

endloop.

here you are deleting table itab2 entries w.r.t entries in table itab1.

hope it is clear.

however in your case, you can or cannot use TABLE. both are ok.

Reward points if useful.

7 REPLIES 7
Read only

Former Member
0 Likes
944

hi,

point 1. yes a & ( b and c ) are same. approach a is better.

point 2. yes there is a difference in b & c.

you use table when the loop of the table and the deleted table are different.

e.g. - loop at itab1 into wa_itab1.

if wa_itab2-dmbtr = wa_itab1-dmbtr

delete table itab2 from wa_itab2.

endif.

endloop.

here you are deleting table itab2 entries w.r.t entries in table itab1.

hope it is clear.

however in your case, you can or cannot use TABLE. both are ok.

Reward points if useful.

Read only

0 Likes
943

you can also check this example

DELETE TABLE <itab> FROM <wa>.

or

DELETE TABLE <itab> WITH TABLE KEY <k1> = <f1> ... <kn> = <fn>.

In the first case, <wa> must be a work area compatible with the line type of <itab>. The values

of the key fields are taken from the corresponding components of the work area.

In the second case, you have to supply the values of each key field explicitly. If you do not know

the name of one of the key fields until runtime, you can specify it as the content of a field <ni>

using the form (<ni>) = <fi>. If the data types of <fi> are not compatible with the key fields, the

system converts them.

reward points if helpful

Read only

0 Likes
943

hi,

points awarded.

but can explain a bit on point 2? i need to loop itab2 also, right? why there are 2 internal table? in what situation have 2 internal table?

loop at itab1 into wa_itab1.

if wa_itab2-dmbtr = wa_itab1-dmbtr

delete table itab2 from wa_itab2.

endif.

endloop.

thanks

Read only

0 Likes
943

<b>This example is to demostrate the usage of TABLE in the delete statement.</b>

in your case you dont need to use two internal tables.

But had there been two internal tables and there would have been a necessity to delete 2nd internal table entries while you are in a loop of first internal table, then you should have used TABLE in the delete statement.

thanks

Read only

0 Likes
943

hi,

thanks alot of your explanation.

can i conclude that the word TABLE whether use for delete or other function that operating on internal table means there are more than 1 internal table, right?

i always do not understand why some statement with table whereas some without table.

if what i said above is right then i am clear with your help.

will award you again of your reply.

thanks

Read only

0 Likes
943

yes your conclusion is right.

Although this is only one use of table statement.

You can also use table when you have the to delete entries from the internal table based on the the TABLE keys.

Also the use of TABLE statement also related to the performance of the statement. Depending on the type of internal table the runtime of the statement will vary.

The system searches for the relevant lines as follows:

Standard tables

Linear search, where the runtime is in linear relation to the number of table entries.

Sorted tables

Binary search, where the runtime is in logarithmic relation to the number of table entries.

Hashed tables

The entry is found using the hash algorithm of the internal table. The runtime is

independent of the number of table entries.

If the system finds a line, it deletes it from the table and sets SY-SUBRC to zero. Otherwise, SYSUBRC

is set to 4. If the table has a non-unique key and the system finds duplicate entries, it

deletes the first entry.

Reward points if helpful

Read only

0 Likes
943

plz refer to this link to find more details about it

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf

reward points if helpful