‎2008 Jul 11 8:24 AM
We have a requirement where the user wants to delete certain records from variuos tables at a time.The user will enter Table name,time created and date created as the input.These will be select-options.Upon executing this the program has to delete the records from the tables the user has entered.how can i do this?
‎2008 Jul 11 8:29 AM
you mean to say you need to delete the records of the database table right?
Then you can use the select option in your where condition as delete the data from the internal table
using the statement delete itab.
Now thats the simple program you need to write.
Hope it helps
regards
Bhanu
‎2008 Jul 11 8:31 AM
The user can enter several tables like MARA,MARC etc ata time.The records should be selected first for these tables and then deleted.So how do we specify the tables dynamically in the select statment?
‎2008 Jul 11 8:34 AM
Hi,
try this code.
select-options s_matnr like mara-matnr.
delete from MARA where matnr in s_matnr.
delete from MARC where matnr in s_matnr.
regards.
sriram.
‎2008 Jul 11 10:14 AM
>
> The user can enter several tables like MARA,MARC etc ata time.The records should be selected first for these tables and then deleted.So how do we specify the tables dynamically in the select statment?
Isn't anyone going to make the obvious comment that you should NEVER do direct table updates on main SAP tables such as MARC and MARA? And, even worse, you are letting the end user decide which table to delete from thus losing even more control over what will happen. When you say 'they can enter several tables like MARA, MARC etc' are you going to impose any restrictions at all on which table they can delete from - or are you intending to let them delete from any SAP table they choose?
‎2008 Jul 11 10:17 AM
‎2008 Jul 11 10:37 AM
Dangerous example. There are some people who could read that and judge from it that it is ok to do a direct DELETE from MARA.
Personally, if I had to do something like this for a small number of tables, I'd try to keep control by making it very specific. I'd give them a list of tables they can delete from on the selection screen with checkboxes and run a separate bit of delete code for each table where the checkbox has been ticked. I would not feel comfortable allowing them to enter any table name they liked - even with validation to restrict them to Z tables or to a list of certain tables - and then generate a bit of code to do the deletion.
‎2008 Jul 11 11:13 AM
Hi.
I would like to support Christine's opinion. Offering a report that allows a user to enter a table name and some parameters and then execute a delete statements seems to be a very risky thing. If you allow users to directly delete from SAP tables everyone who executes that report can crash your system. And even if you restrict it to Z-tables: Most likely that tables contain data that is of high importance for your business.
If you insist on having such a report you should at least implement a good security concept and think carefully about authorization checks!
And even if you are sure that there never will be a malicious user of that report you have to think about some user just mixing up two tables or having a bad day or whatever. People make errors. With such a report this errors might be really bad.
Best regards,
Jan Stallkamp
‎2008 Jul 11 8:33 AM
Hi,
if the user requiremt is to delete all the records, then do the follwoing:
1) Fill all the select options table names in a range( fill only range-low values so that table names are stored there)
2) Loop at range, then call the delete statement...
loop at r_range
DELETE FROM DATABASE r_range-low.
endloop.
Formore info check the syntax of the delete statement..in sap help
Reward if useful..
Regards
Shiva
‎2008 Jul 11 8:37 AM
Not all the records should be deleted..
Table name:
date created :
time created :
‎2008 Jul 11 8:52 AM
Hi,
then try this code.
data: itab like MARA occurs 0 with header line,
jtab like MARC occurs 0 with header line.
select-options: s_matnr like mara-matnr.
select erdat erzet into table itab from mara where matnr in s_matnr.
if sy-subrc = 0.
delete MARA from itab where matnr in s_matnr.
endif.
regards.
\
sriram.
‎2008 Jul 11 8:51 AM
Hi,
the simplest way will be to get the records into an internal table and then delete the records from the database using this internal table. since ur table name is dynamic, u can use a dynamic select query to fetch the records.
since ur selection is based on table name and "Creation date and time", u can write the select as
select
<key fields>
from (tablename)
into *******
do revert for any clarfications.
regards,
Anoop
‎2008 Jul 11 9:54 AM
Hello Rakesh,
To specify the table name dynamically,
DELETE [FROM] (<table>) WHERE <cond>.
For example:
REPORT yh_sample1.
tables: dd03l,
mara.
parameters: table type dd03l-tabname.
select-options:
ersda for mara-ersda.
delete from (table) where ersda in ersda.
write: sy-subrc.
Hope this helps you
Indu.