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 table entry

Former Member
0 Likes
624

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.

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
501

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

2 REPLIES 2
Read only

Former Member
0 Likes
501

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

Read only

Clemenss
Active Contributor
0 Likes
502

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