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

Performance improvement when deleting customer table

gilberto_parga
Participant
0 Likes
3,048

Hi gurus.

I am in charge of tunning a custom ABAP application, which runs as a job because it could take so much long time. There is a little excerpt that I am wondering how to improve. Is the following:

DO.
       SELECT * FROM ztable UP TO 10000 ROWS.
         DELETE ztable.
       ENDSELECT.
       IF sy-subrc NE 0.
         EXIT.
       ENDIF.
       COMMIT WORK AND WAIT.

ENDDO.

ztable is a transparent custom table, likely with 20 million rows or more added in a week time. I understand that original programmer wanted to delete all the rows from this table but with 10,000 row packs instead all once and for all. I pressed F1 help for DELETE and read from ABAP keyword documentation: "The number of rows that can be deleted within a database LUW in the tables of a database has a specific restriction for each database, as each database system can only manage a limited amount of data in the rollback area, and a limited number of locks." I think the restriction of rows to be deleted was an important point to decide only delete with 10000 rows packs.

This program is old (1999), and my system is SAP ECC 6.0 with Oracle 11.2 as DBMS. Can this code excerpt be improved somehow? My try uses an internal table to avoid select-endselect and gets 100,000 instead 10000 rows. Do you think it is fine?:

DO.
       SELECT * FROM ztable INTO it_ztable UP TO 100000 ROWS.

       IF it_ztable[] is not initial.       

         DELETE ztable from it_ztable.
       ELSE.
         EXIT.
       ENDIF.

       COMMIT WORK AND WAIT.

ENDDO.

Thank you in advance for your advice!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,571

I just use "DELETE FROM ZTABLE."  This will dump entire table.

or, alternatively (check exact syntax, haven't used this for a while)

EXEC SQL.

   truncate table 'ZTABLE'  "note no period.

endexec.

10 REPLIES 10
Read only

Former Member
0 Likes
2,572

I just use "DELETE FROM ZTABLE."  This will dump entire table.

or, alternatively (check exact syntax, haven't used this for a while)

EXEC SQL.

   truncate table 'ZTABLE'  "note no period.

endexec.

Read only

yuri_ziryukin
Product and Topic Expert
Product and Topic Expert
0 Likes
2,571

As David proposed above, please use native SQL and TRUNCATE.

This will have the best performance.

       EXEC SQL.

         TRUNCATE TABLE  ztable

       ENDEXEC.

Syntax is DB-dependent.

Read only

0 Likes
2,571

Hi,

watch it: TRUNCATE is considered DDL, which means, it does AUTOCOMMIT whatever you did before AND it cannot be rolled back AND it works cross client, so if you do this on a clientdependant table, the "other" client might not be amused 🙂

Volker

Read only

0 Likes
2,571

Hi,

Try to use Open SQL with below syntax.

DELETE FROM DATABASE ztable client sy-mandt.

regards

sandeep

Read only

0 Likes
2,571

Where did you find this syntax?

In the ABAP help I cannot find anything regarding DELETE FROM DATABASE.

Read only

0 Likes
2,571

I don't think it's applicable here, but it is in the F1 help (deleting data clusters).

Rob

Read only

0 Likes
2,571

Hi

Its there in data cluster help.

regards

sandeep

Read only

0 Likes
2,571

Well, it's something else. Data cluster is not a transparent table. So your advice was misleading.

Read only

gilberto_parga
Participant
0 Likes
2,571

Thank you all guys. First answer is correct. But it could last a time to finish in spite is only a linecode.

Read only

0 Likes
2,571

And depending on the rollback segment size, it could still dump.

Rob