Thanks to Durai Ilango for his tip on using SY-DBCNT to limit database access. An alternative technique is to use...
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
the UP TO n ROWS feature of the SELECT command.
When you use SY-DBCNT to limit your rows, the database manager does not know that you are doing that and so returns a full 32K block of rows. If you use the UP TO n ROWS feature of SELECT, then that information is passed to the database manager and it will only return the number of rows you requested. You can than avoid APPENDing to your internal table and instead load the table directly.
The original example: select * from bkpf into corresponding fields of itab where bukrs in co_code "Company code and gjahr in fyear "fiscal year and blart in doctype "document type and belnr in docno . "test only * AND cpudt IN pa_cpudt. if sy-dbcnt ge 5. exit . endif. append itab. clear itab. endselect. and an example using UP TO n ROWS: select * from bkpf up to 4 rows into corresponding fields of table itab where bukrs in co_code "Company code and gjahr in fyear "fiscal year and blart in doctype "document type and belnr in docno . "test only * AND cpudt IN pa_cpudt.