Ansicht
Dokumentation

ABENSHARED_OBJECTS_ABEXA - SHARED OBJECTS ABEXA

ABENSHARED_OBJECTS_ABEXA - SHARED OBJECTS ABEXA

BAL_S_LOG - Application Log: Log header data   RFUMSV00 - Advance Return for Tax on Sales/Purchases  
This documentation is copyright by SAP AG.
SAP E-Book

- Example

This example demonstrates how shared objects are used.

Source Code

Execute

Description

Area Root Class

The global class CL_DEMO_FLIGHT_LIST is used as an area root class. It contains the internal table FLIGHT_LIST of type SPFLI_TAB from the ABAP Dictionary as a public attribute, which is filled by the method SET_FLIGHT_LIST. This table represents the non-modifiable data that is accessed from different programs.

Area

CL_DEMO_FLIGHTS is used as an area whose properties are maintained in the transaction SHMA. Apart from two exceptions the default values were applied:

  • Versioning is deactivated because the data of the area instance should not be changed at program runtime.
  • The lifetime after the last access is limited to five minutes to prevent memory space from being occupied in the shared memory without a program requiring it.

Brokers and Loaders

The class demo_flight_list_handler encapsulates access to the area for the user (in the real world, this would be a global class). The static constructor creates an instance of this class (singleton). The method get_flight_list is used as a broker. It attempts to set a read lock on an area instance. Since there can only be one read lock within an internal session, a query is first made to establish whether an area handle area already exists. Alternatively, the exception CX_SHM_READ_LOCK_ACTIVE could have been handled, but this is less effective in this example. If the operation is not successful, the method create_flight_list is called, which acts as a loader. This method attempts to set a write lock and to build an area instance with a root object. Any exceptions are propagated to the calling method. A DETACH_ROLLBACK is executed before any possible CX_NO_FLIGHTS exception from SET_FLIGHT_LIST is forwarded to the caller. If the change lock is not removed explicitly, the program is terminated at the end of the current internal session at the latest.

If the area was built successfully, get_flight_list attempts to set a read lock again. If no area instance could be built, get_flight_list creates an object of the class CL_DEMO_FLIGHT_LIST in the current internal session as an emergency measure and fills the internal table flight_list. Finally, a data reference to the flight list is assigned to the return value of the method either in the root object of the shared object or in the local object.

The write lock in create_flight_list is closed explicitly, whereas a read lock in get_flight_list is persisted until the end of the internal session. The latter are possible for areas without versioning if no more writes are to be expected after an area has been built.

Users

The class shm_demo demonstrates a user. The method main creates an object of the class demo_flight_list_handler and attempts to read a reference to the flight list. If accessed successfully, the flight list is displayed in the method display. It is not important for the user whether the data is actually contained in the shared memory or in a local object of the class CL_DEMO_FLIGHT_LIST in case of an error. If no data could be read from the database, a corresponding message is displayed.

After the program call, the area instance version can be examined in transaction SHMM.






General Material Data   Vendor Master (General Section)  
This documentation is copyright by SAP AG.

Length: 4014 Date: 20240423 Time: 101158     sap01-206 ( 79 ms )