ABAP Shared Objects - Shared Memory Programming Made Easy
ABAP Shared Objects - Shared Memory Programming Made Easy
ABAP Shared Objects - Shared Memory Programming Made Easy
Basic Concepts
Advanced Features 1
Advanced Features 2
What is Shared Memory ?
Data Access without Buffering
Data Access with Buffering by Copy
Data Access with in Place Buffering
Benefits for Application Programming
What is Shared Memory ?
DB
User X
Session
Common data
retrieved from DB and
DB aggregated
User X
Session
Common data
retrieved from DB and
DB aggregated for
each user session
DB
User X
Session
Common data
retrieved from DB
DB
Common
Data
User X
Session
Common data
retrieved from DB,
DB aggregated
User X
Session
Common
Data
User X
Session
User X
Session
User X
Session
Workbench navigation
Data is aggregated only once
Ported to ABAP Shared Objects
Saves 3 MB session memory per user
About 100 times faster at first access
Basic Concepts
Advanced Features 1
Advanced Features 2
Usage Scenarios
Areas and Area Instances
Locking Concept
Creating and Accessing Contents
Usage Scenarios
Exclusive buffers
Access by a single writer or reader
Buffer content is kept across transactions
Common class
defined with class
builder (transaction
SE24)
Checkbox
‘Shared Memory
Enabled’ active
Special class
defined with the
shared objects area
manager
(transaction SHMA)
cl_shm_area
data:
... Open default
myShmHandle type ref to cl_my_area, instance for
myRoot type ref to cl_my_root. write
myShmHandle = cl_my_area=>attach_for_write( ).
Releases lock
Makes reference to root
object unavailable
Handle
Changes must be committed Handle Handle
or rolled back
User X User Y
Methods Session Session
detach
detach_commit
detach_rollback
© SAP AG 2004, SAP TechEd / ABAP251 / 38
Example: Detach from Write Access
data:
...
myShmHandle type ref to cl_my_area,
myRoot type ref to cl_my_root.
myShmHandle = cl_my_area=>attach_for_write( ).
...
if ...
myShmHandle->detach_commit( ). Commit changes
else.
myShmHandle->detach_rollback( ). Rollback changes
endif.
data:
...
myShmHandle type ref to cl_my_area,
myRoot type ref to cl_my_root.
myShmHandle = cl_my_area=>attach_for_write( ).
Example:
x = myShmHandle->root->myObject->myAttribute.
data:
Open default
myShmHandle type ref to cl_my_area.
instance
for read
myShmHandle = cl_my_area=>attach_for_read( ).
myShmHandle->detach( ).
Release lock
Overview on areas,
instances, and
locks
Content browser
Demo 1
Exercise 1
Advanced Features 1
Advanced Features 2
Multi Attach
Preloading
Versioning
Client Dependency
Multi Attach
data:
attach_tab type shm_attach_tab,
attach_wa like line of attach_tab,
error_flag type abap_bool.
attach_wa-area_name = 'ZCL_MY_AREA_1'.
attach_wa-inst_name = cl_shm_area=>default_instance.
attach_wa-lock_kind = cl_shm_area=>lock_kind_read.
insert attach_wa into table attach_tab.
attach_wa-area_name = 'ZCL_MY_AREA_2'.
attach_wa-inst_name = cl_shm_area=>default_instance.
attach_wa-lock_kind = cl_shm_area=>lock_kind_write.
insert attach_wa into table attach_tab.
cl_shm_area=>multi_attach(
importing error_flag = error_flag
changing attach_tab = attach_tab ).
Preloading is
specified at design
time using
transaction SHMA
data:
hdl type ref to zcl_my_area,
excp type ref to cx_shm_no_active_version.
try.
hdl = zcl_my_area=>attach_for_read( ).
catch cx_shm_no_active_version into excp.
if excp->textid <>
cx_shm_no_active_version=>build_started and
excp->textid <>
cx_shm_no_active_version=>build_not_finished.
raise exception excp.
endif.
wait up to 1 seconds.
hdl = zcl_my_area=>attach_for_read( ).
endtry.
Instance
Version: active
Reader1
Instance
Reader1
Writer
Instance
Reader1
Reader2 Writer
Instance
Reader1
Reader2
© SAP AG 2004, SAP TechEd / ABAP251 / 60
Versioning Example
Instance
Reader1
Reader2 Reader3
Instance
Reader1
Reader3
Instance
Reader3
Instance
Version: active
Reader3
The 4 States
1. Under construction (0..1): As long as a version is being changed
2. Active (0..1): Last committed version used for further read attaches
3. Out of date (0..n): Version with still attached readers, no further read
attaches possible
4. Expired (0..n): Out of date and no more readers; will be automatically
garbage collected
Versioning is
specified at design
time using
transaction SHMA
Client dependency
is specified at
design time using
transaction SHMA
Demo 2
Exercise 2
Advanced Features 1
Advanced Features 2
Transactional Areas and Propagation
Displacement
Memory Limits
Binding
Transactional Areas Motivation
Database changes
Area
Instance
Version
1
Database
Database changes
Area
Area instance depending on
database changes Instance
Version
1
Version
2
Database
Database changes
Area
Area instance depending on
database changes Instance
Area commit, version 1 gets
out of date Version
1
Version
2
Database
Database changes
Area
Area instance depending on
database changes Instance
Area commit, version 1 gets
out of date and expires
Version
2
Database
Database changes
Area
Area instance depending on
database changes Instance
Area commit, version 1 gets
out of date and expires
???
Database
detach_commit DB commit
© SAP AG 2004, SAP TechEd / ABAP251 / 80
Propagation Motivation
Database
Instance changes
Database
Version 2
Database
Version 2
Database
Database
Transactional Areas
are specified at
design time using
transaction SHMA
Propagation is done
via invalidation
using the
PROPAGATE
methods
data:
root type ref to zcl_my_area_root,
hdl type ref to zcl_my_area.
hdl = zcl_my_area=>attach_for_write( ).
create object root area handle hdl.
hdl->set_root( root ).
hdl->detach_commit( ).
zcl_my_area=>propagate_instance( ).
commit work.
Displacement is
specified at design
time using
transaction SHMA
Memory Limits is
specified at design
time using
transaction SHMA
Lifetime is specified
at design time using
transaction SHMA
Demo 3
Exercise 3
Session Area
Reader
Instance1
Reader
Instance2
Reader
Instance3
Writer
Conceptual
Error handling via exceptions
Query methods for handle state
Special roll handle to address roll area
Technical
Consistency check for types used at area
build-up and attach time
Garbage collection for area instances
Copy-on-write becomes copy-on-detach for
internal tables and strings
Î Public Web:
www.sap.com
SAP Developer Network: www.sdn.sap.com
SAP Customer Services Network: www.sap.com/services/
Coming in December.
http://www.sdn.sap.com/
Q&A
Thank You !