ERPClimb logoERPClimb
Open SQL
ABAP Developmentadvanced 8 min read

Open SQL Part 7: PACKAGE SIZE and Large Data Processing

Preview · a free account unlocks the full lesson

Key takeaway

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 sections

Visual overview

Open SQL Part 7: PACKAGE SIZE and Large Data Processing — learning sheetIn one line: 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.ERPClimb.com / ABAP / LESSON 7/10 / LEARNING SHEETOpen SQL Part 7: PACKAGE SIZE and Large Data Processing1 · IN ONE LINEProcess millions of rows without memory dumps or timeouts: SELECT … PACKAGE SIZE, OPENCURSOR / FETCH, commit handling in long jobs, restartability and parallel processing basics.2 · KEY IDEAS EXPLAINEDSelect … Package SizeEach pass replaces gt_pkg with the next package(APPENDING TABLE accumulates — usually not whatyou want).sy-dbcnt counts all rows read so far.Open Cursor / FetchUseful when processing is split across methods orneeds commits.WITH HOLD keeps the cursor open across databasecommits.Commits In Long JobsLarge updates in one LUW lock many rows and fillthe rollback segments — commit per package.Never COMMIT inside SELECT … ENDSELECT (cursor islost → runtime error on next fetch).RestartabilityKeep a status per record (processed flag, logtable) so a restarted job skips done work.Log package progress (application log / job log).3 · DO · AVOIDBest practice!Common mistakePACKAGE SIZE or cursors for mass reads.WITH HOLD cursors when committing per package.Mass DML (INSERT/UPDATE FROM TABLE) perpackage.✕Loading everything into one internal table.✕COMMIT WORK inside SELECT … ENDSELECT.✕One giant LUW for millions of updates.4 · IN A REAL PROJECTA migration program copied 25 million booking records into a new table with one INSERT per row and a singleCOMMIT at the end. After six hours it dumped because the database's rollback space was exhausted, and the workwas lost. The redesign read with OPEN CURSOR WITH HOLD in packages of 20,000, inserted each package with…Original ERPClimb learning sheet • Verify against your SAP release and edition

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.

Free account

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

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.