Application Development and Automation 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: 
Read only

Cache Class

Former Member
0 Likes
1,073

Hi Guys,

I want to implement a cache class to be used for BSP pages.

I want to cache a table and enhance and sort it in memory for fast access .

In Java i would use a static class. But that doesn't exist in ABAP so I'm looking for an alternative.

When called the first time it should fetch the data and order it.

When called later it should fetch the data from an internal table in the class without database access.

Every time i try the class is empty when i call it the second time.

Anyone knows how to solve this ?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
828

I want to implement a cache class to be used for BSP pages.

Though I'm pretty sure that you looked at it and found it not applicable I'd first look at the [caching BSPs|http://help.sap.com/saphelp_NW04/helpdata/en/d7/446f3b19d99b0de10000000a11405a/frameset.htm] ([ICM server cache|http://help.sap.com/saphelp_NW04/helpdata/en/72/c2153aab4a0c0ee10000000a114084/frameset.htm]).

Every time i try the class is empty when i call it the second time.

If you look at the [ABAP memory organization|http://help.sap.com/abapdocu_70/en/ABENORGANIZATION_OF_MODULES.htm] this will become clear:

<ul style="list-style:circle!important">

<li>Each user who is logging into SAP gets his own user session (stores for example the parameter ID's).</li>

<li>A main session (external mode) is opened for each user session (in case of SAPgui usage this corresponds to one window).</li>

<li>Calls of ABAP programs (e.g. report or transaction) create a new internal session which holds the changeable program data (this is also where your static classes are).</li>

</ul>

In your case I suspect you most likely deal with different main sessions and on top of that even with different user sessions...

Now if you want to share data across main sessions I'd not start with shared objects. As the name implies, they are objects and they offer quite a bit of functionality (but also more complexity and implementation effort). Note that shared objects offer no automatic displacement, but they offer the great benefit that they are accessed by reference (so no copying overhead).

For sake of simplicity I'd start looking at ABAP statement [EXPORT .. TO SHARED BUFFER|http://help.sap.com/abapdocu_70/en/ABAPEXPORT_DATA_CLUSTER_MEDIUM.htm#!ABAP_ALTERNATIVE_6@6@] (along with the corresponding [IMPORT|http://help.sap.com/abapdocu_70/en/ABAPIMPORT_MEDIUM.htm#!ABAP_ALTERNATIVE_6@6@]). Trivial to use and qualifies as a cache due to automatic displacement (if you don't want that you could also consider [EXPORT .. TO SHARED MEMORY|http://help.sap.com/abapdocu_70/en/ABAPEXPORT_DATA_CLUSTER_MEDIUM.htm#!ABAP_ALTERNATIVE_5@5@]). Disadvantage of the EXPORT/IMPORT is that any data has to be copied into the user session. So if your table is huge, shared objects would save you some memory space, but this comes with some implementation overhead...

Cheers, harald

4 REPLIES 4
Read only

GrahamRobbo
SAP Mentor
SAP Mentor
0 Likes
828

You are describing what is known in ABAP as a "Shared Object".

Start with the [Online Documentation|http://help.sap.com/saphelp_nw2004s/helpdata/en/14/dafc3e9d3b6927e10000000a114084/frameset.htm]

There are also several blogs and wiki entries that cover shared objects as well.

Cheers

Graham Robbo

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
828

Create a public static attribute in the class.

Regards,.

Rich Heilman

Read only

Former Member
0 Likes
829

I want to implement a cache class to be used for BSP pages.

Though I'm pretty sure that you looked at it and found it not applicable I'd first look at the [caching BSPs|http://help.sap.com/saphelp_NW04/helpdata/en/d7/446f3b19d99b0de10000000a11405a/frameset.htm] ([ICM server cache|http://help.sap.com/saphelp_NW04/helpdata/en/72/c2153aab4a0c0ee10000000a114084/frameset.htm]).

Every time i try the class is empty when i call it the second time.

If you look at the [ABAP memory organization|http://help.sap.com/abapdocu_70/en/ABENORGANIZATION_OF_MODULES.htm] this will become clear:

<ul style="list-style:circle!important">

<li>Each user who is logging into SAP gets his own user session (stores for example the parameter ID's).</li>

<li>A main session (external mode) is opened for each user session (in case of SAPgui usage this corresponds to one window).</li>

<li>Calls of ABAP programs (e.g. report or transaction) create a new internal session which holds the changeable program data (this is also where your static classes are).</li>

</ul>

In your case I suspect you most likely deal with different main sessions and on top of that even with different user sessions...

Now if you want to share data across main sessions I'd not start with shared objects. As the name implies, they are objects and they offer quite a bit of functionality (but also more complexity and implementation effort). Note that shared objects offer no automatic displacement, but they offer the great benefit that they are accessed by reference (so no copying overhead).

For sake of simplicity I'd start looking at ABAP statement [EXPORT .. TO SHARED BUFFER|http://help.sap.com/abapdocu_70/en/ABAPEXPORT_DATA_CLUSTER_MEDIUM.htm#!ABAP_ALTERNATIVE_6@6@] (along with the corresponding [IMPORT|http://help.sap.com/abapdocu_70/en/ABAPIMPORT_MEDIUM.htm#!ABAP_ALTERNATIVE_6@6@]). Trivial to use and qualifies as a cache due to automatic displacement (if you don't want that you could also consider [EXPORT .. TO SHARED MEMORY|http://help.sap.com/abapdocu_70/en/ABAPEXPORT_DATA_CLUSTER_MEDIUM.htm#!ABAP_ALTERNATIVE_5@5@]). Disadvantage of the EXPORT/IMPORT is that any data has to be copied into the user session. So if your table is huge, shared objects would save you some memory space, but this comes with some implementation overhead...

Cheers, harald

Read only

0 Likes
828

Hi Harald,

I took a look at the EXPORT .. TO SHARED BUFFER.

That seemed to do the trick.

But in my static method i have 2 import my object again each time.

But it takes a lot qiucker that to recaculate them.

So thanks.