I needed to create a database table where there will be no key fields (all fields to be editable during table maintenance) but at the same time I needed some easy way how to identify each table row with unique key. And I found a solution using automatically generated GUID during row addition handled by maintenance view events.
Create table
We will start from scratch so we’ll design and create our database table called in our case ZCA_MNTEVT.
We will disallow it’s display and maintenance because these actions will be performed by it’s maintenance view only.
Now we add the necessary fields
… set technical settings
… and set enhancement category (in top menu – Extras – Enhancement category)
Create table view on top of our table
We will name the view similarly to the database table, ie ZCA_VMNTEVT.
… and create it as maintenance view
In tab Table/Join conditions we enter the name of our database table.
Now click on the View Flds tab, click on Table fields button and select the necessary fields (fileds you want to have in the maintenance view available to be edited)
Note: We don’t want the MANDT and GUID to be displayed because they will be automatically assigned/generated but we need to have them in the view so we can manipulate with data in the fields in the code.
The final look of available fields will be as on the following picture
Now switch to tab Maint.Status where we’ll set the required access level.
At this moment we’re done with the view and we can save&activate it.
Create maintenance view for table view
Stay in the maintenance view screen and go to top menu – Utilities – Table Maintenance Generator where we will create One step maintenance type in new function group named with the same as the view: ZCA_VMNTEVT.
Press F6 (create) to generate code of function group ZCA_VMNTEVT for the maintenance view.
Add events
When the generation is completed go to top menu – Environment – Modification – Events, create new entry for event of row creation/addition (event #05) and assign a form name where our code will be placed.
Note: On this picture you can see all available events you can use in case you need them.
Click on the SAVE button and then on the button in the Editor column.
You will be asked for a new include name where the code will be placed. Enter your desired name or just confirm the suggested one.
When the code editor is displayed enter the following piece of code.
Save and activate all your changes
Modify the maintenance view
Now if you run transaction SM30 and maintain ZCA_VMNTEVT you will see the GUID column is visible and editable. This is not what we’ve originally wanted. So we have to edit the maintenance view accordingly:
Run transaction SE80 and open function group ZCA_VMNTEVT, expand the Screens folder, open screen 0100 and add the highlighted line into the code
Double click on the module and you’ll be prompted for another include name. Enter desired name or just confirm.
When code editor is displayed enter the following piece of code.
Now save and activate all the changes, go to transaction SM30 and maintain ZCA_VMNTEVT.
Now you can see the GUID column is not visible.
The above (hiding a column) was just to show you how you can manipulate data and look&feel of the screen programatically. The same (hiding a column of a view) can be achieved much simpler way – setting it’s visibility directly in the Maintenance view:
If you now regenerate the view using Maintenance view generator, you’ll achieve the same result as previously with typing the code manually.
In this specific case the second approach (setting the field attribute in the view directly) is definitely better because all manual code you put in the auto-genereated code will be removed when maintenance generator is executed again.
Now try to enter some values and save the changes.
Go to transaction SE16, open table ZCA_MNTEVT and verify the GUID has been generated for all new rows.
I love the way you explained it. But unfortunately, the primary key is still reflecting in the maintenance screen. Can you please specify any other way?
Hi, did you enter the ‘H’ in the maintenance attribute for the key field you would like to have hidden?