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: 

One instance of a class over several sessions (ABAP singleton not working)

Former Member
0 Kudos

Hi all,

in other programming languages the singleton works different from ABAP.

In ABAP more than one Instance of the singleton can be created, as the creation/instanciating in ABAP is only per session.

What I need is a "real" singleton as in JAVA ...

Multiple sessions should only have exactly one common class (in the sense of other programming languages)

Does anybody know, how to achieve this?

Regards

Mario

8 REPLIES 8

SuhaSaha
Advisor
Advisor

The only way i can think of achieving this is via "serializing" the object. Cf.

https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-us/abenasxml_class_instances.htm?file=abenas...

Former Member
0 Kudos

Hi suhas,

thanks. As I don't have any knowlege regarding asXML I think it is not a apropriate solution for my problem 🙂

Many thanks

Regards

Mario

0 Kudos

Hi Mario,

The (de)serialization is handled by the identity Transformation(id).

You could have a look at the demo program DEMO_SERIALIZABLE_OBJECT to see how it works.

BR Suhas

0 Kudos

Hi Jörgen,

unfortunately the shared memory does not meet my requirements.

What I wanted to achieve:

I created an ALV-Grid: Think of a ToDo-Liste where more than one user can work with simultationously.

Asuming user #1 is updating a row #xy in the ALV Grid. Now I wanted to notify all other users by a popUp working on the ALV-Grid, that row xy was updated by user #1.

My initial attempted was to create a singleton-class which throws an event.

As I wrote before, a singleton is instanciated for each session. So this does not work.

Also - unfortunatelly- the shared memory does not work as events are not allowed in shared-memory classed.

Do you see any other approach?

Regards

Mario

0 Kudos

I forgot to mention that the ALV-Grid class ist listening for the notifierr-event, when my notifier-class is throwing the event "row xy " changed.

I see. So basically what you want is for one instance of your ALV-Grid to be able to send a message to the other instances to say "Hey, my user just updated this item". You should check out ABAP Messaging Channels

https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenamc.htm

horst_keller
Product and Topic Expert
Product and Topic Expert

"in other programming languages the singleton works different from ABAP"

Well other programming languages are not running on an AS ABAP. Look at the picture under

https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenmemory_organiz...

Where should your singleton reside? Normal objects live in the internal session. Above we have shared objects in the shared memory. Before release 7.52 that's all ABAP can offer.

From 7.52 on, the user memory will comprise the ABAP Daemon Memory, where ABAP Daemons can store their context specific memory. ABAP Daemons also will be able to react on events. (the German version of the ABAP Keyword documentation already introduces Daemons, an upload of the englisch translation will follow soon). Daemons can be created as singletons (but not so easy).