ABAP Keyword Documentation → ABAP − Reference → Creating Objects and Values → CREATE DATA
CREATE DATA - AREA HANDLE
Other versions: 7.31 | 7.40 | 7.54
Syntax
CREATE DATA dref AREA HANDLE handle ...
Effect
This statement creates an anonymous data object as a
shared object in the
area instance version of the
shared memory to which the
area handle referenced by handle
is bound.
handle
expects an object reference variable whose static type is CL_ABAP_MEMORY_AREA or one of its subclasses
(area class). When the statement is executed, handle
must point to an
area handle and the area
handle must be associated with an area instance version with a change lock. A reference like this can be created in one of the following ways:
- By inheriting the return value of the methods ATTACH_FOR_WRITE or ATTACH_FOR_UPDATE of an area class created using transaction SHMA.
- By inheriting the return value of the method GET_HANDLE_BY_... of any area class.
-
By inheriting the return value of the method GET_IMODE_HANDLE of the predefined class CL_IMODE_AREA.
The latter is a reference to an area handle for the current
internal session and
the statement CREATE DATA
operates as if the addition AREA HANDLE
is not specified.
Restrictions
The creation of anonymous data objects as shared objects is subject to the following restrictions for data references in the shared objects memory: the storage of data references in closed area instance versions of the shared objects memory is restricted to those dynamic types that are known when loading a program into an internal session.
Therefore, the following data types cannot be used to create anonymous data objects in the shared object memory, if these are to be preserved in a closed area instance version:
GENERATE SUBROUTINE POOL
.
CREATE DATA
.
CREATE DATA
.
Points 3 and 4 include the statement CREATE DATA
with the addition AREA HANDLE
itself. Exceptions to the restrictions listed under points 2 to 4 are:
-
The restrictions are not valid for data type
p
. -
The restrictions are not valid for data types
c
,n
, andx
as long as the memory requirements do not exceed 100 bytes.
If a data reference variable that is stored in the shared objects memory refers to an anonymous data object of a dynamic type that is subject to the restrictions, the exception of the class CX_SHM_EXTERNAL_TYPE is raised when the DETACH_COMMIT method is executed.
The following can be used without restriction:
- All visible data types of global interfaces and classes.
- Data elements, structures, and database tables and table types from ABAP Dictionary.
- Data types from type groups.
-
Bound data types of anonymous data objects created at program runtime to which a static type with a static length was assigned when they were created using
CREATE DATA
. -
Bound data types of anonymous data objects created at program runtime to which a fully specified dynamic type was assigned when they were created using
CREATE DATA
. -
All data types that were created statically in the same program using declarative statements. It should
be noted, however, that it is no longer possible to access existing area instances once the creating program is changed.
The additions REF TO
and TABLE OF
can be used
as long as the specified types meet the above requirements. This also applies to the addition
HANDLE
, which means the type description object must have been created with methods of the
RTTI from allowed types.
Notes
- The only shared object that can be addressed from an ABAP program directly after a binding is made to an area instance version is the instance of the area root class. All other objects have to be referenced in this instance. In particular, there is no direct access to anonymous data objects possible. Instead, the instance of the area root class must contain references to these anonymous data objects, which can also be indirect.
-
It is best to use only global data types with
AREA HANDLE
. As an occasional replacement for the direct reference to data elements and table types from ABAP Dictionary, the respective types can be created in global interfaces, classes, or even type groups.
Example
Creates an anonymous structure in an area instance version of area CL_DEMO_AREA.
DATA: root TYPE REF TO cl_demo_root,
handle TYPE REF TO cl_demo_area.
...
handle = cl_demo_area=>attach_for_write( ).
CREATE OBJECT root AREA HANDLE handle.
handle->set_root( root ).
CREATE DATA root->dref AREA HANDLE handle TYPE scarr.
...
Executable Example
Creating a Data Object as a Shared Object
Exceptions
Handleable Exceptions
CX_SHM_WRONG_HANDLE
-
Cause: The area handle does not hold any change locks.
CX_SHM_ALREADY_DETACHED
-
Cause: The area handle is not bound to an area instance version.
CX_SHM_OUT_OF_MEMORY
-
Cause: There is not enough memory.