SAP CREATE DATA AREA HANDLE ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID CREATE-DATA-AREA-HANDLE
• AREA HANDLE CREATE DATA

CREATE DATA, AREA HANDLE
Short Reference

ABAP_SYNTAX
CREATE DATA dref AREA HANDLE handle ...

What does it do?
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 bound to 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 ABAP_ISESS and the statement CREATE DATA works in the same way as without the addition AREA HANDLE.
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 ABAP_ISESS .
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: All data types created in a temporary subroutine pool created using GENERATE SUBROUTINE POOL. Data types created dynamically at program runtime using methods of the RTTC. Bound data types of anonymous data objects created at program runtime, to which a dynamic length was assigned when they were created with CREATE DATA. Bound data types of anonymous data objects created at program runtime and that were assigned a dynamic type that requires a length specification when they were created using CREATE DATA.
Points 3 and 4 particularly include the statement CREATE DATA with the addition AREA HANDLE itself. Exceptions to the restrictions listed in points 2 to 4 are:
The restrictions do not apply to the data type p.
The restrictions do not apply to the data types c, n, and x, as long as the memory requirement does 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 restrictions:
All visible data types of global interfaces and classes.
Data elements, DDIC structures, and DDIC database tables and DDIC table types of the ABAP Dictionary.
Data types from type pools.
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 after each change to the creating program.
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.



Latest notes:

The only shared object that can be addressed from an ABAP program directly after an area instance version is bound is the instance of the area root class. All other objects must be referenced in this instance. In particular, no direct access to anonymous data objects is possible. Instead, the instance of the area root class must contain references to these anonymous data objects, which can also be indirect.
It is recommended that only global data types together with AREA HANDLE are used. As an occasional replacement for the direct reference to data elements and table types of the ABAP Dictionary, the respective types can be created in global interfaces, classes, or even type pools.
ABAP_HINT_END



Example ABAP Coding

Creation of an anonymous structure in an area instance version of area CL_DEMO_AREA.
ABEXA 00155
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
Creating a Data Object as a Shared Object
ABAP_EXAMPLE_END



Runtime Exceptions



Catchable Exceptions
CX_SHM_WRONG_HANDLE
Reason for error:
The area handle does not hold any change locks.
CX_SHM_ALREADY_DETACHED
Reason for error:
The area handle is not bound to an area instance version.
CX_SHM_OUT_OF_MEMORY
Reason for error:
There is not enough memory.

Return to menu