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 with SELECT-OPTIONS

Former Member
0 Likes
2,758

Hi.

I want to know if we can use a SELECT-OPTION in a query to delete a TABLE ?

For example :

 
SELECT-OPTIONS:
    so_tname FOR DD02L-TABNAME.

I know in a select I can do something like that :


SELECT TABNAME
  FROM DD02L
  INTO TABLE INT_TAB
  WHERE TABNAME IN so_tname 

Can we use something similar in a DELETE query ? Because for the moment i'm only able to do that with a parameter on 1 table.


DELETE
  FROM (p_tab) 
  WHERE ....

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,722

Hi

Yes you can:

DELETE FROM <TABLE> WHERE <COND IN SELEC-OPTION>

Max

6 REPLIES 6
Read only

Former Member
0 Likes
1,722

Hi helder,

1. Yes ofcourse.

delete from dbtab

where fieldname in seloption.

*----


VERY IMPORTANT.

2. MAKE SURE THERE IS SOME VALUE

IN SELECT-OPTION

IF IT IS BLANK,

ALL RECORDS IN THE TABLE WILL BE DELETED !!!!

regards,

amit m.

Message was edited by: Amit Mittal

Read only

Former Member
0 Likes
1,723

Hi

Yes you can:

DELETE FROM <TABLE> WHERE <COND IN SELEC-OPTION>

Max

Read only

0 Likes
1,722

In fact what i need is to clear all the records in the table of the select-options.

If i have : ztest1, ztest2, ztest3 in the select options, i want to clear these 3 tables.

Read only

0 Likes
1,722

Hi again,

1. i tried at my end.

it works pefectly fine.

2. sample code (just copy paste)

REPORT zam_temp07 .

DATA : tname LIKE dd02l-tabname.

SELECT-OPTIONS : tn FOR tname.

LOOP AT tn.

DELETE FROM (tn-low).

ENDLOOP.

regards,

amit m.

Read only

0 Likes
1,722

Hi

If you want to delete all hits in your table you can use DELETE FROM without where conditions, it works from rel. 4.7, I don't remember for other release.

SELECT-OPTIONS: SO_TAB FOR DD02L-TABNAME.

DATA TAB_TABLE LIKE STANDARD TABLE OF DD02L WITH HEADER LINE.

  • Make sure to delete only records of existing tables

SELECT * FROM DD02L INTO TABLE TAB_TABLE

WHERE TABNAME IN SO_TAB

AND AS4LOCAL = 'A'.

LOOP AT TAB_TABLE.

DELETA FROM (TAB_TABLE-TAB_NAME).

ENDLOOP.

Remember this code is very dangerous, because you could delete the data of whichever SAP table.

Max

Message was edited by: max bianchi

Read only

0 Likes
1,722

Hi Helder,

Just say,

SELECT-OPTIONS s_matnr FOR mara-matnr.

REFRESH s_matnr.

CLEAR s_matnr.

Remember even if it is a select option, it is a internal table.

Regards,

Srikanth