14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

14

Shared Memory

FORM after_save.

DATA: lo_monsters TYPE REF TO zcl_monster_shmo.

TRY.

lo_monsters = zcl_monster_shmo=>attach_for_read( ).

CATCH cx_shm_attach_error.

"If the area does not exist, no need to invalidate it

RETURN.

ENDTRY.

CHECK lo_monsters IS BOUND.

TRY.

lo_monsters->invalidate_area( affect_server = cl_shm_area=>

affect_all_servers ).

CATCH cx_shm_parameter_error

cx_sy_ref_is_initial

cx_dynamic_check.

RETURN.

ENDTRY.

TRY.

lo_monsters->detach( ).

CATCH cx_shm_parameter_error

cx_sy_ref_is_initial

cx_dynamic_check.

RETURN.

ENDTRY.

ENDFORM.

Listing 14.7 Coding an SM30 Event

"after_save

The code in Listing 14.7 is called after the user has just updated table ZTVC_MON-

STERS via SM30. In such a case, you want to make sure that the data in shared

memory also gets updated, so invalidate the shared memory area on every application

server. You can only do this fo r shared memory areas that have been

defined as Transactional. Other shared memory areas can only invalidate the

data on the current application server.

Earlier, you set up the shared memory area such that upon invalidation a new

area is automatically created and the BUILD method is called again to get the new

data from the database. This will happen once on every application server; that is,

if you have six application servers, then each server will have its instance of the

root class rebuilt. This is a bit of a sledgehammer approach, but there is no way to

648

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!