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:

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:

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:

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

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.