Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
kenichi_unnai
Advisor
Advisor

This is a part of H2G - "How To Implement Lightening Fast OData Services with Exchange Table".


Prerequisites


You should have done the following steps:


#1 - OData CRUD Crash Course - Create

#1 - OData CRUD Crash Course - Update

#1 - OData CRUD Crash Course - Delete


Step-by-Step Procedure


- Creating Exchange Table

1. Let's create an Exchange Table. Go to SE11 and create a database table.

2. Select the Delivery Class as "A" and Data Browser/Table View Maint. value as "Display/Maintenance Allowed".

3. Now we're going to define the Exchange Table structure. As shown in the capture, enter "MANDT" and include "/SYCLO/CORE_EXCHANGE_KEY_STR" with marking both in Key and Initial Values fields. And include "/SYCLO/CORE_EXCHANGE_SUB_STR" too.

4. Click on "Technical Settings" button.

5. Select "Data class" as APPL0 and "Size category" as 3 - the size is just an example. You can activate the Exchange Table now, it should be successfully activated without any error.

You have done the Exchange Table!


- Adding Enhancement Framework Implementation (EFI) in CUD logic

1. Let's add the EFI to capture the change during Create/Update/Delete operations and update the Exchange Table.


First thing is to enhance the existing Create operation logic. Go to the "..._CREATE_ENTITY" code via the transaction SEGW. You should already have the code as written here - in between the line #05 and #06, add this variable declaration:

...
05         lv_error_entity TYPE string,
06         lv_action       TYPE string VALUE 'C'.
...

The lv_action in #06 will be used in the EFI at the later step.


And in between the line #15 and #16, add a line of code to call an EFI program:

...
14 * entity inserted
15     er_entity = ls_entityset.
16 * trigger exchange table update
17     INCLUDE zefi_travelagency.
18   ELSE.
...

As you see above, the line #17 is newly inserted to call an EFI program - let's create it.


2. Double click on the "zefi_travelagency" in the ABAP editor. You'll create a new ABAP Object - we can open & edit it via SE38 later on.

3. Copy & Paste entire lines of code below. This is the one single EFI code to be called during the Create/Update/Delete operations.

01 DATA: lv_efi_objkey  TYPE /syclo/core_exch_objkey_dte,
02       lv_efi_action  TYPE /syclo/core_exch_action_dte,
03       lt_efi_data    TYPE /syclo/core_exch_chngdata_tab,
04       lref_exception TYPE REF TO cx_root,
05 * required for Soft State     
06       lv_syclo_active     TYPE /syclo/core_boolean_dte,                         
07       lv_syclo_efi_source TYPE string VALUE sy-repid.
08
09 CONSTANTS: lc_efi_incl_name TYPE /syclo/core_efi_incl_dte VALUE 'ZEFI_TRAVELAGENCY'.
10
11 TRY.
12 * required for Soft State
13     /syclo/cl_core_exch_serv=>logtrace_exch_begin( iv_efi_include = lc_efi_incl_name
14                                                    iv_source      = lv_syclo_efi_source ).
15     lv_syclo_active = /syclo/cl_core_exch_serv=>get_exchange_active( lc_efi_incl_name ).
16     IF lv_syclo_active = abap_true.
17
18       IF lv_action EQ 'C'.
19 * Create
20         lv_efi_action = /syclo/cl_core_constants=>exch_action_insert.
21       ELSEIF lv_action EQ 'U'.
22 * Update
23         lv_efi_action = /syclo/cl_core_constants=>exch_action_update.
24       ELSEIF lv_action EQ 'D'.
25 * Delete
26         lv_efi_action = /syclo/cl_core_constants=>exch_action_delete.
27       ENDIF.
28
29 * set the key value in the Exchange Table
30       lv_efi_objkey = ls_key_tab-value.
31
32 * update exchange table to keep track of CUD operation
33       /syclo/cl_core_exch_serv=>update_exchange( EXPORTING
34                                                  iv_objkey      = lv_efi_objkey
35                                                  iv_efi_include = lc_efi_incl_name
36                                                  iv_action      = lv_efi_action
37                                                  it_data        = lt_efi_data ).
38     ENDIF.                                    
39
40   CATCH cx_root INTO lref_exception.
41     /syclo/cl_core_appl_logger=>logger->catch_class_exception( EXPORTING iref_exception = lref_exception ).
42 ENDTRY.

Code explained -

#01 - #04: declares the variables for Exchange Table update method called in the #33.

#05 - #07: those two variables are for "Soft State" feature which will be used & explained in later H2G enhancement.

#09: Exchange Table update method in #33 requires the actual EFI name.

#12 - #16: those two methods call and IF block statement are required for "Soft State" feature which will be used & explained in later H2G enhancement. It doesn't do any harm in the current EFI code.

#18 - #20: sets the action type for a created entity - the value will be stored in the Exchange Table as delta tracking record.

#21 - #23: sets the action type for an updated entity.

#24 - #26: sets the action type for a deleted entity.

#30 sets the key value of the entity changed - the value will be stored in the Exchange Table as delta tracking record.

#33 - #37: the utility method which updates the Exchange Table.


Now you should be able to activate it successfully. We have done for Create operation, and next one is for Update & Delete.


4. Let's enhance the existing Update operation logic. Go to the "..._UPDATE_ENTITY" code via the transaction SEGW. You should already have the code as written here - in between the line #05 and #06, add this variable declaration:

...
05         lv_error_entity TYPE string,
06         lv_action       TYPE string VALUE 'U'.
...

And in between the line #20 and #21, add a line of code to call the EFI program:

...
19 * entity found and updated
20       er_entity = ls_entityset.
21 * trigger exchange table update
22     INCLUDE zefi_travelagency.
23   ELSE.
...

I believe you know what you're doing 🙂 Just the same with what we have done with Create operation enhancement. As CUD uses the same EFI, you don't add any EFI this time. Next one is - surely Delete operation.


5. Let's enhance the existing Delete operation logic. Go to the "..._DELETE_ENTITY" code via the transaction SEGW. You should already have the code as written here - in between the line #05 and #06, add this variable declaration:

...
05         lv_error_entity TYPE string,
06         lv_action       TYPE string VALUE 'D'.
...

And in between the line #13 and #14, add a line of code to call the EFI program:

...
13 * delete completed
14 * trigger exchange table update
15     INCLUDE zefi_travelagency.
16   ELSE.
...

Now you can activate them all - you have done the Delta Tracking implementation!


The last thing to do is - we need to glue together what we have created - via the Syclo Config Panel.


- Defining Exchange Object in the Config Panel

1. Run the SAP Transaction /SYCLO/CONFIGPANEL. It should open a new browser window displaying the Syclo Config Panel. Find and click the "ConfigPanel Home" link.

2. Find and click on the "Mobile Application Configuration" link.

3. Click on the Create button - we'll define a Mobile Application Configuration, which is an identifier of the configuration - we need to remember this name when we do the Delta Query later.

4. Enter the values. As explained in the previous step, we will need this value when we do the Delta Query. Be sure to enter the Description field too, it will be shown up in the pulldown in the next step. Save it.

5. Back to the "ConfigPanel Home" page. And find and click on the "Exchange Object Configuration" link.

6. Press Create - Now that you had created all the required elements, you are able to search and assign all those values in the capture. Be sure to tick in "Active Flag" too.

You're supposed to fill out following fields:

- Exchange Object - Another value required during Delta Query.

- Mobile Application

- Application Area

- Exchange Table name

- Exchange Lock Object - leave it empty (In this usage, it is ok for the last update to win in the situation, so the object key has the latest time stamp.)

- Exchange Hander - select "/SYCLO/CL_CORE_EX_HANDLER_BASE".


Save it.


7. Back to the "ConfigPanel Home" page. And find and click on the "EFI Assignment" link.

8. Press Create - in the General tab, you are able to search and assign the EFI name you had created.

9. Switch to the Assignment tab. Assign the values for Mobile Application, Exchange Object and Active Flag = "ON".

Save it - now you have done gluing all the important objects together, your Delta Tracking will work! Let's make sure if your Exchange Table is fully functional.


- Testing Exchange Table

1. Go to SE11 and open your Exchange Table in display mode.

2. You should see the Exchange Table structure - click on the contents icon.

3. Here you can browse and maintain the table contents. Click Execute - and you'll see the message "No table entries found for specified key" - yup the Exchange Table is currently empty.

4. Let's run any CUD operation:


- Run Create

- Run Update

- Run Delete


You might want to set External Breakpoints to see how the EFI is called during the CUD operation.

6. Now go back and check the Exchange Table contents. You'll see all the CUD operations are recorded with the key value, its action type and so on. This is the Delta Tracking record.

Congratulations, now your Delta Tracking is happily working! 


Tip: you can manually select each record and delete them in SE11. However in reality you might want to use the ABAP program /SYCLO/CORE_EXCH_PURGE_PROG in SE38 to clean up the Exchange Table contents. And you can configure the "Days To Keep History" value, which is set as 180 by default in Exchange Object config.


What's next? We'll implement super fast Delta Query, which takes advantage of the Exchange Table.



---

List of H2Gs


Blog - SMP3 OData SDK - Performance Tuning with Offline Store

2 Comments