Sie sind auf Seite 1von 4

Table Maintenance with Create/Modified Information Automatically Filled in

If you are creating custom table which would be used as configuration table i.e. content of table would be rarely changed, then creating a custom build data entry screen is not worth the effort. In such cases using table maintenance generator is highly justified. Table Maintenance Generator is very powerful tool to create basic data entry screen. Although entry screen is basic, it comes with standard function of value help, value checked against check table, duplication check on primary key etc. With all these features within few minute it can provide you data entry screen with insert, change and delete function. Table maintenance generator creates a function group which is combination of sap-standard includes, custom program and screen. The custom (usually name starting with Z) part of function group can be changed to add specific requirement. In this blog I will discuss about filling Created by username, create on date, created on time automatically when new record is inserted. And filling Updated by username, updated on date and updated on time when the record is modified. Using this information you can certainly answer who created or last updated the record and when. If there is further requirement to track every change then I would recommend creating you own data entry screen and use Change Object Technique to log changes. So, I have created a table as shown in screen shot below.

Notice that it has field ERNAM, ERDAT, ERZET and AENAM, AEDAT, AEZET. These fields stores the information which I would like table maintenance to fill-in automatically. All these changes are done in following steps.

1. Create table maintenance 2. Hide the columns 3. Event to fill-in Created by Information 4. Event to fill-in Updated information Step 1 Create table maintenance Create table maintenance using table maintenance generator. At this stage you will have every column displayed in your screen.

Step 2 Hide the columns You can either hide or deactivate these columns as we dont want users to change these values. Open then function group created in SE80 and double click on screen which has table control. In the PBO just before the LOOP AT extract WITH CONTROL add a module. Here, Ive added module modify_element. Double click on the module and the module in new include.

This code will hide the column from table control.


MODULE modify_element OUTPUT. LOOP AT -cols INTO vim_tc_cols. IF vim_tc_cols-screen-name = 'ZLBN_ROUTETM-ERNAM' OR

vim_tc_cols-screen-name vim_tc_cols-screen-name vim_tc_cols-screen-name vim_tc_cols-screen-name vim_tc_cols-screen-name

= = = = =

'ZLBN_ROUTETM-ERDAT' 'ZLBN_ROUTETM-ERZET' 'ZLBN_ROUTETM-AENAM' 'ZLBN_ROUTETM-AEDAT' 'ZLBN_ROUTETM-AEZET'

OR OR OR OR .

vim_tc_cols-invisible = 1 . MODIFY -cols FROM vim_tc_cols . ENDIF. ENDLOOP. ENDMODULE. " MODIFY_ELEMENT

OUTPUT

Note: If you just want to deactivate the column you need to add module within LOOP AT extract WITH CONTOL and put deactivation code in there. After this, save and activate the function module. At this point if you run table maintenance it should not show you the fields as shown in below screen shot.

Step 3 Event to fill-in Created by Information We will add two events here which will be used to fill information in field at the time of adding new record and when records are changed. To add event open table maintenance generator in change mode then in menu path Enviroment>Events add event 01 and 05 put a subroutine name and create subroutine by hitting button next to name.

In the form routine under event 05 add code which will fill created user, date and time information.
FORM zlbn_routetm_new_entry . zlbn_routetm-ernam = sy-uname . zlbn_routetm-erdat = sy-datum . zlbn_routetm-erzet = sy-uzeit . ENDFORM. "ZLBN_ROUTETM_NEW_ENTRY

Step 4 Event to fill-in Updated information In the form routine under event 01 put following code. This will fill update by information in respective fields.
FORM zlbn_routetm_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. "ZLBN_ROUTETM_SAVE

Das könnte Ihnen auch gefallen