ERPClimb logoERPClimb
Performance Tuning
ABAP Developmentadvanced 7 min read

Performance Part 9: Package Processing for Large Data Volumes

Preview · a free account unlocks the full lesson

Key takeaway

Process millions of records safely: SELECT … PACKAGE SIZE with ENDSELECT, OPEN CURSOR WITH HOLD / FETCH NEXT CURSOR, committing between packages, restartability, memory limits, and parallel processing with background jobs or aRFC for very large runs.

In this lessonShow sections

Visual overview

Performance Part 9: Package Processing for Large Data Volumes — learning sheetFlow: Rewrite a full-table read to SELECT … PACKAGE SIZE → Add OPEN CURSOR WITH HOLD with a commit per package (test system) → Store the last processed key and test a restart. Key ideas: WHY PACKAGES; SELECT PACKAGE SIZE; OPEN CURSOR WITH HOLD; RESTARTABILITY. Watch out: Design for restart: if a job fails after 3 of 10 million records, it must continue without duplicating work (status flags, last processed key, logs).ERPClimb.com / ABAP / LESSON 9/10 / LEARNING SHEETPerformance Part 9: Package Processing for Large DataVolumes1 · HOW IT FLOWS1Rewrite a full-table readto SELECT … PACKAGE SIZE2Add OPEN CURSOR WITH HOLDwith a commit per package(test system)3Store the last processedkey and test a restart2 · KEY IDEAS EXPLAINEDWhy PackagesMemory: bounded by package size.Commits: long LUWs hold locks and rollbacksegments; packages allow commits.Select Package SizeSELECT … INTO TABLE lt_pkg PACKAGE SIZE 10000 …ENDSELECT: lt_pkg is overwritten each pass.No COMMIT inside (it would close the cursor → dumpDBIF_RSQL_INVALID_CURSOR).Open Cursor With HoldOPEN CURSOR WITH HOLD lv_cursor FOR SELECT …; DO.FETCH NEXT CURSOR lv_cursor INTO TABLE lt_pkgPACKAGE SIZE n. IF sy-subrc <> 0. EXIT…WITH HOLD keeps the cursor open across databasecommits (COMMIT WORK in newer releases; checkrelease notes — DB commit via DB_COMMIT is the…RestartabilityProcess in key order; store the last processed keyin a status table after each package.Mark processed records (status field) or writeidempotent updates.3 · REMEMBER · WATCH OUTRememberReading millions of rows into one internal table can exhaust memory(TSV_TNEW_PAGE_ALLOC_FAILED); process in packages instead.SELECT … INTO TABLE … PACKAGE SIZE n … ENDSELECT processes n rows perpass; OPEN CURSOR / FETCH NEXT CURSOR … PACKAGE SIZE gives more…COMMIT WORK between packages closes normal cursors — use OPEN CURSORWITH HOLD when you must commit while reading.!Watch outDesign for restart: if a job failsafter 3 of 10 million records, itmust continue without duplicatingwork (status flags, last processedkey, logs).4 · IN A REAL PROJECTA data-cleansing job read 45 million accounting lines into one table and dumped withTSV_TNEW_PAGE_ALLOC_FAILED after 2 hours. The next attempt used PACKAGE SIZE but called COMMIT WORK insideSELECT…ENDSELECT and dumped with an invalid cursor. The final version used OPEN CURSOR WITH HOLD, a database…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Parts 4 through 8 made each individual read efficient. For very large data volumes, though, the structure of the program itself needs to change, and that's what this part covers.

The reasoning behind processing in packages comes down to a few things at once. Memory stays bounded by the package size, rather than growing with the full data volume. Reading millions of rows into one internal table can exhaust memory (TSV_TNEW_PAGE_ALLOC_FAILED); process in packages instead. Commits also matter: a single long-running LUW holds locks and rollback segments for its entire duration, while processing in packages allows commits along the way. And packages naturally give you progress tracking and restart points as a side effect.

The simplest form of this is SELECT … INTO TABLE lt_pkg PACKAGE SIZE 10000 … ENDSELECT. SELECT … INTO TABLE … PACKAGE SIZE n … ENDSELECT processes n rows per pass; OPEN CURSOR / FETCH NEXT CURSOR … PACKAGE SIZE gives more control. Here, lt_pkg gets overwritten on each pass through the loop, and committing inside the loop is not allowed — doing so closes the cursor and causes the dump DBIF_RSQL_INVALID_CURSOR.

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

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

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.