Enhanced Table Maintenance with Automatic Change Recording

Table maintenance generator is very powerful tool to generate simple data entry screen for tables. For tables which store configuration data i.e. rarely modified it not worth spending time creating module pool program for data entry. Table maintenance generator also gives programmer opportunity to modify standard behaviour by including additional logic. In this blog I will enhance standard table maintenance to automatically record created by and created date/time and also last modified by and last modified date/time.

I have this table which record additional information per plant. Instead of hard-coding this text we decided to create a table and put these values there in case it requires change in future.

Create table with ‘Display/Maintenance Allowed’

Table Maintenance

I have fields ERNAM, ERDAT, ERZET, AENAM, AEDAT, AEZET apart from fields which will hold actual data.

Table Maintenance Field for change recording SAP ABAP

Create table maintenance from menu option Utilities->Table Maintenance Generator. Make sure to select ‘one step’ in Maintenance type.

With standard table maintenance you will have all field active and ready for input. Since we username and date times field to be filled automatically by program logic we need to hide them from table maintenance screen. To do that, in table maintenance screen double click on screen number.

Table Maintenance Generator Auto recording changes  Technical setting SAP SE11

It will take you to the flow logic of screen. Add module modify_element in PBO of screen.

PROCESS BEFORE OUTPUT.
 MODULE LISTE_INITIALISIEREN.

*--------------------------------------------------------------------*
* Hide user name and date/time column
*--------------------------------------------------------------------*
   MODULE modify_element .
*--------------------------------------------------------------------*
     
 LOOP AT EXTRACT WITH CONTROL
  TCTRL_ZSD_PLANT_CODE CURSOR NEXTLINE.
   MODULE LISTE_SHOW_LISTE.
 ENDLOOP.
*

Save and double click on modify_element module to create module in new include.

If it comes back saying you are already editing main program then close everything, open table in display mode and navigate to PBO in display mode and try again with double click.

In module modify_element copy following code. This code is going through the table control structure to hide columns.

*----------------------------------------------------------------------*
***INCLUDE LZSD_PLANT_CODEO01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  MODIFY_ELEMENT  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE modify_element OUTPUT.

  LOOP AT <vim_tctrl>-cols INTO vim_tc_cols.
    IF vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-ERNAM' OR
       vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-ERDAT' OR
       vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-ERZET' OR
       vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-AENAM' OR
       vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-AEDAT' OR
       vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-AEZET' .

      vim_tc_cols-invisible = 1 .
      MODIFY <vim_tctrl>-cols FROM vim_tc_cols .
    ENDIF.
  ENDLOOP.

ENDMODULE.                 " MODIFY_ELEMENT  OUTPUT

Save and activate all objects. Make sure the function group where table maintenance generator code is active including screen and our new include.

If you run table maintenance now you should not see these field.

table maintenance generator auto record changes se11

Now it’s time to add code which will fill user name, date and time when records are created or changed.

Table Maintenance Generator offers events that during program processing and we programmer can add our own code to execute at this point. Very similar to user-exits. Events in which we are interested in are 05 which executes when new entry is create and event 01 which triggers before saving the data in database. We are going to add code at these event which will populate our fields.

Open Table Maintenance Generator in change mode and choose menu option Environment->Modification->Events.

table maintenance generator se11 events sap abap

Click ok on dialog box which say do not change SAP data. On next screen press ‘New Entries’ and add modules at 05 and 01 events.

table maintenance se11 sap abap events modification

Click on the editor button next to form routine, create include if required, and put following code in each of these form routines.

*&---------------------------------------------------------------------*
*&      Form  ZSDPLANT_NEW_ENTRY
*&---------------------------------------------------------------------*
FORM zsdplant_new_entry .
  zsd_plant_code-ernam = sy-uname .
  zsd_plant_code-erdat = sy-datum .
  zsd_plant_code-erzet = sy-uzeit .
ENDFORM.                    "zsdplant_new_entry
*&---------------------------------------------------------------------*
*&      Form  ZSDPLANT_MODIFY_SAVE
*&---------------------------------------------------------------------*
FORM zsdplant_modify_save .

  FIELD-SYMBOLS : <fs_field> TYPE ANY .

  LOOP AT total .
    CHECK <action> EQ aendern.
    ASSIGN COMPONENT 'AENAM' OF STRUCTURE <vim_total_struc> TO <fs_field> .
    IF sy-subrc = 0 .
      <fs_field> = sy-uname .
    ENDIF.

    ASSIGN COMPONENT 'AEDAT' OF STRUCTURE <vim_total_struc> TO <fs_field> .
    IF sy-subrc = 0 .
      <fs_field> = sy-datum .
    ENDIF.

    ASSIGN COMPONENT 'AEZET' OF STRUCTURE <vim_total_struc> TO <fs_field> .
    IF sy-subrc = 0 .
      <fs_field> = sy-uzeit .
    ENDIF.

    READ TABLE extract WITH KEY <vim_xtotal_key>.
    IF sy-subrc = 0.
      extract = total .
      MODIFY extract INDEX sy-tabix.
    ENDIF.

    MODIFY total.
  ENDLOOP.
ENDFORM .                    "ZSDPLANT_MODIFY_SAVE

Save and Activate all objects. To activate function group you can go to SE80 and activate from there.

I have created two entries in table maintenance and then changed one. This is how table contents look like.

SE11 table maintenance generator auto change recording events


You may be interested in reading following blogs

Defining Customising Table

Enhance SPRO Structure – Adding Node to SPRO

9 Replies to “Enhanced Table Maintenance with Automatic Change Recording

  1. This would not work. after check, READ TABLE extract WITH KEY . and
    If sy-subrc = 0,
    lv_index = sy-tabix.
    endif.

    Later, MODIFY extract INDEX lv_index.

  2. HI

    i was tried this its throwing to dump .

    actually what is my requirement is if you pass USER NAME into ‘Z’ table by using table maintenance generator then automatically update the remaining fields information (like first name , last name, email address, contact details etc,.)

    is there any solution for this, i was tried a lot but i am not found proper output

    please help me

    best regards vijay

  3. Sometimes navigation does not work because we have to navigate in “display” mode.
    Thanks a lot, it works just fine!

Leave a Reply