2012 Apr 11 4:47 PM
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!
2012 Apr 11 5:04 PM
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.
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!
2012 Apr 11 5:04 PM
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.
2012 Apr 12 10:08 AM
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.
2012 Apr 12 5:37 PM
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
2012 Apr 12 3:40 PM
Hi,
Try to use Open SQL with below syntax.
DELETE FROM DATABASE ztable client sy-mandt.
regards
sandeep
2012 Apr 12 3:50 PM
Where did you find this syntax?
In the ABAP help I cannot find anything regarding DELETE FROM DATABASE.
2012 Apr 12 4:33 PM
I don't think it's applicable here, but it is in the F1 help (deleting data clusters).
Rob
2012 Apr 12 4:35 PM
2012 Apr 12 4:57 PM
Well, it's something else. Data cluster is not a transparent table. So your advice was misleading.
2012 May 25 10:02 PM
Thank you all guys. First answer is correct. But it could last a time to finish in spite is only a linecode.
2012 May 25 10:06 PM
And depending on the rollback segment size, it could still dump.
Rob