Especially if you are working with sensitive data, it is crucial to track the latest changes. Such process creates responsibility and helps to avoid business risk due to error or negligence. In the "How to track changes with NextTables" article, you learned the basics of the change log process. In this article you will receive step by step guidance through the technical side of implementation.
At the end of this article, you will be able to lock the change log fields and fill them automatically. You can see an example below.
In order to achieve the desired result, we have to change the setting EDITABLE of the fields Changed on and Changed by to locked. In order to ensure it, we will set this setting in the META method of the /NLY/BADI_EDITOR BAdI.
Furthermore, we have to derive and fill these fields in the I_STEP 1 of the UPDATE method.
In the How to implement a BAdI for NextTables article you have learned how to create a BAdI implementation. To make sure that the BAdI is executed for a certain table only, you have to setup the filter criteria accordingly. Please enter respective table name and table type. In our example we use the DSO ZOMACOST.
The logic itself is implemented in the implementing class. First, we will utilize the method /NLY/IF_EDITOR~SET_META_EXIT to change the field editability settings. Double click on the method to create an implementation.
In our example, we use the fields ZCUSER and ZCDATE to store the Changed by and Changed on information. In order to prevent manual changes, we have to set editability of those fields to locked using the following code.
METHOD /nly/if_editor~set_meta_exit.
DATA: l_s_fields_info TYPE /nly/ts_fields_info.
FIELD-SYMBOLS: <l_s_fields_info> TYPE /nly/ts_fields_info.
* Change properties
LOOP AT ch_t_fields_info ASSIGNING <l_s_fields_info>.
CASE <l_s_fields_info>-fname.
WHEN '/BIC/ZCUSER' OR '/BIC/ZCDATE'.
<l_s_fields_info>-editable = '1'.
ENDCASE.
ENDLOOP.
ENDMETHOD.
After activation, user cannot edit these fields via front end.
After we have ensured that the fields are not editable, we will fill them automatically. In our example we use system parameters sy-uname, which contains the active user, and sy-datum, which represents the current date. Please create an implementation of the Update method /NLY/IF_EDITOR~SET_UPDATE_EXIT with the following code.
METHOD /nly/if_editor~set_update_exit.
FIELD-SYMBOLS:
<fs_t_table> TYPE ANY TABLE,
<ls_table> TYPE /bic/azomacost2. "Table structure
CHECK co_table IS BOUND.
ASSIGN co_table->* TO <fs_t_table>.
CASE i_type.
WHEN /nly/cl_table_rest_v3=>co_type_validate.
CASE i_step.
WHEN /nly/cl_table_rest_v3=>co_step_before_update.
WHEN /nly/cl_table_rest_v3=>co_step_after_update.
ENDCASE.
WHEN /nly/cl_table_rest_v3=>co_type_update
OR /nly/cl_table_rest_v3=>co_type_insert
OR /nly/cl_table_rest_v3=>co_type_delete.
CASE i_step.
WHEN /nly/cl_table_rest_v3=>co_step_before_update.
LOOP AT <fs_t_table> ASSIGNING <ls_table>.
<ls_table>-/bic/zcuser = sy-uname.
<ls_table>-/bic/zcdate = sy-datum.
ENDLOOP.
WHEN /nly/cl_table_rest_v3=>co_step_after_update.
ENDCASE.
ENDCASE.
ENDMETHOD.
Now, as you change the values, the fields Changed by and Changed on are updated automatically.
As you implement your custom logic, please make sure that all involved pieces are activated, not only the implementing class. You need to activate the following objects:
Which License is needed for this feature Professional ✘ | Enterprise ✔