CREATE DATA - AREA HANDLE
Syntax
CREATE DATA dref AREA HANDLE handle ... .
Effect
This statement creates an anonymous data object as
shared object in the
area instance version of the
shared memory, which is bound to the
area handle referenced by handle.
For handle, an object reference variable must be specified, 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 bound to an area instance version with a change lock. To create such a reference, you have the following options:
-
Transfer of the return value of the methods ATTACH_FOR_WRITE or ATTACH_FOR_UPDATE of an area class created with SHMA.
-
Transfer of the return value of the method GET_HANDLE_BY_OREF of any area class.
-
Transfer of 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 mode and the statement
CREATE DATA acts like without the addition AREA HANDLE.
Restrictions
The creation of anonymous data objects as shared objects is subject to 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 possible since release 7.0 and restricted to such
dynamic types that are known when loading a program into an internal mode.
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:
-
Data types created at runtime, that means, data types that were created dynamically with the methods of the
RTTC and bound data types of anonymous data
objects, which were defined not until the data objects were created with CREATE DATA.
-
All data types that were created in a temporary pool of sub-routines created by GENERATE SUBROUTINE POOL.
-
Data elements of the ABAP Dictionary (currently due to technical reasons).
-
Table types of the ABAP Dictionary (currently due to technical reasons).
If a data reference variable, which is stored in the shared objects memory, refers to an anonymous data
object of such a dynamic type, the exception of the class CX_SHM_EXTERNAL_TYPE is raised when the DETACH_COMMIT method is executed. Alternatively, you can use:
-
All visible data types of global interfaces and classes.
-
Structures and database tables of the ABAP Dictionary.
-
Data types from type groups.
-
All data types that were created statically in the same program with declarative statements. However, you should note that you can no longer access existing area instances once you changed the creating program.
The additions REF TO
and TABLE OF can
be used until the specified types fulfill above requirements. This also applies for the addition
HANDLE, that means the type 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 connecting an area instance version, is the instance of the
area root class. All other objects
must 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.
-
We recommend that you only use global data types with AREA HANDLE.
As an occasional replacement for the direct reference to data elements and table types of the ABAP Dictionary, you can create the respective types in global interfaces, classes, or even type groups.
Example
After creating an area handle referenced from my_handle,
which is bound to an area instance version of the area my_area
(inluding write authorization), an instance of the area root class cl_my_data
of the area is created. The area root class contains a generically typed (using
REF TO data) data reference variable dref as
public attribute. With CREATE DATA, you create an anonymous data object in the area instance version, which is fed with a value after it has been assigned to a field symbol.
-
DATA: my_handle TYPE REF TO cl_my_area,
my_data TYPE REF TO cl_my_data.
FIELD-SYMBOLS <fs> TYPE ANY.
TRY.
my_handle = cl_my_area=>attach_for_write( ).
CREATE OBJECT my_data AREA HANDLE my_handle.
my_handle->set_root( my_data ).
CREATE DATA my_data->dref AREA HANDLE my_handle TYPE i.
ASSIGN my_data->dref->* TO <fs>.
<fs> = 999.
my_handle->detach_commit( ).
CATCH cx_shm_external_type.
...
CATCH cx_shm_attach_error.
...
ENDTRY.
In another program, you can access the shared object as follows
-
DATA my_handle TYPE REF TO cl_my_area.
FIELD-SYMBOLS <fs> TYPE ANY.
TRY.
my_handle = cl_my_area=>attach_for_read( ).
ASSIGN my_handle->root->dref->* TO <fs>.
... <fs> ... .
my_handle->detach( ).
CATCH cx_shm_attach_error.
...
ENDTRY.