cancel
Showing results for 
Search instead for 
Did you mean: 

how to handle stateful session in Gateway

0 Kudos

Hello,

i am quite new to SAP UI5 and SAP Gateway. I had a problem in figuring out the below problem.

I have a web application developed in SAP UI5 and connected to ERP via SAP Gateway. I wanted to mantained stateful session for my application like in BSP application we can tick a checkbox "stateful"  and the framework will handle the stateful sessions. Is there similiar thing which can be implemented in SAP UI5 through Gateway.

Regards

Trinoy Hazarika

Accepted Solutions (0)

Answers (1)

Answers (1)

Vlad
Advisor
Advisor
0 Kudos

Hello Trinoy,

NetWeaver Gateway should be used as your data model or data storage. In other words, it must have some entity where you will store data permanently. Actually, for your "checkbox" I would recommend other techniques like:

- use offline storage (HTML5)

- store user settings in cookies

- or use the web server to store them (e.g. in a database).

However, you can implement the same approach with OData webservice. E.g. you can create an entity like user preferences and do all updates. But you must remember that usually webservices can be used by the application to get a collection of items, do some filtering and pagination stuff, and there is a chance that your settings can be accessed by someone.

In other words, you take all the responsibility to prevent user's settings from non-authorized reading.

Kind regards,

Vlad

0 Kudos

Hi VLad,

Would you please elaborate on how the user preference as a entity will help.

Let` s say i have a simple scenario.

1. i have a function module which has a global variable g_value and i have a UI5 application page
    where in there is a button clicking which will increment the global value by 1 and have a label
    which update me the updated value. So lets say i click twice i should get 2 in a stateful scenario.

2. Can this scenario be achieved by user user preferences.

Regards

Trinoy Hazarika

Vlad
Advisor
Advisor
0 Kudos

To understand your scenario better, I have to ask you. So, let us assume, that you have the global variable:

var i = 123;

Do you want to increase this variable, within the single page, or you want to persist it in the database. If you choose the first option, you do not need gateway. However, when you close the window, you will lose all changes.

If you prefer to save this value in the database, you have to create a table in ABAP Dictionary and write a simple code to read/write records from/to it. Finally, you have to create a model like:

Property Entity:

  • Name
  • Value
  • User

Using URLs like: http:...../Property(User=...., Name=....) you will be able to get these values from the ABAP dictionary.

0 Kudos

Hi Vlad,

Lets say i have defined the variable not in the FM but in its TOP include(so it is global).

Now in FM , i have a code like  i = i + 1.

Now from the UI, i am doing 2 subsequent call to the Server(which has the FM). So ideally i should get the return value as 2 as it will treat the 2 calls in the same session if the call are stateful. if stateless i will get the value returned as 1.

i want to know how gateway service will call. Let say i make 2 subsequent call to server. How do i get the value returned as 2 in my UI as not as 1.

Regards

Trinoy

Vlad
Advisor
Advisor
0 Kudos

I think, two subsequent calls of function module are independent. For example, if you have one ABAP method, which calls the same function module twice, what will you have?  The same approach works with URL requests - you must store this value somewhere on the server, which will live "forever" (even if you restart NetWeaver). That is why I suggest you to use the DB table.

0 Kudos

Hi Vlad,

Yes , we can use DB tables on server side. But if you see the BSP application , there we can mantained a stateful flag in the properties and then it open and maintains a session in the backend.

Then even if you can a FM twice from the consumer(BSP web page) the function group buffers are intact and the global values are acesssible for the second call. Actually this is done by the BSP framework.

So i thought whether such a possibility was there in UI5/Gateway route but it seems we need to handle sessions ourself in this case.

Thanks a lot for the response.

Regards

Trinoy Hazarika

Vlad
Advisor
Advisor
0 Kudos

BSP pages are hosted on the webserver, which maintains the session. If you host the page on your own server (e.g. Apache, Tomcat, IIS), this server is responsible for session storage.  Gateway is just the OData service provider, and it follows REST consept (which means - Stateless).  Probably, you are looking for the solution using a wrong tool 🙂