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: 

Dinamic delete. is it possible?

guilherme_lahr
Explorer
0 Kudos

Hi guys.

How are you?

Is it possible use the command delete itab. with dinamic fields?

For exemple:

field-symbols: <field> type any.

do 3 times.

case sy-index.

when 1.

l_field = 'MARK1'.

when 2.

l_field = 'MARK2'.

when 3.

l_field = 'MARK3'.

endcase.

assign l_field to <field>.

DELETE itab WHERE <field> EQ 'X'.

enddo.

thanks.

bye.

Edited by: guilherme lahr on Jan 28, 2009 12:17 AM

Edited by: guilherme lahr on Jan 28, 2009 12:20 AM

4 REPLIES 4

Former Member
0 Kudos

Hi,

I think DELETE will not allow to specify a component dynamically...

Instead...you can try this..In one shot you can delete the entries..instead of doing it within loop..

DELETE itab WHERE mark1 EQ 'X' OR
                  mark2 EQ 'X' OR
                  mark3 EQ 'X'.

Thanks

naren

Edited by: Narendran Muthukumaran on Jan 28, 2009 12:37 AM

Former Member
0 Kudos

Dynamic specifications are not supported in this case.

It says so right on the ABAP help for the DELETE itab statement, which you can access using F1 from the ABAP source editor.

Why not just do the various deletes in your CASE instead of assigning the name of the field to delete with?

CASE sy-index.
    WHEN 1.
      DELETE itab WHERE mark1 EQ 'X'.

    WHEN 2.
      DELETE itab WHERE mark2 EQ 'X'.

    WHEN 3.
      DELETE itab WHERE mark3 EQ 'X'.

  ENDCASE.

Good luck

Brian

Former Member
0 Kudos

Hi,

you can't use DELETE WHERE with dynamic tables, but it is still possible to delete records.

Consider a situation where you want to delete all entries in where FIELD1 (one of the fields in the table) is equal to 'X'.

DATA. lp_data TYPE REF TO DATA.

FIELD-SYMBOLS: TYPE ANY,

TYPE ANY.

CREATE DATA lp_data LIKE LINE OF .

ASSIGN lp_data->* to .

ASSIGN COMPONENT 'FIELD1' OF STRUCTURE TO .

LOOP AT INTO .

CHECK EQ 'X'.

DELETE TABLE FROM .

ENDLOOP.

Another possibility is to use, for example, with a table that has key fields kf1 and kf2:

DELETE TABLE WITH TABLE KEY ('KF1') = val1 ('KF2') = val2.

With fully specified keys this is very efficient for HASHED tables, somewhat efficient for SORTED tables,

and not very efficient, usually, for STANDARD tables.

As ever, what you actually write depends on precisely what you are trying to achieve.

Former Member
0 Kudos

Hi,

It is not possible to specify the field dynamically in the delete clause,

but you can achieve this by adding the below code after your case endcase.


LOOP AT itab INTO wa_tab.
  ASSIGN COMPONENT l_field OF STRUCTURE wa_tab TO <field>.
  CHECK <field> EQ 'X.
  DELETE itab.
ENDLOOP.

Regards,

Manoj Kumar P