Table Maintenance Generator and its Modifications Applies to: SAP ECC (6.0). For more information, visit the ABAP homepage. Summary This article contains the procedure of implementation of table maintenance generator for custom tables and also explains some modifications available in the table maintenance generator Author: Nimisha Agarwal Company: Infosys Technologies Limited Created on: 31 May 2010 Author Bio Nimisha Agarwal is working with Infosys Technolofies Limited from last 1.5 years. She has got experience in various projects in SAP ABAP. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 1 Table Maintenance Generator and its Modifications Table of Contents Introduction ......................................................................................................................................................... 3 Reasons to use Table Maintenance Generator .............................................................................................. 3 Prerequisite to Create Table Maintenance Generator for a Custom Table .................................................... 3 Creation of Table Maintenance Generator for a Custom Table ......................................................................... 4 Maintaining the Table Through SM30 ................................................................................................................ 8 Modifications in Table Maintenance Generator .................................................................................................. 9 Maintenance Screens: .................................................................................................................................... 9 Events ........................................................................................................................................................... 13 Difference Between Event ‘05’ and ‘21’ ..................................................................................................................... 24 Disclaimer and Liability Notice .......................................................................................................................... 25 SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 2 Table Maintenance Generator and its Modifications Introduction Table Maintenance Generator (TMG) is a tool which is used to create equipment by which customized tables created by end users can be changed as required, such as making an entry to that table, deleting an entry, modifying an existing entry etc. Table Maintenance generator can be created using transaction SE54 or SE11. A table maintenance generator is used to create table maintenance program to add, modify or delete records in the database tables. It is generated to maintain customizing data with these maintenance dialogs. We can check the table maintenance dialog in SM30 or SE16. In SM30, We have display and maintain options. Display option is used to view the table contents and maintain option is used to maintain the entries in the table. Reasons to use Table Maintenance Generator There are different reasons due to which table maintenance generator is used. 1. In the production system, end-users will not be having access to transaction codes like SE11 and SE16. Therefore, developers will not be having access to many transaction codes including the above SE11 and SE16. So in order to edit or create the contents of a database table, we should go for table maintenance generator. 2. With the help of table maintenance generator, we can edit or create multiple entries at a time. 3. Various events can be added to the table maintenance generator to maintain the entries. These events get triggered while maintaining the entries in the table. They help in enhancing the functionality of the table maintenance. Prerequisite to Create Table Maintenance Generator for a Custom Table While creating the table the table, go in tab ‘Delivery and Maintenance’. Select the option ‘Display/Maintenance allowed’ under ‘Data Browser/Table View Maint.’ as shown below. This will help in maintaining the data entries for the table. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 3 Table Maintenance Generator and its Modifications Creation of Table Maintenance Generator for a Custom Table Steps: 1. Let us take an example of a custom table ZMTABLE to implement the table maintenance generator and its events. 2. Go to Utilities Table Maintenance Generator. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 4 Table Maintenance Generator and its Modifications 3. The following screen would appear to implement the table maintenance generator. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 5 Table Maintenance Generator and its Modifications The following are the options available in the screen. These options are filled according to the given description. Table/View: the name of the table or view for which table maintenance generator has to be implemented. Authorization Group: Authorization group is used to apply authorization checks to a particular group of people i.e. to specify the users who are authorized to maintain table or view contents. If in case, a table has to be maintained by a group of people, an authorization group is assigned else fill the option ‘&NC&’. Authorization groups for a table/ view can be created using transaction SE54. Authorization Object: Authorization objects can be created using transaction SU21. An authorization object can have upto10 authorization fields which are used to verify user authorizations. A user has to pass the check for every field to run the authorization check successfully. In this case it is auto generated which is S_TABU_DIS have following fields: DICBERCLS - Authorization group, maximum field length is four characters. ACTVT - Activity (02: Add, change or delete table entries, 03: Only display table contents). S_TABU_DIS is used for displaying and maintaining tables. It controls the access during following transactions: SM31: Standard maintenance tool SM30: Enhanced table maintenance SE16: Data browser, including access in customizing Function group: The function group is the one in which all the maintenance modules of the given table or view are generated. All the generated maintenance modules will belong to this function group. Function group names can have maximum of 26 alphanumeric characters. A function group can also be created in transaction SE80. Here, the name of the function group can be same as that of table/ view. Package: Package here refers to the function group package which is assigned to the table or view. A package can be created in transaction SE21 or SPACKAGE. Maintenance Type: There are two maintenance types: One step dialog: One step dialogs only have one maintenance screen (overview screen) containing all the fields i.e. one has to give screen number in overview screen only. All the entries in overview screen are displayed in the form of lists. It works as follows: Go to SM30; give the table name for which table maintenance generator is implemented. Overview screen would be displayed. To create entries, click on ‘New Entries’. Enter the values and save the data. Multiple entries can be created using one step dialog. Two step dialog: Two step dialogs have one additional maintenance screen (single screen) along with overview screen. Here, the overview screen contains only the key fields and texts longer than 20 characters and single screen contains all fields. Single screen can be called from overview screen by function key, for every entry. It works as follows: Go to SM30; give the table name for which table maintenance generator is implemented. Overview screen would be displayed. To create entries, click on ‘New Entries’. Now, next screen (single screen) would be displayed, enter the values and save. You can enter one record at a time. Maintenance Screen No.: Maintenance screen numbers are the internal number for each maintenance screen. It has two different cases: One step dialog: In this case, only overview screen value is required. It can have any screen number except 1000 because 1000 is assigned to the selection screen. Two step dialog: In this case, both the screen numbers are required i.e. one has to give the screen number for both overview screen and single screen. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 6 Table Maintenance Generator and its Modifications Recording Routine: It gives the option which recording routine should be used to record the changes to table contents. It can be done automatically and manually. There are two types of recording routines: Standard routines: More functionality can be added to the standard routines using individual routines. We can create individual routines via menu function Environment Modification Events. It concerns the events 10, 11 and 12. No, or user, recording routine: In this case, it’s up to the users choice whether he wants the recording or not. Compare Flag: This flag indicates whether the maintenance transaction allows the (checked) activation of Business Configuration Sets (BC Sets), and the adjustment. This is the case if the maintenance transaction can run in the background. The following settings are available for the flag: No Information Not adjustable Adjustments in Dialog Automatically Adjustable All the fields are filled according to the above mentioned description. Then click on ‘Create’. The Table Maintenance Generator has been implemented successfully. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 7 Table Maintenance Generator and its Modifications Maintaining the Table Through SM30 1. Go to SM30, give table name and click on ‘Maintain’. 2. The following screen would appear. You can click on ‘New Entries’ to make the entries to the table. 3. Enter the values in the following screen and click on ‘Save’. 4. Data would be saved in database successfully. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 8 Table Maintenance Generator and its Modifications Modifications in Table Maintenance Generator There are different types of modifications available in the table maintenance generator. These are as follows: Maintenance screens: The function group which has been created in the table maintenance Generator contains the code and the maintenance screens. We can modify the way, maintenance screens appears to user through the mentioned option. It navigates to the screen painter where we can modify the appearance of the screens. User Interface: A dialog specific interface can be created using user Interface which can be changed with Menu Painter. The maintenance dialogs access the standard table/view maintenance interface in the function group SVIM. One can define a function group interface by choosing interface to copy and change the original interface. The message ‘User Interface exists’ in the ‘Maintain Interface assignment’ dialog indicates whether an interface already exists in the current function group. Events: Much functionality can add to the table maintenance though the addition of events. Maintenance events are used, when certain logic is to be added in the already generated table maintenance. They are called when certain events are triggered, when user maintains the table through SM30. Source Code: It displays the function group main program and maintenance dialog top include and also the user defined includes in the ABAP editor. Maintenance Screens: Maintenance screens can be modified so as to enable or disable any of the fields during table maintenance. It means that any of the fields can be made editable or non-editable based on the requirement through modification of maintenance screens. It can be achieved through following procedure: 1. Go to Environment Modifications Maintenance Screens SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 9 Table Maintenance Generator and its Modifications 2. Click on ‘Element List’ in the screen which appears. The following screen would appear thereafter. 3. A field can be made disabled by clicking the checkbox of the Input option of that particular field i.e. uncheck the checkbox of the respective field. In this case, we would disable the username field as below. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 10 Table Maintenance Generator and its Modifications 4. The maintenance screen would now appear as follows in transaction SM30. In this ‘User name’ is now disabled. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 11 Table Maintenance Generator and its Modifications 5. The layout of the appearing screen can also be modified through the screen painter. Here, we can also modify the screen name of a field by changing its parameters. It can be achieved via Environment Modifications Maintenance Screens Layout. The following screen appears: Make the changes; save and activate the maintenance screen. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 12 Table Maintenance Generator and its Modifications Events Table maintenance generator is used for handling events. Once table maintenance is implemented for a table, events can be handled. There is a list of predefined list of events in SAP. These events can be implemented using the table maintenance. Events are used to add custom checks for table maintenance screen generated using the table maintenance generator in SE11. Many validations, checks and functionalities can be performed while maintaining the table entries. These events are triggered when a table/view is maintained through transaction SE16 or SM30. The action to be performed by these events can be defined by writing the FORM routine in the ‘Includes’ generated by function group. Events can be implemented as follows: 1. The events can be added in table maintenance generator via Environment Modifications Events 2. The following screen appears. Click on ‘New Entries’ to add events to the table. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 13 Table Maintenance Generator and its Modifications 3. In the next screen, click on F4 help and the following screen of events would appear. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 14 Table Maintenance Generator and its Modifications 4. EVENT 1: 03- Before deleting the data displayed This event gets triggered whenever user delete a data i.e. select a record and click on ‘delete’. Let us add first event i.e. before deleting the data displayed. Give the name of the event in ‘FORM routine’ and click on ‘Editor’. 4.1 The following screen would appear. We can use an already existing include or a new include also. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 15 Table Maintenance Generator and its Modifications 4.2 After selecting the ‘Include’, write the code inside the ‘include’ of function group of the event and activate the ‘include’. Write the following code in the FORM routine. Please note that FORM and ENDFORM statements have to be added on our own because these statements would appear automatically. Save and activate the code. Note: Whenever a new ‘include’ is created for a function group, the function group becomes deactivated. In this case; both ‘include’ and function group has to be activated. If the function group is not activated, a runtime error is generated while maintaining the table through SM30. Function group can be activated in transaction SE80. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 16 Table Maintenance Generator and its Modifications 4.3 This code would work as: Whenever a record in deleted from ZMTABLE through table maintenance, a pop-up would be displayed asking ‘Are you sure to delete the record’. If the user clicks ‘yes’, the record would be deleted and if user clicks ‘No’, first screen would appear without deleting the data. The demo has been shown in the below screenshots: 4.3.1. Go to transaction SM30, give the table name and Click on ‘Maintain’. In the subsequent screen, select a record and click on delete. 4.3.2. A popup would be displayed asking ‘Are you sure to delete the record’. Click on ‘Yes’. 4.3.3. The record would get deleted. Click on ‘Save’ to save the data. 4.3.4. If the user clicks on ‘No’ in step 4.3.2, the record would not get deleted. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 17 Table Maintenance Generator and its Modifications 5. EVENT 2: 21- Fill hidden fields This event gets triggered whenever user hits ‘Enter’ key of the keyboard while creating the new entries through table maintenance. We can apply various validation checks in this routine. We can also generate the values of certain fields automatically on hitting of ‘Enter’ key. Let us add the second event. st 5.1. Repeat the steps from 1 to 3 and select the 21 event i.e. fill hidden fields. Give a name to the event and click on editor. 5.2. Select the ‘include’ from the subsequent screen and write the following code in the FORM and ENDFORM statements. Save and activate the code, include and function group. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 18 Table Maintenance Generator and its Modifications 5.3. This code would work as follows: Whenever a user creates new entry in ZMTABLE through table maintenance and hits ‘Enter’ key on the keyboard, this event would get triggered. If the USERID field of table is left blank, an error message would be thrown saying ‘User Id cannot be initial. Please enter a value.’ Secondly, since USERNAME field is an output only field, its value is auto generated whenever user hits ‘enter’. The demo has been shown below: 5.3.1. Go to transaction SM30, give the table name and Click on ‘Maintain’. In the subsequent screen, click on ‘New Entries’. The following screen would appear. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 19 Table Maintenance Generator and its Modifications 5.3.2. Write only ‘Hobbies’ of the user and hit ‘Enter’ key. Since a validation check has been applied to the User Id field, an error message appears as follows: 5.3.3. Now enter the user id of the user. This screen would appear. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 20 Table Maintenance Generator and its Modifications 5.3.4. Press the ‘Enter’ key now. The value of User Name would be automatically generated. Click on save to save the data. Similarly, we can add many more validation checks to enhance the functionality of the table maintenance. 6. EVENT 3: 05- Creating a new entry. This event gets triggered when the user makes a copy of an existing entry. In this case, he can select an entry from the existing data and create its copy. Let us add the third event: th 6.1. Repeat the steps from 1 to 3 and select the 5 event i.e. creating a new entry. Give a name to the event and click on editor. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 21 Table Maintenance Generator and its Modifications 6.2. Select the ‘include’ from the subsequent screen and write the following code in the FORM and ENDFORM statements. Save and activate the code, include and function group. 6.3. This code would work as follows: This code would help the user to create a copy of an existing entry with a different key value. This means user can create the same record but with different key values. The demo of the above code has been shown below: 6.3.1. Go to transaction SM30, give the table name and Click on ‘Maintain’. In the subsequent screen, select an existing entry and click on ‘copy’. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 22 Table Maintenance Generator and its Modifications 6.3.2. The following screen would appear. Change the value of User Id and hit ‘Enter’ key. Make sure that the new user id should not be an existing entry; else an error message would be displayed saying ‘An entry already exists with the same key’. 6.3.3. The following screen appears with a message ‘number of entries copied: 1’. Please note that User name has automatically changed to the system user name. Click on ‘Save’ to save the data. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 23 Table Maintenance Generator and its Modifications Difference Between Event ‘05’ and ‘21’ The two events i.e. fill hidden fields and creating new entry works on hitting ‘enter’ key of keyboard. But the difference lies within the function code of the events. Event 21- Fill Hidden fields: This event gets triggered when user creates a new entry in the table and hits ‘Enter’ key. This event does not get triggered when user creates a copy of an existing entry. Event 05- Creating new entry This event gets triggered both the times i.e. whenever the user creates a new entry as well as creates a copy of an existing record. But in case; both the events are being used for a requirement in table maintenance, there are two cases. 1) Whenever the user creates a new entry and hits ‘Enter’ key, the first event which would get triggered is ‘Fill Hidden fields’ and then ‘Creating a new entry’. In that case; to avoid the usage of second event which is being used in copy functionality, we use function code. The function code for the copy statement is ‘KOPF’. By applying this, the code for ‘Creating a new entry’ would not work. It can be implemented as follows. 2) When the user creates a copy of an existing entry and hits the ‘Enter’ key, only ‘Creating a new Entry’ event gets triggered. It checks the value of the function code which is ‘KOPF’ and executes the code accordingly. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 24 Table Maintenance Generator and its Modifications Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document. SAP COMMUNITY NETWORK © 2010 SAP AG SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 25