Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Singleton Object

Former Member
0 Kudos
429

Hi all,

is it possible to create systemwide unique objects?

I know of the singleton class, but I do not want to create a unique class instance,

but I want to create some kind of factory class which gives unique objects.

For instance I want to create delivery objects and I do not want multiple users

to create the same delivery object (you can imagine why).

How can I achieve this?

Greetings Fred.

6 REPLIES 6

Former Member
0 Kudos
151

hi

Singleton

If it is to be impossible to instantiate a class more than once (for example, because it serves as a data administrator or data container), you can use the singleton concept. The class is defined with the addition CREATE PRIVATE and FINAL and instantiated using its static constructor.

Former Member
0 Kudos
151

Hi,

The only really systemwide (User sessin, application servers, etc.) available memory is the database.

So i think the only way to achieve your requirement is to use the Database as global memory.

First

1)Create a DB table that saves the unique criterias of your deliveries.

2)Implement the Semaphore pattern (even using database as global memory)

Your factory have to

1)Lock (Semaphore pattern) the entire table of unique keys. So can you ensure that a another existing factory (for example on a separate application server) creates at the same moment a equal key.

2)Create a key that identifies uniquely your Delivery.

3)Save the key on the database and commit the transaction.

Now it is possible for your factory (on the other application server or in the other User session) to detect if a user just creates the same delivery.

You shuld not forget to delete the lock also if the user abort the creation.

Is this for you a solution approach?

Regards,

Gianpietro

0 Kudos
151

Damn, I was hoping not to have to use a table for this.

I have already build a solution like this,

but thougt that there should be a better way to achieve this.

0 Kudos
151

Hi Fred,

you might want to consider using a GUID as the unique key for your objects. A GUID is a unique system wide ID. You can create each one using the function module GUID_CREATE.

I would also use this problem as an excuse to look at Shared Objects. The possibilities with Shared Objects are fantastic.

Cheers

Graham

0 Kudos
151

What you are doing here is as you've found out is to try and get round the limits of using OO in a " Classic Relational Database" system.

When SAP starts using OBDBMS (Object database system) and can geuninely save objects as "persistent" in this type of database system then it probably can be done.

However in the current SAP system complex objects can only be built from data held in large numbers of different tables which may have a complex relationship (by virtue of the RDBMS - relational data base system) so "Locking" this stuff system wide is not really (AFAIK) an option.

A possibility is to use the JDO in JAVA where you can create genuine persistant objects which are held in a type of "OBDBMS" or Object data base management system as opposed to the traditional RDBMS (Relational model) that SAP uses.

The JAVA JDO handles the actual SAP data base updates and maintains Data integrity between the JAVA object and the various SAP tables.

Classic ABAP currently isn't really geared to handle this yet. OO Abap is a HUGE improvement but still essentially limited by use of the underlying RDBMS (relational data base system) and (internal) SQL queries to retrieve the data from various tables when "constructing" / instantiating your object.

Graham's suggestion seems to be the nearest you can get to answering this problem.

However if anybody does have an answer to this I'll also be interested so please post on this thread.

uwe_schieferstein
Active Contributor
0 Kudos
151

Hello Fred

Actually I only have a good guess for you but perhaps storing this singleton instance in the <b>shared memory</b> may be way to match your requirement.

I am sure the new book written by Rich Heilman and Thomas Jung about cutting-edge ABAP techniques will give you indications whether this might be a solution.

Regards

Uwe