Skip to Content
0

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

Nov 24, 2017 at 07:43 AM

111

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Horst Keller
Nov 28, 2017 at 07:08 AM
2

"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_organization.htm

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).

Share
10 |10000 characters needed characters left characters exceeded
Jörgen Lindqvist Nov 24, 2017 at 09:36 AM
1
Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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
Former Member

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.

0

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

1
Suhas Saha
Nov 24, 2017 at 09:09 AM
1

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=abenasxml_class_instances.htm

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Nov 24, 2017 at 09:12 AM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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