Thanks to Durai Ilango for his tip on using SY-DBCNT to limit database access. An alternative technique is to use 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.
Requires Free Membership to View
When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.
Hannah Smalltree, Editorial DirectorThis was first published in November 2001
Join the conversationComment
Share
Comments
Results
Contribute to the conversation