‎2007 Jul 16 2:26 PM
I'm wondering if there is any possiblity to create ABAP objects which are globally (from all users in all session) accessible.
I want to implement the flyweight pattern (http://en.wikipedia.org/wiki/Flyweight_pattern) using ABAP objects.
I have some small objects which needs a lot of calculation and database access for the creation. This objects are needed very often, but there are only a few different shapes of the object. So I'm using the flyweight pattern for avoiding expansive object instantiation.
I implemented the pattern as follows: For the class I created a static hash table with the line type of an string identifier and a reference to an object instance with the type of the class.
Then I added a static method "get_instance" which gets an identifier as input and looks up for the object in the static hash table. If it's not found it will be created and added to the table.
Now I have a problem: it seems that static attributes are not really static in ABAP, but only for the current user session.
Since I want to avoid as much creation time as possible I want to access this table globally.
Then I tried the "Shared Objects" mechanism introduces in AS 6.40. But it seems that I can't store object references in shared objects. If I try write a object with a reference I get an exception.
Does anybody know if there is a possibility to access objects globally for all users and sessions?
Best regards
Achim
‎2007 Jul 16 3:34 PM
The only possibility I can see here is to make the objects persistent. That however doesn't come "free". So, depending on the durability of your data it might be a better approach to work with Z-Tables.
‎2007 Jul 16 3:34 PM
The only possibility I can see here is to make the objects persistent. That however doesn't come "free". So, depending on the durability of your data it might be a better approach to work with Z-Tables.
‎2007 Jul 16 4:22 PM
AFAIK, Shared Object Memory (as part of Shared Memory) is App-Server specific. I.e. with Shared Memory you can share data between sessions but not between servers.
In order to export objects to shared memory, you must define them as
CLASS class DEFINITION ... SHARED MEMORY ENABLED.
(for global classes - check properties).
There are also other things that may go wrong, so you might want to check the documentation:
http://help.sap.com/saphelp_nw2004s/helpdata/en/14/dafc3e9d3b6927e10000000a114084/frameset.htm
HTH,
Hristo
‎2007 Jul 16 4:28 PM
Yes I know how to use the shared objects. But there is the problem that a shared object itself can't reference to other objects, that will raise an exception.
So it's not possible to create a shared object which contains a hashed table with references to other objects.
By measuring runtime I also find out the read access to a shared object is pretty slow
‎2007 Jul 16 5:05 PM
> By measuring runtime I also find out the read access
> to a shared object is pretty slow
Yes, this is what I meant. And you'll find persistent objects even much slower. If you store the data you want to share on the DB, this should be a lot faster- and easier !
Oh, if you ever worked with an OODBMS such as ObjectStore or POET you will find, that this isn't an SAP specific problem.
‎2007 Jul 17 7:32 AM
I never worked with over OODBMS but I also don't won't to make the objects persistent.
I just want something like in Java or an other OO-language where an static attribute of a class is globally (at least for the server or vm instance) accessible.
It seems that there's possibility to achieve this with ABAP Objects.
On the other side there's no other mechanism in ABAP like an memory cache for storing transient objects globally. I would like to have something like the KM cache in the SAP portal , there I can store usually object instances (not specially marked as shared objects) and there are accessible very fast.
‎2007 Jul 17 9:12 AM
Well, it might be possible or not, but if the case is that creating the data in question is very performance intense but the amount of data is not that big, then you'd be better off to store this data in a z-table, possibly with time stamp and valid-to stamp and create a class that has a static method get_data which will check if it has already this static data and if not, then it will read it from this z-table. I believe performance wise this would be the best thing to do ...