<area_constructor> Area Constructor Class

An area constructor class is a global class with a freely selectable name <area_constructor>, which implements the IF_SHM_BUILD_INSTANCE interface. An area constructor can be implemented in the BUILD interface method.

An area constructor class can be assigned to an area in Transaction SHMA. This is always necessary if the area should be built automatically by calling the area constructor, that is, if the BUILD_KIND and REFESH_TIME components of the PROPERTIES structure of the CL_SHM_AREA class are filled accordingly. If an area should not be built automatically, an area constructor class can be specified for the explicit call of the area constructor using the BUILD method of the area class.

Area Constructor

The following structure is recommended for the area constructor implemented in the BUILD interface method:

...

       1.      First, the area constructor has to use the ATTACH_FOR_WRITE method to create an area handle with a write lock for the area instance that is passed in the INST_NAME parameter. As it cannot ensured that it is possible to set the write lock, even with an area constructor that is called automatically, all exceptions have to be caught and forwarded to the caller of the constructor by triggering the CX_SHM_BUILD_FAILED interface exception. This should pass the original exception to the PREVIOUS parameter of the constructor of CX_SHM_BUILD_FAILED.

       2.      Just like whenever a new area instance version is created, a root object also has to be defined in the area constructor using the SET_ROOT method.

       3.      The area instance version can then be built, that is, objects are stored in the shared memory.

       4.      The area handle that is created has to be released again using the DETACH_COMMIT method.

       5.      If the area constructor was called automatically, a database commit has to be triggered when a transactional area is built.

Example

You can use the following implementation used as a template for your own implementations.

CLASS <area_constructor> IMPLEMENTATION.

  METHOD if_shm_build_instance~build.

    DATA:
      my_handle TYPE REF TO <area>,
      my_data   TYPE REF TO <area_root_class>,
      my_except TYPE REF TO cx_root.

    TRY.
        my_handle = cl_my_area=>attach_for_write( inst_name ).

      CATCH cx_shm_error INTO my_except.
        RAISE EXCEPTION TYPE cx_shm_build_failed
                        EXPORTING previous = my_except.
    ENDTRY.


    CREATE OBJECT my_data AREA HANDLE my_handle.
    my_handle->set_root( my_data ).


    ... " code to build the area instance

    TRY.
        my_handle->detach_commit( ).

      CATCH cx_shm_error INTO my_except.
        RAISE EXCEPTION TYPE cx_shm_build_failed
                        EXPORTING previous = my_except.
    ENDTRY.


    IF invocation_mode = cl_shm_area=>invocation_mode_auto_build.
      CALL FUNCTION 'DB_COMMIT'.
    ENDIF.

  ENDMETHOD.

ENDCLASS.