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

Data Deletion From Database table

Former Member
0 Likes
456

Hi all,

I need to create a program to delete old data's from database tables through a program. the criteria is the input for the program is to be any table name and date . is this requirementt possible. is there any function module catering to this.

thanks,

kavitha

2 REPLIES 2
Read only

Former Member
0 Likes
407

Hi,

This can be done using Dynamic open SQL.

Use the following Code Excerpts in your program.

DATA: tabname type tabname,

dref type ref to data,

<wa> type any.

Field-symbols: <itab> type any table.

**This creates your generic dynamic internal table.

CREATE data dref type (tabname).

assign dref->* to <wa>.

**Now you can use any of the DML statements.

DELETE | UPDATE | INSERT | MODIFY

(dbtab) FROM wa.

Alternatively, records to be deleted or updated

can be selected by a WHERE clause with a static

logical condition, as in:

DELETE | UPDATE (dbtab) WHERE

logical_condition.

**This logical condition can satisfy your requiremnt for date.

Now when u write your program just keep in mind two things,

1. Be aware of the following pitfall when

specifying a dynamic WHERE clause with

an UPDATE or DELETE statement: if the

WHERE clause is empty, it will be interpreted

as the Boolean value TRUE with the result

that all records on the database get updated

or deleted.

2. In ABAP Release 4.6 and earlier, a dynamic table

name has to be specified in uppercase.

Handle the exceptions properly .

This DELETE statment should work fine if you are the only person accessing the table. But if their are more then 1 users accessing the table, then table locking concept needs to be implemented so that discrepancies can be avoided.

Just check this.

Regards,

Khushboo.

Read only

manubhutani
Active Contributor
0 Likes
407

Hi Kavitha

There is no function module for this

because it FM cannot determine about the varipous table in R3.

So use Delete command for this.

Please reward points