Get Example source ABAP code based on a different SAP table
ABAP_SHM - Writing to and Reading from an Area This example demonstrates the writing to and reading from an area.
ABAP_SOURCE_CODE DEMO CL_DEMO_SHARED_OBJECTS_RW
ABAP_DESCRIPTION
Area Root Class The global class CL_DEMO_SO_ROOT> > is used as an area root class. It contains three data objects number>, first_name> and last_name> as private attributes. The methods WRITE> and READ> are used to set values for the data objects and read those values.
Area CL_DEMO_SH_OB_AREA>> is used as an area whose properties are maintained in the transaction SHMA>>. 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.
Description The internal table values> is filled with data the writing and reading procedure is based on. It also provides instance names. The table is looped across to write the entries to the area. First, an area is created before any data can be written to the shared memory using the method ATTACH_FOR_WRITE>>. This method call includes the instance name that is provided in the internal table. This method returns a handle to the area (or instance), that has just been created in the shared memory. Then, a root object is created for the instance using a CREATE OBJECT ... AREA HANDLE ...>> statement that includes the handle returned by the method call before. The WRITE> method of the root reference is called providing the values for the attributes that are stored in the shared memory. Calling the DETACH_COMMIT>> method releases the change lock. The internal table is looped across again to read from the instances using the instance names. The ATTACH_FOR_READ>> method is called using those instance names and the area handle as parameters. Using the READ> method, the values of the attributes of the individual instances that have been created before are retrieved from the shared memory. Calling the DETACH>> method releases the read lock. After the executing the class, the area instance versions can be examined in transaction SHMM>>.