Application Development 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: 

Deleting Table entries

Former Member
0 Kudos

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

former_member188685
Active Contributor
0 Kudos

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

13 REPLIES 13

Former Member
0 Kudos

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

former_member188685
Active Contributor
0 Kudos

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

0 Kudos

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

0 Kudos
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 .

0 Kudos

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

0 Kudos

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

0 Kudos

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.

0 Kudos
[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

0 Kudos

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

0 Kudos

Thanks a lot Vijay Babu.

0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos
small correction to vijays code

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