cancel
Showing results for 
Search instead for 
Did you mean: 

Delta Query

CRVMANISH
Contributor
0 Kudos

Hello Experst,

How to develop delta query in SAP Gateway, we want to bring last changed data.

I am referring this URL http://help.sap.com/saphelp_nw74/helpdata/en/19/a426519eff236ee10000000a445394/content.htm

but i don't know where to use this code and how my oData query stream will look like.

Please Suggest

Regards

Manish

http://help.sap.com/saphelp_gateway20sp06/helpdata/en/2e/d7d9ee0f0f4c3292a555ec1c2952b1/frameset.htm

Accepted Solutions (1)

Accepted Solutions (1)

kammaje_cis
Active Contributor
0 Kudos

Hi Manish,

These are my thoughts. I have not tried them before.

To support Delta token, first you need to issue delta token with your all query outputs. That is done by filling ES_RESPONSE_CONTEXT-deltatoken. Delta token can be date and time, and it is upto you to decide the format and content. Once you put in the above variable, it should be available to the client in the form of response headers.

When the client wants to query the Collection again and wants to use the delta functionality, then it has to use the last delta token and pass it as part of the URI. ($delta)

Example: ....../PincodeCollection?$deltatoken=20120101

Inside the DPC class, get_entityset method, you fetch the delta token value from the code given in your link. (example of handling a delta token link).

Then you use it to query your application data and pass only the ones which are changed after that date. Also remember to issue the delta token, so that client can use it next time.

Let us know what is your business case and how it went. Interested to know.

Thanks

Krishna


CRVMANISH
Contributor
0 Kudos

Excellent Krishan & Vlad,

Will try this out.

Business Case : We want to download complete data once , we cannot afford to download it every time when application loads, next time it should download only the changes and new data.

I will keep you posted about the results.

Regards

Manish

Vlad
Advisor
Advisor
0 Kudos

Hello Manish,

For the delta synchronization, you have to create something which knows how old your data is. For example, imagine you have a table with columns: Table, Record ID, Update Time. This table contains the history of all tables and records that are required for your business. Each time, you update/create/delete the record, you have to maintain a corresponding record in this table.

Each time, you make the GET request with the delta token, you check this table first, and then return updated records only. Well... actually, that is why SAP provides SMP

Kind regards,
Vlad

CRVMANISH
Contributor
0 Kudos

Hello Krishna & Vlad,

I am not able to find ET_SERVICE_MODEL_INFOS in the signature, how to use this.

data lo_delta_context type /IWBEP/IF_MGW_REQ_ENTITYSTDLTA
* first get the delta token
lo_delta_context =? io_tech_request_context.
lv_delta_token = lo_delta_context->get_deltatoken( ). "converts it automatically into a datetime   
loop at ET_SERVICE_MODEL_INFOS REFERENCE INTO lr_svc_mdl_info.
      TRY .
       
        if lr_svc_mdl_info->*-last_modified le lv_delta_token.
*         then add it to the return table
          delete ET_SERVICE_MODEL_INFOS index sy-tabix.
        endif.
*       catch as much as possible
      CATCH cx_root INTO lx_exception.
*       service does not exist anymore or is not compileable --> put it to the deleted entries
        lr_svc_mdl_info->*-deleted = abap_true.
      ENDTRY.
    endloop.

Regards

Manish

CRVMANISH
Contributor
0 Kudos

Hello Experts,

I have written code of issuing delta here is my URL

/sap/opu/odata/CRAVE/EQUIP_LIST_SRV_02/EQUIP_LIST?!deltatoken=20130927

I have created new records but still it does not show me last changes it shows me complete list.

Please Suggest

Regards

Manish

former_member184867
Active Contributor
0 Kudos

Hi Manish,

I have not implemented deltatoken. Form the experience I can suggest the following.

Gateway does not automatically filterout data based on the delta token. In the data provider the logic needs to be handled carefully. If you have created new records even after timestamp specified in the deltatoken(20130927) and you are not getting the expected result back, then this means the the filtering logic implemented in the DPC needs to be re checked. Please check if youare returning the currect result(the filtered resultset)  back via export parameter 'ER_ENTITYSET' of /IWBEP/IF_MGW_APPL_RUNTIME~GET_ENTITYSET() of your DPC ?

Please refer to the sample code mentioned in the documentation(SP6) provided.

This is a sample code and ET_SERVICE_MODEL_INFOS REFERENCE contains the list of all the records. Now you need to remove all the records from ET_SERVICE_MODEL_INFOS REFERENCE for which creation date/time is less than deltatoken(20130927). Once removed you will only have the result set which is created after the specified delta token.

loop at ET_SERVICE_MODEL_INFOS REFERENCE INTO lr_svc_mdl_info.

      TRY .

       

        if lr_svc_mdl_info->*-last_modified le lv_delta_token.

*         then add it to the return table

          delete ET_SERVICE_MODEL_INFOS index sy-tabix.

        endif.

*       catch as much as possible

      CATCH cx_root INTO lx_exception.

*       service does not exist anymore or is not compileable --> put it to the deleted entries

        lr_svc_mdl_info->*-deleted = abap_true.

      ENDTRY.

    endloop.

For Deltatoken implementation following things must be considered.

  1. The result set source data must have datetime imformation. Deltatoken value can be applied on them to filter out the correct result set.
  2. The developer explicitly needs to implement the logic for filtering resultset based on the deltatoken value.
  3. The developer should reissue the new delta token back

Hope this helps.

Regards,

Atanu  

CRVMANISH
Contributor
0 Kudos

Hello Atanu,

There is no export parameter ET_SERVICE_MODEL_INFOS in the signature.

From where can i delete the records and filter the result set.

Regards

Manish


former_member184867
Active Contributor
0 Kudos

Hi Manish,

You do not need 'ET_SERVICE_MODEL_INFOS'. This is just an example.As I mentioned, you should return the final result via ER_ENTITYSET' of /IWBEP/IF_MGW_APPL_RUNTIME~GET_ENTITYSET().

So ER_ENTITYSET is the export parameter to look for and fill it with relevant entries.

Regards,

Atanu

CRVMANISH
Contributor
0 Kudos

Hi Atanu,

Got it , will try this and let you know

Regards

Manish

CRVMANISH
Contributor
0 Kudos

Hello Atanu,

Thanks , It works like a charm!!!......

Regards

Manish

Answers (1)

Answers (1)

Vlad
Advisor
Advisor
0 Kudos

Hello Manish,  The parameter ES_RESPONSE_CONTEXT is available in the GET_ENTITYSET. Exactly this parameter you should change to supply a delta token.  Kind regards, Vlad