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: 

How to Delete the Content of a Table?

Former Member
0 Kudos

Hi,

Please, i need to modify the content of a table, but before i want to delete this content. See follow the code that is used actually:

DELETE (pr_name_table).
MODIFY (pr_name_table) FROM TABLE prt_table.
MESSAGE s000(zbrx) WITH text-i02 pr_name_table.

The ABAP Editor don't accept the expression "DELETE (pr_name_table).".

How to delete this content???

Best Regards,

Daniel Sanchez

23 REPLIES 23

former_member194669
Active Contributor
0 Kudos

Hi,


              call function 'DB_DELETE_TABLE'
                exporting
                  tablename      = table "<Dynamic Name
                tables
                  inttab         = <tab> " Content
                exceptions
                  db_error       = 1
                  not_found      = 2
                  wrong_param    = 3
                  internal_error = 4
                  others         = 5.

Former Member
0 Kudos

Are you deleting an internal table or database table?

Rob

0 Kudos

I need to delete the entries of a database table.

Daniel Sanchez

0 Kudos

Use below syntax :

DELETE dbtab FROM TABLE itab.

Thanks

Seshu

Former Member
0 Kudos

OK, I see:

DELETE FROM (pr_name_table).

But this looks really dangerous. what if you misspell the table name and delete the wrong one?

Rob

0 Kudos

Rob,

When i use the command "DELETE FROM (pr_name_table)." the ABAP Editor expected a "WHERE" too, don't compiling with this command.

Regards,

Daniel Sanchez

0 Kudos

Hi,

Try to use


SELECT * FROM (TABLENAME) INTO TABLE INTTAB.
DELETE (TABLENAME) FROM TABLE INTTAB.

Here INTTAB contains the entries to be deleted.

0 Kudos

Yes - you can say something like

WHERE one-of-the-required-key-fields NE space.

Rob

Former Member
0 Kudos

Hi Daniel,

Use COMMIT WORK statement after DELETE statement. it should work.

<b>Reward points if it helps,</b>

Satish

0 Kudos

Hi,

The solutions proposals above did not work.

I need to delete the ALL ENTRIES of a database table and after add new entries with "MODIFY" command.

I'm using this code:

DELETE (pr_name_table).
MODIFY (pr_name_table) FROM TABLE prt_table.
MESSAGE s000(zbrx) WITH text-i02 pr_name_table.

I'm waitinf for more helps!

Tks,

Daniel Sanchez

0 Kudos

Daniel,

do like this

DELETE (pr_name_table) where <keyfield> <> ' '.

COMMIT WORK.

Reward points if it helps,

Satish

Former Member
0 Kudos

Hi.

Use :

REFRESH pr_name_table.

Regards.

Former Member
0 Kudos

Hi,

If you are changing the non-key fields of a database table, use Update command instead of Modify.

MODIFY pr_name_table FROM prt_table.

If sy-subrc = 0.

DELETE pr_name_table FROM TABLE prt_table.

Endif.

Note: Check the syntax by clicking on F1

Bye,

KC

Former Member
0 Kudos

Hi.

cond = '%'.

DELETE FROM<tab> WHERE field like cond.

Regards

0 Kudos

I need to use this operation for diversified tables. For this, I can´t use the "WHERE" command.

Also, I don't use the expression "DELETE pr_name_table FROM TABLE prt_table" why the number of entries between the 2 tables are diferent.

When used just the expression "DELETE (pr_name_table).", the ABAP Editor show the error message: "FROM wa" must follow "DELETE (dbtab)"

Please, i need more helps.

Message was edited by:

Daniel Sanchez

0 Kudos

Hi.

1º load all the table pr_name_table in the internal table ptr_table

select *

from pr_name_table

appending corresponding fields of table ptr_table.

the tables are equals.

2º delete pr_name_table from table ptr_table.

0 Kudos

You have to use the solution I proposed above, but you will also have to add a dynamic WHERE clause that will choose all table entries.

Rob

0 Kudos

Daniel,

What on Earth is going on? Read the SAP help as I believe the statement you need is as follows:

DELETE FROM (pr_name_table).

Deletes lines in a database table. If you do not specify a WHERE clause, the system deletes all lines (in the current client).

Hope it helps.

0 Kudos

I think the help is incorrect. In earlier releases you could delete without a WHERE clause, but now I think you get a syntax error if you try it.

Rob

0 Kudos

You maybe right, on 470 here and it syntax checks ok.

0 Kudos

my SAPHelp tells it is optional since release 6.10 (I think this is the ABAP version, not the SAP version). It was mandatory <i>before</i>, and optional since that (i. e. no WHERE ==> all entries will be deleted in DB table).

ec

0 Kudos

You seem to be right, but I recall it being needed in earlier versions. Maybe the original poster could let us know which version he is on.

Rob

0 Kudos

Hi,

Thanks for helps! The problem been resolved with this solution:

>> Call of Call:

IF sy-subrc IS INITIAL.
      PERFORM z_upload_table TABLES t_zpf0012 t_bkp_zpf0012
                                USING  c_zpf0012.
ENDIF.

>> In the Form: (after processing of Form)

FORM z_upload_table TABLES prt_table prt_table2
                       USING  pr_nome_table.

.

.

.

  IF sy-subrc <> 0.
    MESSAGE i000(zbrx) WITH text-i03 l_file.
  ELSE.
    DELETE (pr_name_table) FROM TABLE prt_table2.
    MODIFY (pr_name_table) FROM TABLE prt_table.
  ENDIF.

Best Regards,

Daniel Sanchez