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: 

Making a static variable accessible across different sessions!

Former Member
0 Kudos
5,109

Hi Folks,

I have a class with a static variable (internal table). My intention is, to share this variable across sessions. (everytime filling the table is expensive). But this works within a session. whenever i create a new session and executes, a separate instance of this variable is created.

How to make this variable accessible across different sessions. In java app servers, we can do the same by placing the files in specific class folders. How can we achieve the same with ABAP?

Thanks and Regards

Shahul

21 REPLIES 21

former_member181962
Active Contributor
0 Kudos
725

Hi Shahul,

Try creating a Global class in se24. I assume you are creating that class locally as of now.

Regards,

ravi

0 Kudos
725

Hi ravi,

The class which i created is a global one. It doesn't work when i work with different sessions (windows).

Regards

Shahul

0 Kudos
725

Sessions mean by ?

vijay

former_member188685
Active Contributor
0 Kudos
725

Hi Using SE24 you can create global class .

and with the static variable . you can call this where ever it is required.

regards

vijay

Former Member
0 Kudos
725

Hi Shahul,

Create a globla class in SE24 and declare the variable as static public variable. So that data will be accessed by all who all are instantiating it.

Hope this will help you.

Thanks & Regards,

Siir.

0 Kudos
725

Hi guys,

The class I created is a global one via se24.

Its static and public.

Let me explain the scenario.

I have a program which uses this class and its static variable. during the initialization, i loaded tat variable. Now I open another R/3 window (/o) and executes the same program. But now , the static variable is initial and the initialization happens again.

Hope it is clear!

Regards

Shahul

0 Kudos
725

Hi shauhul,

Try this solution. Create a class-constuctor to initialize the static variable you have created. Write the logic to fill the static variable in the class constructor.

Regards,

Ravi

0 Kudos
725

Hi Shahul,

Java sessions are different from SAP sessions.

In java you can interact between sessions but here concept is different.

You cant' access data between sessions. Here diffrent work process created for each session. so, when ever you execute program with in the program only dat is accessble.not outside the program.

But still I have doubt r u trying to access data betwen 2 sap sessions?

Thanks & Regards,

Siri.

0 Kudos
725

Hi Shahul,

It will generate only in runtime. The values cannot be maintained in sessions.

until unless u store it, using xport to memory

regards

vijay

0 Kudos
725

Hi Siri,

I agree with your point about work processes.

Wat I try to achieve is,

If user1 has used that class , the static variable wud be initialized. When user2 trying to use the class, i want to avoid that initialization again. Its not only between 2 sap sessions.. Its across different user sessions.

I jst want to know the feasibilty of achieving this!

Regards

Shahul

0 Kudos
725

Hi shahul,

As I said earlier data is availble only at runtime.

Once the program execution is over you can't access that data.

In your case you can export to memory when user1 is executed and when user2 executed you can import the value and use. I feel that is only wany you can do it.

see the syntax for it.

To export

EXPORT V_STATUS TO DATABASE INDX(ST) ID 'CONS'.

To import

IMPORT V_STATUS FROM DATABASE INDX(ST) ID 'CONS'.

Here you can give your ID.

Hope this will help you.

Thanks & Regrds,

Siri.

0 Kudos
725

Hi,

I think it is not possible to access a variable across different session. Only possibility is via Memory IDs. Can you tell me what exactly you r going to achieve with this(other that what you have explained previously)

Rajavardhana Reddy

0 Kudos
725

Hello shahul,

The only way in which data can be accessed across SAP sessions (belonging to various users) is to place the internal table in the buffer. You can do that by using the statements EXPORT TO SHARED BUFFER and IMPORT FROM SHARED BUFFER.

The F1 Documentation also has an example.

Regards,

Anand Mandalika.

0 Kudos
725

Hi,

I have a further question to that topic.

I thought of the relevance of static methods in ABAP. We learned before that static methods/attributes are not valid over work process boundaries. Imagine a class with static methods/attributes. Is it true that this class and the methods/attributes are only valid in one user-dialog or are they relevant for the whole work process? You know several user-dialogs running within one work process (for example)?! My opinion is that it is like that - but need clarification. Short answer is sufficient.

Do you have experience?

Thank you and best regards,

Daniel

0 Kudos
725

Using a static class in a program, the attributes are only valid for that program, not across programs in the same process. The static class is just that you don't need to create an instance of the class to use it.

Using a static class in your programs, is comparable to using a function group/module.

Regards,

Rich Heilman

Former Member
0 Kudos
725

Hi shahul,

Try to implement this in one of the methods in se24.I dont think that a static variable could be used across multiple sessions once u kill the session unless u store it some where.

Hope u will find it useful.

method INCREMENT .

DATA: IM_KEY TYPE LIFNR.

DATA: V_VALUE TYPE CHAR5.

DATA: ZINDEX TYPE ZINDEX.

IM_KEY = 'YSSN_NUM'.

IMPORT NUM TO V_VALUE

FROM database indx(AL) id IM_KEY TO ZINDEX.

CLEAR ZINDEX.

V_VALUE = V_VALUE + 10.

var_st = v_value.

export NUM from V_VALUE

to database ZindEx(AL) id IM_KEY FROM ZINDEX.

endmethod.

Thanks,

Vamsi.

Former Member
0 Kudos
725

Hi,

Try to send the variable to ABAP memory and then u can solve your problem.

Regards,

Azaz Ali Shaik.

christian_wohlfahrt
Active Contributor
0 Kudos
725

Hi Shahul!

Beside Anand Mandalika's solution with shared buffer there is one other option: context (SE33). It is somehow like DB table buffering, but you can buffer results of modules (so calculated or aggregated values).

Used in your global class, coding would look like a new generation each time, but in fact second and following access should be faster because of buffering.

Regards,

Christian

0 Kudos
725

SAPs approach to this task are Persistent Classes.

Look at http://help.sap.com/saphelp_erp2005/helpdata/en/06/f23c33638d11d4966d00a0c94260a5/frameset.htm

to get the concept of Persistent Attributes.

I analyzed that at least a year ago. As far as I remember they put the static attribute values to database and retrieve them on CONSTRUCTOR event.

When creating the class, select Persistent class as the class type. ABAP will do the rest.

Hope this really helps,

Clemens

0 Kudos
725

Hi,

thank you for your reply. The persistent classes are very well for getting/setting data during runtime. The problem is that I thought of some kind of at least workprocess wide singleton. I apologize I did not write that clearly.

As far as I know the persistent classes cannot handle references?! In other words a workprocess-wide singleton is not possible by using persistent classes.

What do you mean: is there another possibility?

Thank you and best regards,

Daniel

0 Kudos
725

Hmm.

The only thing that get's into my mind ist a dictionary table defined as fully buffered. That means the values read once remain in memory. But this may cause trouble as well if your processes are running on distributed servers - I don't know too much about server synchronization but I know there may be delays.

But I still do not fully understand your task. First we were talking about static variables. OK you may define a static variable as an object reference. But this reference will exist only in one LUW. Thus it is technically impossible to share this memory among sessions.

I think a possible way may be to look at SAP's enqueue/dequeue handling. AFAIK this is done by 'memory table' but I'm not sure about that. At least it does something that you want in a (I hope so) very efficient way.

Sorry, no more ideas for today.

regards,

C.