Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
bradp
Active Participant

After finally upgrading Gateway to SP07, I decided to look into the new Delta Query Support functionality. I found a really great document written by andre.fischer, How to Implement Basic Delta Query Support in SAP Netweaver Gateway, which gave me all the direction I needed. I recommend reading it to get a better understanding of Delta Query Support and the different techniques.

As I am currently working on incorporating offline OData support using the new OData SDK’s included in the SMP 3.0 SDK, I needed to add in Delta Query Support to my Gateway Service. However, in my case the service I am consuming is a standard service, namely WFSERVICE (Workflow Service).

The technique and code I applied to get this working with WFSERVICE can be applied to any service.

Follow the following steps to redefine and add Delta Query Support:

Step 1

Create a new Gateway Project in transaction SEGW

Step 2

Right click on the Data Model under your new project and go to Redefine->OData Service GW



Step 3


Select the service you would like to redefine and click Next



Step 4

Select the entities and associations you would like to redefine. Although in this case I am only going to add the Delta Query Support to the WorkflowTaskCollection entity set which uses the WorkflowTask entity, it seems to error when I don't include all the associated entities.

Step 5

Generate Runtime by right clicking on the project and selecting Generate Runtime.

Give the Technical Service a new name

Step 6

Now we need to redefine the GET_ENTITYSET and GET_ENTITYSET_DELTA methods for the Entity Collection.

Start by right clicking the GetEntitySet of the Service Implementation for WorkflowTaskCollection and click on Go to ABAP Workbench

In the ABAP Workbench, we need to redefine both GET_ENTITYSET and GET_ENTITYSET_DELTA methods.

Once both methods have been redefined, go into their Redefinitions and paste the following code:


METHOD /iwbep/if_mgw_appl_srv_runtime~get_entityset.
DATA: lo_dp_facade   TYPE REF TO /iwbep/if_mgw_dp_facade.

DATA: lv_delta_token TYPE        string.

FIELD-SYMBOLS:
      <fs_entityset>
TYPE ANY TABLE.

TRY.
     
CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~get_entityset
          
EXPORTING
                iv_entity_name          
= iv_entity_name
                iv_entity_set_name      
= iv_entity_set_name
                iv_source_name          
= iv_source_name
                it_filter_select_options
= it_filter_select_options
                it_order                
= it_order
                is_paging               
= is_paging
                it_navigation_path      
= it_navigation_path
                it_key_tab              
= it_key_tab
                iv_filter_string        
= iv_filter_string
                iv_search_string        
= iv_search_string
                io_tech_request_context 
= io_tech_request_context
          
IMPORTING
                er_entityset            
= er_entityset
                es_response_context     
= es_response_context.


* get the data provider facade
     
TRY.
           lo_dp_facade
= /iwbep/if_mgw_conv_srv_runtime~get_dp_facade( ).
     
CATCH /iwbep/cx_mgw_tech_exception.
          
RAISE EXCEPTION TYPE /iwbep/cx_mgw_tech_exception.
     
ENDTRY.


ASSIGN er_entityset->* TO <fs_entityset>.

* call the delta token functionality
     
TRY.
          
CALL METHOD /iwbep/cl_query_result_log=>create_update_log_entry_hash
               
EXPORTING
                     io_tech_request_context 
= io_tech_request_context
                     io_dp_facade            
= lo_dp_facade
                     ir_service_document_name
= mr_service_document_name
                     ir_service_version      
= mr_service_version
                     it_entityset            
= <fs_entityset>
               
CHANGING
                     ev_delta_token          
= lv_delta_token.

           es_response_context
-deltatoken = lv_delta_token.

     
CATCH /iwbep/cx_qrl_locked.
          
RAISE EXCEPTION TYPE /iwbep/cx_qrl_locked.
     
CATCH /iwbep/cx_qrl_delta_unavailabl.
          
RAISE EXCEPTION TYPE /iwbep/cx_qrl_delta_unavailabl.
     
ENDTRY.

     
CATCH /iwbep/cx_mgw_busi_exception .
     
CATCH /iwbep/cx_mgw_tech_exception .
ENDTRY.


ENDMETHOD.




and....

METHOD /iwbep/if_mgw_appl_srv_runtime~get_entityset_delta.
DATA: lo_dp_facade           TYPE REF TO /iwbep/if_mgw_dp_facade.

DATA: lv_delta_token         TYPE        string.

FIELD-SYMBOLS:
      <fs_entityset>         TYPE ANY TABLE,
      <fs_deleted_entityset>
TYPE ANY TABLE.

TRY.
     
CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~get_entityset_delta
          
EXPORTING
                io_tech_request_context
= io_tech_request_context
          
IMPORTING
                er_entityset           
= er_entityset
                er_deleted_entityset   
= er_deleted_entityset
                es_response_context    
= es_response_context.

     
ASSIGN er_entityset->* TO <fs_entityset>.

     
IF er_deleted_entityset IS NOT BOUND.
          
CREATE DATA er_deleted_entityset LIKE <fs_entityset>.
     
ENDIF.

     
ASSIGN er_deleted_entityset->* TO <fs_deleted_entityset>.


* get the data provider facade
     
TRY.
           lo_dp_facade
= /iwbep/if_mgw_conv_srv_runtime~get_dp_facade( ).
     
CATCH /iwbep/cx_mgw_tech_exception.
          
RAISE EXCEPTION TYPE /iwbep/cx_mgw_tech_exception.
     
ENDTRY.

*  call the delta token functionality
     
TRY.
          
CALL METHOD /iwbep/cl_query_result_log=>create_update_log_entry_hash
               
EXPORTING
                     io_tech_request_context 
= io_tech_request_context
                     io_dp_facade            
= lo_dp_facade
                     ir_service_document_name
= mr_service_document_name
                     ir_service_version      
= mr_service_version
                     it_entityset            
= <fs_entityset>
               
IMPORTING
                     et_deleted_entityset    
= <fs_deleted_entityset>
                     et_entityset            
= <fs_entityset>
               
CHANGING
                     ev_delta_token          
= lv_delta_token.


           es_response_context
-deltatoken = lv_delta_token.

     
CATCH /iwbep/cx_qrl_locked.
          
RAISE EXCEPTION TYPE /iwbep/cx_qrl_locked.
            CATCH /iwbep/cx_qrl_delta_unavailabl.
          
RAISE EXCEPTION TYPE /iwbep/cx_qrl_delta_unavailabl.
     
ENDTRY.

CATCH /iwbep/cx_mgw_busi_exception .
CATCH /iwbep/cx_mgw_tech_exception .
ENDTRY.

ENDMETHOD
.



Step 7

Add the new service in transaction /IWFND/MAINT_SERVICE

Click on ZWFSERVICE to add it

Step 8

Run the service in a browser via its URL: http://my.domain.com:8200/sap/opu/odata/sap/ZWFSERVICE/WorkflowTaskCollection

The difference you will notice is that there is the following additional tag at the second last line of the response:

<link rel="delta" href="WorkflowTaskCollection?!deltatoken='22000AB22B051EE397AFF3B8EE42B356_20131205073405'"/>

Now on subsequent calls you will use the new delta token retrieved from the latest response to make sure that only new/updated and deleted entries are returned like follows: http://my.domain.com:8200/sap/opu/odata/sap/ZWFSERVICE/WorkflowTaskCollection?!deltatoken='22000AB22...

In the case where an entry has been deleted since the last service call and in the case of Workflow, when a work item has been approved and is no longer in the approvers worklist, the following will appear in the response:

<at:deleted-entry ref="http://my.domain.com:8200/sap/opu/odata/sap/ZWFSERVICE/WorkflowTaskCollection('000001224760')" when="2013-12-05T07:33:41Z"/>



And that is all you need to do from the backend side, the rest would be handled on the client side.

5 Comments
Labels in this area