Skip to Content
author's profile photo Former Member
Former Member

Delete from database Table

Hi,

To delete data from database table using internal table I am using following statement.

DELETE dbtab FROM TABLE itab.

Itab is a sorted table.Just wondering if table type matters while deleting database entries using internal table.which is efficient table type for deleting records from database table?

Regards

Nilesh

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on May 17, 2005 at 09:26 PM

    Hi Nilesh

    The row type of the internal table must be a data object with at least the same length and alignment as the key structure of the database table. The key is read according to the structure of the table line, and not that of the row type. It is a good idea to define the row type with reference to the structure of the database table.

    From SAP Help

    DATA: BEGIN OF WA,
    CARRID TYPE SPFLI-CARRID,
    CONNID TYPE SPFLI-CONNID,
    END OF WA,
    ITAB LIKE HASHED TABLE OF WA
    WITH UNIQUE KEY CARRID CONNID.
    
    WA-CARRID = 'UA'. WA-CONNID = '0011'.
    INSERT WA INTO TABLE ITAB.
    
    WA-CARRID = 'LH'. WA-CONNID = '1245'.
    INSERT WA INTO TABLE ITAB.
    
    WA-CARRID = 'AA'. WA-CONNID = '4574'.
    INSERT WA INTO TABLE ITAB.
    
    ...
    
    DELETE SPFLI FROM TABLE ITAB.

    Besides, it is so technical what algorithm is run to delete records from the DB table when an internal table is given. If you want you can have a quick test using GET TIME. However, it seems logical that if your internal table is sorted with respect to any index, especially the primary index, of the DB table this may increase performance.

    Regards

    *--Serdar https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 18, 2005 at 03:55 AM

    Hi,

    While using delete dbtab check whether you are using the same table type for the internal table you have specified. If not while executing it will give a dump.

    So first move the internal table into a table of type dbtab and then use delete.

    <i>Mass deletion: Deletes all database table lines for which the internal table itab contains values for the primary key fields. The lines of the internal table itab must satisfy the same condition as the work area wa in addition 1 to variant 2.

    The system field SY-DBCNT contains the number of deleted lines, i.e. the number of lines of the internal table itab for whose key values there were lines in the database table dbtab.

    The return code is set as follows:

    SY-SUBRC = 0:

    All lines from itab could be used to delete lines from dbtab.

    SY-SUBRC = 4:

    For at least one line of the internal table in the database table, there was no line with the same primary key. All found lines are deleted.

    Note

    If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0.</i>

    Thanks & Regards,

    Judith.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.