The requirement is to capture the changed contents – updated, deleted or inserted – after the table maintenance call using the FM VIEW_MAINTENANCE_CALL.
The simple solution to handle this requirement is:
1. Get all the data from the database table for which we will call the FM VIEW_MAINTENANCE_CALL.
2. Call FM VIEW_MAINTENANCE_CALL
3. Get all the data from the database table again in separate internal table Compare the contents of the data using some utility.
This kind of generic solution would be possible, but the performance of the report would be slow. I thought of having something which can tell us directly just after the FM call, which line was changed: update or deleted or inserted. Suddenly, I thought of implementing the Event and use the same data which are there in the global tables of the Maintenance Function.
Based on the thought, new steps to achieve this solution would be:
1. Implement Event in the Maintenance. Export the Main internal table to ABAP memory, which can be accessed later from the calling program.
2. Call the FM VIEW_MAINTENANCE_CALL
3. Import the data from the ABAP memory
In this later approach, we can get the data instantly from the memory. Since we will have the indicators (ACTION field in the table) which will help us to identify the type of change made to table entries.
You can find more information on the Events of the Table Maintenance at: Extended Table Maintenance Events
To implement the solution, I have used the Event 01 - Before Saving the data into Database. We need to create the subroutine which can be called when the event gets hit. When we create a subroutine, it will be created in the same Function group in which we have created the Table mainteinance. Hence, it will provide us the access to all the global tabbles. From all of these tables, we will export the internal table TOTAL to the memory.
TOTAL table contains the fields: ACTION and MARK.
Content of the ACTION field would help us to indetify the type of change:
D – Delete
U – Update
N – New Entry
Code Snippet to Export data in Event 01 |
*&---------------------------------------------------------------------* *& Form EXPORT_TOTAL_TABLE *&---------------------------------------------------------------------* * This form is called in the Event 01 of the table maintainence * events *----------------------------------------------------------------------* FORM EXPORT_TOTAL_TABLE. * * Table of the same structure of the TOTAL which can be exported DATA: BEGIN OF ITAB OCCURS 0. INCLUDE STRUCTURE ZTEST_NP_EVENT. INCLUDE STRUCTURE VIMFLAGTAB. DATA: END OF ITAB. * * Moving data to ITAB from total ITAB[] = TOTAL[]. * * Clearing memory FREE MEMORY ID 'ZTEST_EVENT'. * * Exporting data to Memory EXPORT ITAB = ITAB TO MEMORY ID 'ZTEST_EVENT'. * ENDFORM. "EXPORT_TOTAL_TABLE
|
Code Snippet of the Report |
*&---------------------------------------------------------------------* *& Report ZTEST_NP_EVENT *&---------------------------------------------------------------------* *& This Report will start the Table Maintainence and after saving the *& data in the table maintinence, it will generate a list which will *& what data has been newly added, updated or deleted *&---------------------------------------------------------------------* REPORT ZTEST_NP_EVENT. * * Table with the Same structure of the table which is exported. DATA: BEGIN OF ITAB OCCURS 0. INCLUDE STRUCTURE ZTEST_NP_EVENT. INCLUDE STRUCTURE VIMFLAGTAB. DATA: END OF ITAB. * * Output table TYPES: BEGIN OF TY_OUT. INCLUDE TYPE ZTEST_NP_EVENT. INCLUDE TYPE VIMFLAGTAB. TYPES: END OF TY_OUT. * DATA: IT_OUTPUT TYPE STANDARD TABLE OF TY_OUT. * * Output ALV reference DATA: O_ALV TYPE REF TO CL_SALV_TABLE. * * START-OF-SELECTION. * Start the Table maintainence CALL FUNCTION 'VIEW_MAINTENANCE_CALL' EXPORTING ACTION = 'U' VIEW_NAME = 'ZTEST_NP_EVENT' EXCEPTIONS CLIENT_REFERENCE = 1 FOREIGN_LOCK = 2 INVALID_ACTION = 3 NO_CLIENTINDEPENDENT_AUTH = 4 NO_DATABASE_FUNCTION = 5 NO_EDITOR_FUNCTION = 6 NO_SHOW_AUTH = 7 NO_TVDIR_ENTRY = 8 NO_UPD_AUTH = 9 ONLY_SHOW_ALLOWED = 10 SYSTEM_FAILURE = 11 UNKNOWN_FIELD_IN_DBA_SELLIST = 12 VIEW_NOT_FOUND = 13 MAINTENANCE_PROHIBITED = 14 OTHERS = 15. IF SY-SUBRC <> 0. ENDIF. * * Importing the memory from the Memory ID * Table has been exported in the Event 01 of the Table * maintenance events. IMPORT ITAB TO ITAB FROM MEMORY ID 'ZTEST_EVENT'. * * Clear the memory id FREE MEMORY ID 'ZTEST_EVENT'. * * Moving data to output IT_OUTPUT = ITAB[]. DELETE IT_OUTPUT WHERE ACTION IS INITIAL. * * New ALV Instance TRY. CL_SALV_TABLE=>FACTORY( EXPORTING LIST_DISPLAY = ABAP_FALSE IMPORTING R_SALV_TABLE = O_ALV CHANGING T_TABLE = IT_OUTPUT ). CATCH CX_SALV_MSG. "#EC NO_HANDLER ENDTRY. * * Display the ALV O_ALV->DISPLAY( ).
|
0 comments
Post a Comment