Hi, I provide training in SAP UI5. Also feel free to checkout my new web page https://saptechblog.com
Webdynpro ABAP

Context change log


In many applications it is necessary to capture the changes made by the user in the screen. Imagine you have a number of UI elements in the screen and the user changes the value of only one field and click on some action. We may not exactly which UI element he has made the changes. We will read all contexts binded to the UI element and process the data. This may cause a negative impact on the performance as you process the huge amount of data even though the user has not done any actions on those data.

Imagine I have a table that displays the data in a editable mode and the user has the provision to update the data in the table and update it back on the database table on the click on submit button.




At this point of time we may not know which row he has exactly edited. We simply read all the records in the table and process it in the loop and also update the records which are not modified back in the database table.

Hence it is necessary to optimize the performance. Each context node has the provision to store the information about itself. We don’t have to process all the context nodes that are available in the controller; instead there is a Webdynpro framework which provides which particular context has been changed using change log function.

Within the controller all the information about the changes made to the context nodes of the controller is stored in a single internal table. At runtime we can access this table and based on the values in the table we can process the data.

It is like a recorder that records the user entries with relevant information’s.

Note: This only captures the changes made by the user in the screen. It does not capture the changes to context element made through programming.

Context Changes are recorded only for the original nodes in that controller and not for the mapped nodes.

In the case of OVS value helps and freely programmed value helps, the new value is not entered automatically into the table but must be entered actively using method ADD_CONTEXT_ATTRIBUTE_CHANGE of interface IF_WD_CONTEXT, provided an entry is desired.

By default the change log function in any controller will be disabled. We need to activate the change log function in order to use its functionality.

We activate it through the interface if_wd_context in any controller. This interface in contrast to if_wd_context_node not only refers to the root context but also to the context as the whole.

Methods of the interface if_wd_context and its uses:



The internal table that contains the user defined types is of type WDR_CONTEXT_CHANGE_LIST.

The component of internal table is as follows.



Example program given by SAP: DEMO_CONTEXT_CHANGES.

Now let us see an example on how to use the change log function.

Step 1: Create a table that displays the data in the editable mode.

Refer the below link for how to create a Table with input field.


Create a table as in the link that displays the flight detail as below.




Code in the method doinit:




Step 2: Create a context node with structure of the internal table WDR_CONTEXT_CHANGE_LIST that the change log function returns the output.



Enter the name for the node and provide the dictionary structure as the line type WDR_CONTEXT_CHANGE of the table type WDR_CONTEXT_CHANGE_LIST.



Click on add attribute from structure and choose all the fields and press enter.








Context node will be created as below.




Change the type of attribute as string for node, old_value and new_value.


Step 3: We will proceed from here. Go to the layout tab of the view controller and insert a button UI element.




Provide ID and Type for the UI element.



Change the Text property of the Button UI element and create an action for the button UI element.





Step 4: Insert a table UI element. Right click on the table and select create binding.






Choose the context node as changes and press enter.




Step 5: As I mentioned earlier the change log function by default will be deactivated in the controller. Let’s activate the change log function to capture the changes made by the user.

Go to the doinit method of the view controller and activate the change log.

We need the object reference to the interface if_wd_context to activate the change log. There is a method called get_context in the interface if_wd_context_node which returns the reference variable of type if_wd_context.

Using pattern call the method to get the interface of the context.




Coding will be generated as below.



Modify the code as below.



Using the object for context call the method enable change log of the interface to activate the change log function.




Coding will be generated as below.



Now we have activated the change log function.

Step 6: Now there is a method called get_change_log which will return the changes in the user entries in the form of the internal table specified. This method cannot be called inside a event handler method. Hence we will create a method and call this method inside it to get the change log.

Go to the methods tab of the view controller and create a method get_log.





Inside the method get the data reference for the context as we did before in the doinit method and call the method get_change_log of the interface to get the change log in the form of internal table.



Call the method get_change_log.





Coding will be generated as below.


Modify the code as below.



Now the change log has been captured in the internal table. Export this internal table contents so that these change log can be accessed inside an event handler method.


Code in the method GET_LOG:

data : lo_context type ref to if_wd_context.
call method wd_context->get_context
= lo_context.

call method lo_context->get_context_change_log
= it_changes.



Step 7: Go to the event handler method created for the button and get these changes and bind it on the context for the changes.




Get the changes in the event handler method as below.

Set the internal table content to the node changes.




Modify the generated code as below.

Code in the event handler method is as below.



data : it_changes type wdr_context_change_list.
= wd_this->get_log( ).

data lo_nd_changes type ref to if_wd_context_node.
data lt_changes type wd_this->elements_changes.
data ls_changes type wd_this->element_changes.
data : wa_changes like line of it_changes.

field-symbols : <fs_value> type any.
field-symbols : <fs_value_new> type any.

= wd_context->get_child_node( name = wd_this->wdctx_changes ).

loop at it_changes into wa_changes.
-node_name = wa_changes-node_name.
-sequence = wa_changes-sequence.
-node_path = wa_changes-node_path.
-change_kind = wa_changes-change_kind.
-element_index = wa_changes-element_index.
-attribute_name = wa_changes-attribute_name.

assign wa_changes-old_value->* to <fs_value>.
-old_value = <fs_value>.

assign wa_changes-new_value->* to <fs_value_new>.
-new_value = <fs_value_new>.

append ls_changes to lt_changes.
clear ls_changes.

->bind_table( new_items = lt_changes set_initial_elements = abap_true ).

Note: Do not pass any value to the attribute node as it is a reference variable it will cause dump as it of reference variable type.

I have converted the data reference variable old_value and new_value into string and binded to the table.

Save and activate the whole component and test the output.






Change some values in the table and click on get changes. I am changing the values of the first record.





About Arun


  1. Hello, as I activated the onacttionget_changes method, I received an error: "method get_log does not have a RETURNING parameter. It cannot be called in expressions."

    What should I do? Thanks in advanced

  2. I visit your blog regularly and recommend it to all of those who wanted to enhance their knowledge with ease. The style of writing is excellent and also the content is top-notch. Thanks for that shrewdness you provide the readers! compact tractors
    I visit your blog regularly and recommend it to all of those who wanted to enhance their knowledge with ease. The style of writing is excellent and also the content is top-notch. Thanks for that shrewdness you provide the readers! compact tractors


Powered by Blogger.