Capture Changed content after the FM VIEW_MAINTENANCE_CALL

By | September 11, 2008 | Table Maintenance | 9,781 | 1

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
  DATABEGIN OF ITAB OCCURS 0.
        INCLUDE STRUCTURE ZTEST_NP_EVENT.
        INCLUDE STRUCTURE VIMFLAGTAB.
  DATAEND 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.
DATABEGIN OF ITAB OCCURS 0.
        INCLUDE STRUCTURE ZTEST_NP_EVENT.
        INCLUDE STRUCTURE VIMFLAGTAB.
DATAEND OF ITAB.
*
* Output table
TYPESBEGIN OF TY_OUT.
INCLUDE TYPE ZTEST_NP_EVENT.
INCLUDE TYPE VIMFLAGTAB.
TYPESEND   OF TY_OUT.
*
DATAIT_OUTPUT TYPE STANDARD TABLE OF TY_OUT.
*
* Output ALV reference
DATAO_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).

I came across the requirement from one of the Forum post in the ABAP Development forum on SDN. You can follow this link to view the discussion: VIEW_MAINTENANCE_CALL

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

1 Comment

  • Ujjaval

    Nice work man…

    Not that I understand your SAP blog. But its amazing to see how you maintain this things beside your work along with your pencil drawings which are good.. you’ve maintained your hobby even after school.

    Cheers,

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.