Skip to Content


What is Shared Memory?

Shared Memory is an area on the application server. This is similar to the Primary memory in a Computer, which is used for faster access to data. In BW, we use SAP Memory to store data that is accessed frequently by programs, queries etc. Instead of going to the database table every time, data is accessed through the shared memory, thereby providing faster data retrieval. This shared memory area can be accessed by all the ABAP programs running on that application server

Access

Shared Memory can be accessed via transaction – SHMM.

Below screenshot shows, the various Shared Memory areas available in a sample system. This screen also provides more details on what is the space allocated for each Shared Memory Area and how much of it is being used. Clicking on the dropdown for “View” and selecting “User” provides more information on, who refreshed/updated the Shared Memory with date, time etc.

Picture1.png

  

How to Create a Shared Memory Area?

To create a Shared Memory Area, there are 2 things to be done.

  1. Define the Shared Memory Object by Creating a “Root Class”
  2. Create the Shared Memory Area by associating the “Root Class”

Define the Shared Memory Object by Creating a “Root Class”:

  1. A Root Class is created the same way, a normal class is created.
  2. This is done in SE24 or SE80.
  3. Here, we define what data will be stored by the class and methods required to access and work with this data.
  4. The only difference between a normal class and this Root Class is, we will have to make the Root Class – “Shared Memory Enabled”

Picture2.png

 

Create the Shared Memory Area by associating the “Root Class”:

  1. Here we define a Shared Memory Area
  2. This is done using transaction SHMA.
  3. Also, we associate the “Root Class” created above as the Global Area Root Class of our area.

   

How to populate Shared Memory using an Automated Program?

Remember, Shared Memory Objects exist as long as the SAP Instance exists. Any server restart, system upgrade etc. activities can remove the instance. Also, any change to the root class needs the existing memory objects to be deleted and updated again.

For this, we can create an automated program that deletes the Shared Memory Objects and updates them easily. The following 4 options are useful.

  1. Delete Shared Memory Objects from Server
  2. Populate Shared Memory Objects in Server
  3. Delete Shared Memory Objects from all Servers
  4. Populate Shared Memory Objects in all Servers

Below Screenshot shows a sample program execution screen with options to choose the “Application Servers” from the dropdown.

 

Picture23.png

   

Sample “Z” Program Code:

*&———————————————————————*
*& Report  ZFXX_SERVER_DETAILS
*&*&———————————————————————*

report  zfxx_shmobj_invalidation.

type-pools:
abap, vrm.

data:
lt_list        
type table of           msxxlist,
ls_list        
like line of            lt_list,
lt_infos       
type                    shm_inst_infos,
ls_infos       
like line of            lt_infos,
gt_list        
type standard table of  vrm_value,
gs_list        
type                    vrm_value.

data:
l_tsx_mapping  
type                 zfxx_tsx_virtual_mapping,
nt_mapping     
type                 zfxx_tsx_virtual_mapping.

data:
hdl            
type ref to          zcl_fxx_shm_vcha_map,
root           
type ref to          zcl_fxx_shm_vcha_map_root,
l_instance     
type                 shm_inst_name,
ro_vmap        
type ref to          zcl_fxx_vcha_map.

selection-screen begin of block b1 with frame title text001.

parameters:
c_ndb    
radiobutton group g1,
c_npop   
radiobutton group g1,
c_nmap   
radiobutton group g1,
c_npall  
radiobutton group g1,
p_dbser  
type              msname2 as listbox visible length 20.
selection-
screen skip.
parameters:
c_nhier  
radiobutton group g1.
selection-
screen skip.
parameters:
c_omap   
radiobutton group g1,
c_opop   
radiobutton group g1.

selection-screen end of block b1.

at selection-screen output.
“Function Module is called to return the list of Application Servers
clear: lt_list, gt_list, ls_list, gs_list.
call function ‘TH_SERVER_LIST’
tables
list           = lt_list
exceptions
no_server_list =
1
others         = 2.

if sy-subrc ne 0.
message ‘Error in getting server list’ type ‘I’.
exit.
endif.

loop at lt_list into ls_list.
move ls_list-name to gs_list-key.
append gs_list to gt_list.
endloop.
call function ‘VRM_SET_VALUES’
exporting
id     = ‘P_DBSER’
values = gt_list.
clear: ls_list, gs_list.

at selection-screen.

if c_ndb eq abap_true or
c_npop
eq abap_true.
read table lt_list into ls_list with key name = p_dbser.
if sy-subrc eq 0.
free lt_list.
append ls_list to lt_list.
else.
message ‘Please select a server name’ type ‘I’.
exit.
endif.
elseif c_npall eq abap_true or
c_nmap 
eq abap_true.
read table lt_list into ls_list with key name = p_dbser.
if sy-subrc eq 0.
delete lt_list where name = p_dbser.
else.
message ‘Please select a server name’ type ‘I’.
exit.
endif.
endif.

if c_npall is initial.
loop at lt_list into ls_list.

“Function Module Created for Invalidation and Re-population of Shared Memory
call function ‘ZF_INVALIDATE_SHM’ destination ls_list-name
exporting
i_nhier = c_nhier
i_nmap  = c_nmap
i_omap  = c_omap
i_opop  = c_opop
i_npop  = c_npop
i_ndb   = c_ndb.
endloop.

elseif c_npall eq abap_true.

call function ‘ZF_INVALIDATE_SHM’ destination p_dbser
exporting
i_instance  =
‘X’
changing
lt_instance = lt_infos.

if lt_infos is initial.
message ‘Shared memory not available in DB server’ type ‘I’.
exit.
endif.

loop at lt_infos into ls_infos.

call function ‘ZF_INVALIDATE_SHM’ destination p_dbser
exporting
i_nrd      = abap_true
changing
c_instance = ls_infos-name
c_mapping  = nt_mapping.

if nt_mapping is initial.
message ‘Shared memory not available in DB server’ type ‘I’.
exit.
endif.

“Loop at all the servers and called invalidate the shared memory for each server
loop at lt_list into ls_list.

“Function Module Created for Invalidation and Re-population of Shared Memory
call function ‘ZF_INVALIDATE_SHM’ destination ls_list-name
exporting
i_npall    = c_npall
changing
c_instance = ls_infos-name
c_mapping  = nt_mapping.
endloop.
endloop.
endif.



How to check consistency of Shared Memory using a Custom Program?

Checking Shared Memory consistency is nothing but, comparing if the contents of Shared Memory are the same as the source object’s contents.

This can be done by simply comparing if the last changed or last updated date of the source is after the last changed/updated date of the Shared memory.

Based on your objects, this program is simple to write.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply