SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP Programming Guidelines → Robust ABAP → Dynamic Programming Techniques →Memory Consumption of Dynamic Memory Objects
Background
In dynamic objects, the actual data is addressed using a reference. This means that dynamic memory objects are always deep objects. Possible dynamic memory objects are:
The maximum total size and number of all dynamically managed memory objects in an internal session are defined in principle by the maximum amount of memory that this session can request to execute programs.
Alongside the available memory on the application server, there are two further technical limits that can restrict the size of individual dynamic memory objects:
Any attempt to exceed these limits results in a runtime error and the termination of the program.
Rule
Avoid memory bottlenecks
When using dynamic memory objects, ensure that the program is not terminated due to a lack of memory.
Details
Memory limits are fixed limitations that cannot be deactivated with programming. To avoid memory bottlenecks, we recommend that you account for:
The only way to prevent memory limits from being exceeded is to use programming to restrict the data loaded into the memory. This applies to processing large data sets and also to object creation. The latter can result in memory bottlenecks, if overly large objects or too many small objects are created. Memory leaks (unused, unreleased memory) can also cause memory problems.
Processing large data sets
You need to process large data sets that are
stored in a persistent storage as one piece, but the sets do not fit into the available memory. In this
case, you must import and process these data sets, either in packages or sequentially. A common language
element here is the PACKAGE SIZE addition. You can this addition when importing
large data sets to internal tables with the SELECT Open SQL statement. Memory-saving
processing of large strings (Large Object, LOB) in database tables is also possible. Locators enable
you to access subfields of strings in database tables. Streaming allows a sequential and gradual transfer of data into the memory. Both concepts were predominantly introduced in ABAP to avoid memory bottlenecks.
Releasing memory
The main advantage of dynamically managed memory is that
it can be released again. Use this option to delete data and objects no longer required, to avoid memory leaks and possible memory bottlenecks:
Note
Note that statically managed data objects can also involve unnecessary memory consumption. For example, large flat structures with unused or initial components, whose initial values require a lot of memory space. Character strings that only contain spaces are particularly significant in Unicode systems with 2 bytes for each space. The situation can become particularly critical if these structures are combined with dynamic techniques (if they are used as internal table rows, for example). Consequently, boxed components were introduced. They support initial value sharing for initial substructures, which means that the initial value of a substructure is created only once in memory. For structures with substructures that have a sparse fill level, this can reduce memory consumption and copy costs significantly.
Bad Example
In the following source code, all the data in a very large database table is imported into an internal table. Here there is an obvious risk of memory bottlenecks.
Good Example
In the following source code, the PACKAGE SIZE addition is used. This restricts the maximum size of the internal table to a secure level.