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

Deleting Table entries

Former Member
0 Likes
2,051

Dear All,

I need to delete ALL THE entries in the table marc that contains entries in the mara table.

Pls. let me know how to code this.

Thanks in Advance,

CR

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,695

Hi,

select * from marc
        into table it_marc.
if sy-subrc = 0.
select * from mara
         into it_mara
         for all entries in it_marc
         where matnr = it_marc-matnr.
if sy-subrc = 0.
<b>delete marc from it_mara.</b>
endif.
endif.

Regards

vijay

Dear All,

I need to delete ALL THE entries in the table marc that contains entries in the mara table.

Pls. let me know how to code this.

Thanks in Advance,

CR

13 REPLIES 13
Read only

Former Member
0 Likes
1,695

Hello KC,

It is not correct to delete the table entries in MARC directly as u are creating inconsistency in the SAP database table. The entries in MARC should be deleted through std mechanism and not otherwise.

However if u want to still go ahead and delete then u need to read table MARA and for each entry in MARA DELETE entries from MARC using where clause.

BUT

Read only

Former Member
0 Likes
1,696

Hi,

select * from marc
        into table it_marc.
if sy-subrc = 0.
select * from mara
         into it_mara
         for all entries in it_marc
         where matnr = it_marc-matnr.
if sy-subrc = 0.
<b>delete marc from it_mara.</b>
endif.
endif.

Regards

vijay

Read only

0 Likes
1,695

Small correction to the issue.

Please delete log entries from table DBTABLOG related to KONP and YMTOL_I696_MAINF tables.

Kindly let me know.

Thanks a lot,

Ranjan

Read only

0 Likes
1,695
data : begin of itab occurs 0.
         include structure DBTABLOG.
 data: end of itab.


select * from DBTABLOG into table itab where tabname = 'KONP' or TABNAME = 'YMTOL_I696_MAINF'.

delete DBTABLOG from table itab .
Read only

0 Likes
1,695

Hi,

select * from DBTABLOG 
        into table it_dblog
        where TABNAME = 'KONP'
             or TABNAME = 'YMTOL_I696_MAINF'.
if sy-subrc = 0.
<b>delete DBTABLOG from table it_dblog.</b>
endif.

Regards

vijay

Read only

0 Likes
1,695

Thanks a lot Vijay,

Last question is, I need to select the table name from the selection screen (entered by user). i.e., the user can enter either KONP or 'YMTOL_I696_MAINF'.

Kindly let me know how to do this..

Thanks,

CR

Read only

0 Likes
1,695

Hi,

I think u'll enter it in a parameter.

then change your where condition as

select * from DBTABLOG

into table it_DBTABLOG

where TABNAME = p_tabname. " table name

if sy-subrc = 0.

DELETE DBTABLOG FROM TABLE IT_DBTABLOG.

endif.

Regards,

GSR.

Read only

0 Likes
1,695
[code]selet-options begin of block b1 with frame title text-001.
selet-options : s_tabnm for datablog-tabname.
selet-options end of block b1

select * from DBTABLOG into table itab where tabname in <b>s_tabname.</b>
if sy-subrc = 0.
delete DBTABLOG from table itab .
endif.

pls reward for helpful answers and close the thread if solved

Message was edited by: Sekhar

Message was edited by: Sekhar

Read only

0 Likes
1,695

Hi,

REPORT  ZTEST_Delete  MESSAGE-ID ZZ   .
TABLES: DD02L.
data: tablename type dd02l-tabname.
DATA: IT_DBLOG LIKE DBTABLOG OCCURS 0 WITH HEADER LINE.
SELECT-OPTIONS: S_TABLE FOR DD02L-TABNAME NO INTERVALS.

AT SELECTION-SCREEN.

  LOOP AT S_TABLE.
    tablename = S_TABLE-LOW.
    IF tablename <> 'KONP' and tablename <> 'YMTOL_I696_MAINF'.
      MESSAGE E000 WITH 'enter valid tab name'.
    ENDIF.
  ENDLOOP.

  SELECT * FROM DBTABLOG
          INTO TABLE IT_DBLOG
          WHERE TABNAME IN S_TABLE.
  IF SY-SUBRC = 0.
    DELETE DBTABLOG FROM TABLE IT_DBLOG.
  ENDIF.

Regards

vijay

Read only

0 Likes
1,695

Thanks a lot Vijay Babu.

Read only

0 Likes
1,695

WARNING! Deleting any entries from SAP tables directly is likely to fracture database integrity and highly likely to invalidate your support contract!

Read only

Former Member
0 Likes
1,695

Hi,

Write a Join on MARA and MARC into IT_MARA.

Now write

DELETE MARC FROM TABLE IT_MARA.

********************************************

Simply write a select statement on DBTABLOG as

select * from DBTABLOG

into table it_DBTABLOG

where TABNAME = 'KONP' OR

TABNAME = 'YMTOL_I696_MAINF'.

DELETE DBTABLOG FROM TABLE IT_DBTABLOG.

Regards,

GSR.

Read only

Former Member
0 Likes
1,695
small correction to vijays code

delete marc from <b>table</b> it_mara.