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 without a where condition

Former Member
0 Likes
3,555

Hi,

I am giving a delete <tablename> statement in a macro, the table name is passed as a parameter. However while compiling it gives me an error saying that it expects a where condition but I don’t have an where condition I want to delete all the entries in the table. I dont want to use client specified. this problem occurs only if it is a SAP standard table. There is a statement in INFORMIX like delete from <tablename> where 1=1. Is there any statement like this in ABAP.

Regards

Raghu

23 REPLIES 23
Read only

Former Member
0 Likes
3,037

Hi,

try delete from (tabname).

Additionally check out the F1-help on the keyword delete.

regards

Siggi

Message was edited by: Siegfried Szameitat

Read only

0 Likes
3,037

Hi,

I tried DELETE (IADR&1). and it did not work, it shows compilation errors

Read only

0 Likes
3,037

well, not DELETE (IADR&1) but DELETE FROM (IADR&1).

Read only

0 Likes
3,037

This is usually how I delete all records of a database table.



delete from <tablename> client specified 
             where mandt = sy-mandt.

You could also use the following syntax if your internal table has all the database table records that you want to delete.



  delete <db_table> from table <itab>.

Regards,

Rich Heilman

Read only

0 Likes
3,037

no, that also did not work, i tried it and then only posted it

Read only

Former Member
0 Likes
3,037

delete from (tabname) will delete the database table.

Give a condition that will always be +ve.

Like if you r deleting from t_mara...

give delete itab where matnr <> space.

Or still better, use refresh itab. clear itab.

Pls reward proper points to the answer that helped u sovle ur problem.

Read only

0 Likes
3,037

To be clear, are you trying delete data from a database table or an internal table?

Regards,

Rich Heilman

Read only

0 Likes
3,037

Hi,

try

delete (tabname).

Read only

0 Likes
3,037

I've just tested the statements which I suggestion above. They both work well. Can you post some of the relevant code. Here is the code that I have tested.



  data: itab type table of zdbtab with header line.
  select * into corresponding fields of table itab
            from zdbtab.
  delete zdbtab from table itab.

Regards,

Rich Heilman

Read only

0 Likes
3,037

Hi all,

I also have some programs where I have the statment

DELETE FROM (tabname).

It works.

So in this case I think there is an issue with the parameter of the macro. May be you should give it a try to create a subroutine as follows:

form delete_table using p_tabname type c.

delete from (p_tabname).

endform.

I strongly believe that this will work.

regards

Siggi

Read only

0 Likes
3,037

DEFINE SELECT_ADR_S.

SELECT * INTO CORRESPONDING FIELDS OF TABLE IADR&1

FROM ADR&1S

WHERE TRKORR = H_TRKORR.

  • DELETE ADR&1S from IADR&1.

DELETE ADR&1S.

*. "CLIENT SPECIFIED

  • WHERE CLIENT EQ SY-MANDT.

END-OF-DEFINITION.

This is the potion of code i have written. Deletion is from a Database Table

Read only

0 Likes
3,037

Hi,

Syntax for delete is

<b>DELETE FROM <Databasetable name>.</b>

or

<b>DELETE (dbtabname) FROM TABLE itab.</b>

<i>U have missed <b>Table</b> itab</i>

DELETE ADR&1S from <u><b>Table</b></u> IADR&1.

Also

DELETE <u><b>From</b></u> ADR&1S.

It will work fine.

Also got this info from help docu

<b>DELETE FROM DATABASE dbtab(ar) ... ID key.</b>

Addition:

... CLIENT f

Effect

Deletes the data cluster stored in the table dbtab under the area ar (constant) and the ID key (field or literal) (EXPORT ... TO DATABASE ...).

Example

TABLES INDX.

TYPES: BEGIN OF TAB OCCURS 1,

CONT(30),

END OF TAB.

DATA: FLD(30) TYPE C,

TAB TYPE TABLE OF TAB_TYPE WITH NON-UNIQUE DEFAULT KEY,

WA_INDX TYPE INDX.

...

EXPORT TAB FROM TAB

FLD FROM FLD TO DATABASE INDX(AR)

ID 'TEST'.

You can delete this data cluster with the following statement:

DELETE FROM DATABASE INDX(AR) ID 'TEST'.

Addition 1

... CLIENT f

Effect

Deletes the data cluster in the client specified in the table f (only with client-specific import/export databases).

<b>Example

TABLES INDX.

DELETE FROM DATABASE INDX(AR) CLIENT '001' ID 'TEST'.</b>

Thanks & Regards,

Judith.

Message was edited by: Judith Jessie Selvi

Read only

0 Likes
3,037

Hi,

I get an error saying that "Delete from dbtab" should be followed by a where condition.

Regards

Raghu

Read only

0 Likes
3,037

Can you copy paste your code here, we can correct it test it and post it back here.

Regards

Raja

Read only

0 Likes
3,037

Hi,

It is not like that the syntax is correct.

Kindly check it once more

or u can try as

DELETE from ADR&1S where TRKORR = H_TRKORR.

that is in the select condition.

Thanks & Regrads,

Judith.

Read only

0 Likes
3,037

Hi,

Instead of the select & delete statement,I suggest you to write the following.

delete from ADR&iS where TRKORR = H_TRKORR.

In your code,you are selecting the record which satisfies TRKORR = H_TRKORR and then deleting the selected lines from the table.Instead of that this piece of code directly deletes the records from the database table.

Read only

0 Likes
3,037

Hi,

by the way, which release are you working on?

Siggi

Read only

0 Likes
3,037

*----


DEFINE SELECT_ADR_S.

SELECT * INTO CORRESPONDING FIELDS OF TABLE IADR&1

FROM ADR&1S

WHERE TRKORR = H_TRKORR.

  • DELETE ADR&1S from IADR&1.

DELETE ADR&1S.

  • DELETE (IADR&1).

*. "CLIENT SPECIFIED

  • WHERE CLIENT EQ SY-MANDT.

END-OF-DEFINITION.

This is the portion of code

Read only

0 Likes
3,037

Hi Raghuram,

Have you tried my suggestion?

Instead of the select & delete statement,I suggest you to write the following.

delete from ADR&iS where TRKORR = H_TRKORR.

In your code,you are selecting the record which satisfies TRKORR = H_TRKORR and then deleting the selected lines from the table.Instead of that this piece of code directly deletes the records from the database table.

Reward points for those answers which are useful.

Read only

0 Likes
3,037

You are using the Delete statement within the

Define ...

End-of-definition.

SO it might not work. Check with that.

Read only

0 Likes
3,037

following the modified code. i didnot get compilation error.

DEFINE select_adr_s.
  select * into corresponding fields of table iadr&1
         from  adr&1s
         where trkorr      = h_trkorr.

*      DELETE ADR&1S from IADR&1.
  delete from adr&1s where trkorr = h_trkorr .
*      DELETE (IADR&1).
*. "CLIENT SPECIFIED
*      WHERE CLIENT EQ SY-MANDT.
END-OF-DEFINITION.

Please note also using

delete from adr&1s .

delete adr&1s .

for the delete process also did not give me compilation error.

I would suggest that if the code is not too large copy/paste the whole program here. particulary the place where you are using this macro.

Regards

Raja

also have a look at the following weblog to learn about how to say thanks to the fellow SDNers who are trying to help you.

/people/mark.finnern/blog/2004/08/10/spread-the-love

Read only

0 Likes
3,037

Hi,

I also checked with the following:

DEFINE select_adr_s.

*SELECT * INTO CORRESPONDING FIELDS OF TABLE IADR&1

*FROM ADR&1S

*WHERE TRKORR = H_TRKORR.

  • DELETE ADR&1S from IADR&1.

delete from (&1).

  • DELETE (IADR&1).

*. "CLIENT SPECIFIED

  • WHERE CLIENT EQ SY-MANDT.

END-OF-DEFINITION.

select_adr_s 'ZTEST'.

It deleted all entries in the table and it is compilable without any error.

Siggi

Read only

Former Member
0 Likes
3,037

Hi Raghu,

I suppose you can try out something like this -

ranges r_mandt for T000-mandt. 

delete from  <tablename> client specified
  where mandt in r_mandt.

Here, if r_mandt is initial, all the entries in the table would be deleted.

Regards,

Anand Mandalika.