‎2007 Sep 30 3:23 PM
Hi Everyone,
I have a situation. Some of the functional guys created a plant and later deleted it, but didnt delete it across the landscape. So there are records which still has that plant in a couple of tables say MCON and MARC.
Now my functional guy wants me to write a program by which I can delete the record in those tables when plant is 'ROM'.
Can anyone help me in this??
Thanks
Kumar.
‎2007 Sep 30 5:37 PM
Hi Kumar,
tables: dd03l. "Just for select-options
* tables to check, try M*
select-options:
s_tabname for dd03l-tabname.
data:
lv_tabname type dd03l-tabname,
* table for unique table names
lt_tabname type sorted table of dd03l-tabname
with unique key table_line.
start-of-selection.
select tabname
into lv_tabname
from dd03l
where tabname in s_tabname
* Most plant fields are called WERKS
and fieldname = 'WERKS'.
* or try
* and rollname = 'WERKS_D' - find some more for the data element
* sorted table will take an entry only once without muttering
insert lv_tabname into table lt_tabname.
endselect.
loop at lt_tabname into lv_tabname.
delete from (lv_tabname) where WERKS = 'ROM'.
* for test purposes use SELECT COUNT( * )...
if sy-subrc = 0.
write: / sy-dbcnt, 'records deleted from table', lv_tabname.
endif.
endloop.
Let it run overnight and see what happens
Regards,
Clemens
‎2007 Sep 30 4:25 PM
For deleting entries from a database table:
you can first select all the entries which satisfy ur condition ( in ur case where plant is 'ROM') from table TAB(dbtable) into itab(internal table).
then you can say something like:
DELETE itab FROM TAB.
Sri
‎2007 Sep 30 5:37 PM
Hi Kumar,
tables: dd03l. "Just for select-options
* tables to check, try M*
select-options:
s_tabname for dd03l-tabname.
data:
lv_tabname type dd03l-tabname,
* table for unique table names
lt_tabname type sorted table of dd03l-tabname
with unique key table_line.
start-of-selection.
select tabname
into lv_tabname
from dd03l
where tabname in s_tabname
* Most plant fields are called WERKS
and fieldname = 'WERKS'.
* or try
* and rollname = 'WERKS_D' - find some more for the data element
* sorted table will take an entry only once without muttering
insert lv_tabname into table lt_tabname.
endselect.
loop at lt_tabname into lv_tabname.
delete from (lv_tabname) where WERKS = 'ROM'.
* for test purposes use SELECT COUNT( * )...
if sy-subrc = 0.
write: / sy-dbcnt, 'records deleted from table', lv_tabname.
endif.
endloop.
Let it run overnight and see what happens
Regards,
Clemens