Skip to Content
Technical Articles

How to use Soft-State support for OData services


  • 17.03.2015 added information that security session management has to be activated
  • 11.10.2019 changed layout after the automatic conversion so that screen shots are again visible



The so-called “soft state” mode enables the SAP NetWeaver Gateway runtime to process several requests in one ABAP application server session, similar to stateful behavior. The only difference is the behavior of the application server after the session times out: Instead of breaking the request processing with a time-out exception the server creates a new session and processes the request as usual. For the consumer the change of the application server sessions is transparent and no data is lost on the client session.

The session that is held by the ICF framework results in session held in the backend system via RFC where the data provider class can cache data in member variables. The Data Provider Cache is highlighted in green in the following figure.

HTTP Stack - Soft State.jpg


The soft state mode should be used for applications built on legacy functionality in the backend, especially when the functionality includes initial loading/caching of big amounts of data for a single request. A typical example would be a price calculation.


By using soft state, the resources/functionality which has been loaded during the initial load can be reused for the subsequent requests of the service. Thus, the main benefit of soft state is a considerable performance optimization of an OData service.





You have created a sample OData service using the Service Builder as described in my SCN document How to Develop a Gateway Service using Code based Implementation .



In order to use soft state it is mandatory that HTTP Security Session Management on AS ABAP has been activated. Security session management can be managed using transaction SICF_SESSIONS as described in the SAP Online Help:


Activating HTTP Security Session Management on AS ABAP – User Authentication and Single Sign-On – SAP Library


Even if secúrity session management is not being activated a service currently is shown as active for soft state but does not work as supposed.



Overview – Implementation steps to activate Softstate for your service


  1. Redefine the DEFINE method of the model provider extension call
  2. Create an instance attribute MV_IS_SOFTSTATE for the DPC_EXT class that stores  the status whether soft state is activated
  3. Redefine the method /IWBEP/IF_MGW_SOST_SRV_RUNTIME~OPERATION_START to set this variable



Implementation steps in the model provider class

Steps Result
1. Start maintaining the model provider extension class ZCL_ZGW_PRODUCT_MPC_EXT
2. Redefine the DEFINE method of the MPC_EXT class method DEFINE.
  super->define( ).
  model->set_soft_state_enabled( abap_true ).


Implementation steps in the data provider class

Start maintaining the data provider class ZCL_ZGW_PRODUCT_DPC_EXT
Click on the Attributes tab and insert a new attribute with the following Settings


Instance Attribute



Associated Type

TRUE if we are running in softstate mode

 DPC Maint.JPG

Click on the Methods tab and redefine the method /IWBEP/IF_MGW_SOST_SRV_RUNTIME~OPERATION_START

and enter the following line of code


mv_is_softstate = abap_true.

  mv_is_softstate = abap_true.

Now click on the Methods tab and redefine the method /IWBEP/IF_MGW_SOST_SRV_RUNTIME~OPERATION_END

without entering any code.


Please note:
Without activating both methods you would get an exception

Now define a second (static) attribute GV_COUNT of type I to demo the use of soft state


Click on the Attributes tab and insert a new attribute with the following settings:


Static Attribute



Associated Type

Store counter

Activate your changes

Navigate back to the Service Builder and expand the folder Service Maintenance.

Expand the folder Maintain.

Right click on the entry of your Gateway Hub system  to start the transaction /IWFND/MAINT_SERVICE with filtered for your service name

Confirm the warning of being redirected to the Hub system

You will notice that the service ZGW_PRODUCT_SRV is shown as not supporting Soft-State.

If you click on the Soft-State button (1) you will get an error message

Confirm the error message.
Click on Load Metadata and confirm the sucess message

The service is now shown such  that it supports soft state but soft state is not yet activated.


If the service is not shown as inactive try to clear the metadata cache in the Gateway Hub as well as in the Gatebay backend system. To do so:

  1. Start transaction /IWBEP/CACHE_CLEANUP in the backend and activate the check box Cleanup Cache for all Models.
  2. Start transcation /iwfnd/cache_cleanup on the hub and run it with the check box Cleanup Cache for all Models.
Change the session time out
On the lower left part on the screen click on ICF Node –> Configure (SICF)
Double Click on the entry of your service in the SICF tree

From the menu choose Service –> Change (1) and enter a Session Timeout greater than zero, for example 10 seconds.

Save your changes (2) and navigate back to the Service

Since the service should now shows up with the Softstate-Status Inactive you can now activate the softstate status by pressing the softstate button.
Confirm the warning before activating soft state for your service and confirm the information that softstate has now been activated.
 warning softstate activation.png
Use of softstate in the data provider extension class

Change the implementation of the method  PRODUCTSET_GET_ENTITYSET to enable a custom counter when $count is called for the entity set ProductSet with the coding shown on the right.

The coding first checks whether /$count is requested and has implemented a custom implementation to retrieve $count.

If soft state is not enabled the number of products will be retrieved by counting the table entries in SNWD_PD.

If soft state is enabled the code checks whether the member variable GV_COUNT is inital.

If it is initial that means if the /$count is called for the first time in this session we have to retrieve the number of entries from the database.

Only if /$count is called a second time when soft state is enabled no data will be read from the database and /$count will rather be filled with the value stored in the variable GV_COUNT which is then incremented by 1 to show you that soft state is actually working.

If the time configured as a session timeout is exceeded counting starts again from the number of products which is equal to the number of table entries in table SNWD_PD.

Activate your changes.



Test the service in the browser



Call your service via the browser.
When refreshing the URL you will notice that the counter will start to count the number of calls.
Wait for 20 seconds …

When you wait for a period longer than the one configured as a session timeout in SICF the counter starts with 1 again.

Please note:
If you have configured a small time window (for example 10 seconds) you will probably have to wait longer since there is an additional latency.
If you are too impatient and click on refresh to fast the wait time starts again from zero.


Comparison of response times

The behaviour when using soft state or not can nicely be checked using the performance trace. This can be started using transaction /IWFND/TRACES.



Start a performance trace using /IWFND/TRACES.

Perform several requests with $count having soft state enabled

We can see that the initial request takes 16 milliseconds in the backend (GW framework overhead + Application Data Provider response time).

For every subsequent request  the Application Data Provider Response time is zero and the GW framework overhead is reduced to 5 mill seconds.

 Count with softstate.JPG
Deactivate soft state and perform again several requests with $count

The result now is that subsequent requests have the same response time.

The response time is the same that we got for the first initial request when soft state was enabled.

Count without softstate.JPG


You must be Logged on to comment or reply to a post.
  • Hi Andre, many thanks for the detailed explanation.

    Nevertheless i have two questions:

    1. Why do you added the variable MV_IS_SOFTSTATE? For the example it is not really necessary or am i wrong?
    2. The static attribute variable is different for every session (and every instance of the dpc class)?

    Best Regards, Frank

    • Hi Frank,

      Thanks for pointing this out.

      I have thus changed the coding to really make use of my variable MV_IS_SOFTSTATE. 😉

      I have changed the coding and used the variable MV_IS_SOFTSTATE to check whether soft state is enabled or not. If it is not enabled the /$count is retrieved from the database whereas the implementation checks whether this value has already been retrieved from the backend when soft state is enabled.

      When soft state is enabled the implementation only reads the number of products from the database in the first request.

      You are right, the static attribute variable is different in every session.that means if I call the service a second time having waited longer than the time span configured as the session time out in the ICF node.

  • Hi

    Thanks for the detailed explanation. I have an issue where the soft state is shown as Active, but when i debug I see that the variable mv_is_softstate is not set. What am I missing here? I redefined the methods you suggested and did all other steps in the same way.

  • Hi Andre,

    Thanks for the detailed explanation.

    I have the following question : if we want to retrieve for instance list of countries , do we have to create a static instance for that ?

    can we usethe soft state if we qeuery for the detail of an entity (for instance detail of a product with key fields ).


    • Hi Moo,

      the example of a list of countries is not the one where I would see soft state. This list should not be so expensive to retrieve so using soft state for this would not be appropriate.

      An example where soft state would be beneficial would for example be a list of products with prices where the price is expensive to calculate.

      If you want to store this you would not use an instance attribute but rather an Static Attribute because otherwise the content would be lost.

      If you just want to cache the content of a list the Softstate based query result cache might be something you want to look at. For example if you are looking for read only access. This is technically based on the soft state as well and allows to cache the result of a query in the Gateway Hub rather than in the Gateway backend.

      The details of a product are a perfect example to be stored in a static attribute of your data provider extension class if it is very expensive to retrieve those details. Example for this might be the availability or the price.

      Best Regards,


      • Hi Andre,

        Thanks for an excellent blog on how to achieve stateful behaviour for GW service but I have some doubts

        I created a service with session time out in SICF set as 30 secs and enabled softstate for the service as well as in MPC define method.

        But when i fire multiple request from GW client in a span of 5 secs also, the static attribute  variable GV_COUNT is initial .It always return the count from the DB.

        I also dont understand the need of MV_IS_SOFTSTATE which will always be true irrepective of whatever services you call inside that project . That leads me to the next question of how can we enable softstate for a particular entity types(inside a projects) query operation



  • Hello Andre,

    Thanks for your excellent blog. I have a question to soft state respectively to session handling. When the user closes their browser, how can you intercept the relationship as setting the timeout to zero? Is that anyway possible?

    Best Regards,


    • Hi Claudia,

      good to hear that you like the document. You can rate it as well 😉 .

      It is not clear to me what you are looking for exactly.

      Are you looking for an option to have access to the session after a user has closed the browser?

      Or are you looking for information how the session is closed after the user has closed the browser window?

      Best Regards,


        • Hello Claudia,

          I have the very same requirement. I was wondering if you found a way to achieve that?

          Look forward to hear from you.

          Best Regards,


        • Hello Claudia,

          You can try the following:

          1. You'll get your own JavaScript event on leaving the window, e.g. window.onbeforeunload or window.onunload.

          2. From there you'll trigger the request informing you want to close the session. E.g. /sap/opu/odata/sap/zmy_test/MyCounter/?close_session_now=X or any other means, e.g. including something into request header.

          3.  You can catch it via your own handler in SICF node or somehow in your OData DPC class. It's up to you and up to method you chose in p.2).

          4. Get the right session via: cl_server_info=> get_session_list.

          5. Kill the session via FM: TH_DELETE_USER having set all parameters: USER, CLIENT, LOGON_HDL and LOGON_ID.

          You can simulate it in transaction SM04.

          It should work, if not, let me know.

          BR, Dima

      • Hi Andre,

        Is there a way for us to capture the event (Session Ended) in the DPC class?

        I was wondering if that can be done then I can potentially persist the state of my transient data and then reload it whenever a new session is created..

        Maybe I did not understand the role of OPERATION-END api if that is intended to this.



        • Hi Vikas,

          the method /IWBEP/IF_MGW_SOST_SRV_RUNTIME~OPERATION_END is exactly the place where you can perform actions such as to persist the state of your transient data.

          You will not be able to catch the event session ended yourself in the DPC class because the session will be automatically terminated after the end of the session timeout is reached. At this time your user will not use the session anymore.

          Best Regards,


          • Hi Andre,

            Can you shed some lights here ?

            "Nice and helpful feature in SAP Gateway. Could you please give some more insights in using "Softstate based query result cache" ? What classes and interfaces are required to required to use this feature and in which DPC method should the implemenation be done. Thanks for the help."


            Prabaharan Asokan

          • Hi Andre,

            Soft state will only improve the performace  post completing the first request. But still first run will not have any performance impact when using soft state.

            Please suggest.


            Prabaharan Asokan

          • Hi Prabaharan,

            I am not sure whether I understood your question.

            Soft state is a feature that should not make the first request faster but any sub sequent requests.

            Think about an app that needs to determine a price for a product. Pricing is usually a very expensive calculation from a performance perspective.

            The first calculation of the price is not faster when using soft state.

            But if the app needs the price for the same product for a subsequent request your service implementation in the data provider class could take the price it has calculated a few seconds or minutes earlier that was cached in your DPC.

            The second call will then be faster.

            Best Regards,


  • hi Andre,

    i have the same issue as Vishwa.

    i still get no luck with softstate status "Not supported" after i redefined the methonds in

    MPC and DPC extention classes.

    Did i miss something right there?

  • Hi Andre,

    Nice and helpful feature in SAP Gateway. Could you please give some more insights in using "Softstate based query result cache" ? What classes and interfaces are required to required to use this feature and in which DPC method should the implemenation be done. Thanks for the help.


    Prabaharan Asokan

  • I create and configurate soft state but create back-end session every request. So I lost data. I did it Netweaver GW 7.01 but upgrade NW 740 I couldn't do it.

    For example:

    Sessions from SM04:

    R=2 P=/sap/opu/odata/sap/ZMOBILEDI_SRV/mobiledi_temp_recover


  • Hallo Andre Fischer,


    Zuerst einmal vielen Dank für deine How To´s. Die haben mir bei meiner bisherigen Bachelorarbeit echt weitergeholfen.

    Ich bin gerade dabei, dass serverseitige Cachen auszuprobieren um dies als Möglichkeit in meiner Arbeit zu erwähnen. Klar kann ich die Theorie dahinter aufschreiben, jedoch wollte ich es auch selber testen.

    Bisher bin ich deine Anleitung Schritt für Schritt durchgegangen, kommen jedoch zu dem Punkt, dass die Variable GV_COUNT bei jedem Aufruf initial ist. In der MPC_EXT habe ich die Define Methode redefiniert und das Model für das Softstate aktiviert. Auch die Variable GV_COUNT habe ich natürlich auf Statisch gesetzt, jedoch verhält sich das Mistding wie eine Instanzvariable ?

    Kann es vielleicht an der Sicherheitseinstellung des Service liegen?
    Die Einstellungen sind wie folgt:

    login/create_sso2_ticket = 2
    login/accept_sso2_ticket = 1
    login/ticketcache_entries_max = 1000
    login/ticketcache_off = 0
    login/ticket_only_by_https = 0
    icf/set_HTTPonly_flag_on_cookies = 3
    icf/user_recheck = 0
    http/security_session_timeout = 1800
    http/security_context_cache_size = 2500
    rdisp/plugin_auto_logout = 1800
    rdisp/autothtime = 60

    Gibt es hierbei noch irgendetwas zu beachten? Würde mich über eine Antwort sehr freuen ?

    PS: Das SAP Gatewaybuch ließt sich sehr gut ?

  • Hi Erich,

    I am glad you like my How Tos, the book and that both helped you with your bachelor thesis.

    For further questions I would like to ask them in the fourm.

    Have you checked whether the soft state is really active ? (transaction /IWFND/MAINT_SERVICE), is the session time out configured to be > 0 s. You can check SM05 whether your security session is reused or not).

    Best Regards,



  • Hi Andre,

    Thanks for the this very helpful post. I have a query here. Method OPERATION_START is not getting called and because of this variable mv_is_softstate is not set. Please help here.

    soft state is active and session time out configured is > 0 sec 

    SM05 entry :




    Best Regards,




  • Hey,

    I have implemented everything as you said. When I call the method get_entityset for the first time it gives me the number of records in the table but when i call it the second time it does not give me the call counts instead keeps incrementing the value of number of records.please help me solve this.



  • Hi Andre,

    Thank you for this great blog.

    I have implemented Soft state in my Odata service.

    I have an issue where the soft state is shown as Active, but the debugger does not stop on my external breakpoints in :


    Thank you


  • Hi Andre,

    Here is one more detail

    If I implement the service Directly in Gateway, the debugger works perfect.

    When I implement it in backend and publish it in Gateway, I get the issue mentioned above.

    Thank you


    • My service Soft-state enable in gateway hub.

      Set session time out greater than zero from T-code SICF.

      Implementation is in DPC_EXT

      Implementation is in MPC_EXT.

      • Simply because your table SNWD_PD is empty ! Why not using another table (not empty but small) for the test ?

        Be careful, you entered a time out of 10 MINUTES (instead of 10 seconds), do you really want to wait more than 10 minutes between each test ?

      • have you tested the scenario using the SAP Gateway client ?

        This should reuse the session unless you have to specify it in older releses.


          • In older Releases there is a check box you have to activate in order to reuse the http session to see the effect of soft state (here 740)


            In newer releases (latetest SP of 750) the button is gone and the session is reused automatically.



          • /
  • I know that this blog is from 2014 and we’re now in 2020 – but just dropping in to say a HUGE THANKS because I was able to implement the soft state functionality and apply locking to my project with the information provided here since we’re still on a much older ABAP release and do not have any of the new fancy functionality the newer releases has – but was able to get this basic soft state functionality to work! Thanks again!

    • You are welcome :-).

      Glad to hear that it works and though soft state has not been built to achieve locking I know that some customers are "misusing" it.

      You only have to be sure what you are doing (that means what happens if the soft state session is terminated, but the lock resides) and you have to be sure that your locking works fine.

      Having said that.

      Good luck and hope to see you back on a new release soon ;-).

      • Oh yes – ideally, if we were on any “newer” version like 751, would have most likely use BOPF with draft functionality… but… life’s not always ideal. LOL… and I'm certainly not trying to ignore the very fact that I could be "misusing" it. 🙂

        And yup, will certainly be testing to make sure that sessions are being released automatically as expected and db locks are being handled along with it. Thanks for the advice! We have considered other points before enabling soft state for this application such as it will be a low traffic but critical app - only about 5 users daily, making sure locks are on single record instead of locking entire table, and keeping session timeout to a minimum, etc...

        I too look forward to our move to newer or the latest release! Hopefully soon!