Open SQL Part 7: PACKAGE SIZE and Large Data Processing
Preview · a free account unlocks the full lesson
Process millions of rows without memory dumps or timeouts: SELECT … PACKAGE SIZE, OPEN CURSOR / FETCH, commit handling in long jobs, restartability and parallel processing basics.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Parts 1 through 6 of this series dealt with manageable data volumes, but interfaces, archiving preparation, and data migrations often need to read millions of rows, and this part covers the classic tools for that.
SELECT … INTO TABLE … PACKAGE SIZE n … ENDSELECT processes n rows at a time, keeping only one package in memory. For example: SELECT … FROM sbook INTO TABLE gt_pkg PACKAGE SIZE 10000 WHERE …, then process gt_pkg (write a file, post, aggregate), ENDSELECT. Each pass replaces gt_pkg with the next package — APPENDING TABLE would accumulate everything instead, which is usually not what you want — and sy-dbcnt keeps a running count of all rows read so far.
OPEN CURSOR and FETCH give you more control, for instance when processing is split across method calls or needs commits in between.
The pattern is: OPEN CURSOR WITH HOLD lv_cursor FOR SELECT … FROM sbook WHERE …, then inside a DO loop, FETCH NEXT CURSOR lv_cursor INTO TABLE gt_pkg PACKAGE SIZE 10000, exiting when sy-subrc <> 0, otherwise processing the package and issuing COMMIT WORK (which is allowed because the cursor was opened WITH HOLD), and finally CLOSE CURSOR lv_cursor. The WITH HOLD clause is what keeps the cursor open across database commits.
Create a free account to keep reading
You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.
- Full explanation
- Code example
- Real project scenario
- Common mistakes
- Best practices
- Interview angle
One tap with Google works too. Every topic keeps its first lesson open to everyone.
Keep exploring
Interview questions on this topic
Related SAP topics
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.