cancel
Showing results for 
Search instead for 
Did you mean: 

Change Log Contains only Index.What about sorting

daniel_humberg
Contributor
0 Kudos

In my application, I show an ALV table, and the user can edit the different rows of the table.

When I save, I read the change log, and write all changes of the user to an action-log-table (this tables logs all changes of all users).

Now, the problem comes when I sort or filter the ALV in the meanwhile:

The change log only stores the context-node and the index, but after sorting, the index is not correct anymore, and therefore worthless.

Example: I edit the first line of the ALV, sort, and edit the (new) first line afterwards. The change log will contain the index 1 twice in this case, and I have no change to find out which entries have been changed, have I ?

What can I do?

Regards, Daniel

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hallo Daniel,

each sort in an ALV-Component results in a roundtrip. You can track the changes in the WDDOBEFOREACTION-Method of a view-controller and build your own change log.

For example, you can add a hidden column to the table with a dirty-flag, which is set in the WDDOBEFOREACTION-Method.

Regards

Joerg

daniel_humberg
Contributor
0 Kudos

In other words: the built-in change log is completely useless if you allow sorting, right?

Former Member
0 Kudos

The change log can inform you about the changes in each roundtrip. But when you change the order of the elements of a context node, the recorded index information of the log is wrong.

daniel_humberg
Contributor
0 Kudos

I now solved it like this:

<b>Problem</b>:

The Change Log contains the context node that was changed, and the index of the element in the node. After sorting the node (e.g. when displaying it in an ALV), the index in the change log is not valid anymore.

<b>Quick-Fix</b>:

Disable Sorting. Users can use filtering as a work-around.

<b>Solution</b>:

Wrap the built-in Context-Change-Log with a self-controlled Context-manager.

<b>New Class</b>: <b><u>zcl_change_log_manager</u></b> (either static, or as singleton)

<b>Attribute</b>:

<u>st_change_log</u>

(columns: MANDT | Ids of my entitites, and entity type | NODE_NAME | ATTRIBUTE_NAME | OLD_VALUE | NEW_VALUE )

=> will contain all changes of the user since the last save, except the changes that were done after calling update_change_log the last time (these changes are still in the context-change-log until you call update_change_log)

Methods:

<u>update_change_log</u>( ir_context TYPE REF TO if_wd_context )

1. get current change log from the controller context (called „context-change-log“ from now on)

2. add object type and object keys to the change-log-table

3. add change-log-table to st_change_log

4. reset the context-change-log

=> called whenever the indices in the context-change-log will be invalidated, e.g. whenever the ALV is sorted.

Maybe also when the user changes a value in a column, by which the ALV is currently sorted.

=> this can be done in an event handler for the event ON_STD_FUNCTION_BEFO of the ALV. Inside this handler, you can check whether the current event was sorting (r_param) or something else

=> could be also called before filtering or paging, but this is not necessary since these functions do not disturb the context-change-log

<u>get_change_log</u>( ir_context TYPE REF TO if_wd_context )

1. call <u>update_change_log</u> to put the context-change-log into st_change_log

2. return <u>st_change_log</u> (returning parameter)

=> called whenever we need to get the change_log (e.g. when saving, or when writing the action log)

<u>reset_change_log</u>( ir_context TYPE REF TO if_wd_context )

1. clear st_change_log

2. reset controller-change-log

=> called when selecting a new program/project

=> called after save

=> called when going from edit mode to display mode without save

Answers (0)