Events in database table maintenance view

SAPI 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.

Table creation 01

We will disallow it’s display and maintenance because these actions will be performed by it’s maintenance view only.

Table creation 02

Now we add the necessary fields

Table creation 03

… set technical settings

Table creation 04

… and set enhancement category (in top menu – ExtrasEnhancement category)

Table creation 05

Create table view on top of our table

We will name the view similarly to the database table, ie ZCA_VMNTEVT.

Table view creation 01

… and create it as maintenance view

Table view creation 02

In tab Table/Join conditions we enter the name of our database table.

Table view creation 03

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.

Table view creation 04

The final look of available fields will be as on the following picture

Table view creation 05

Now switch to tab Maint.Status where we’ll set the required access level.

Table view creation 06

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 – UtilitiesTable Maintenance Generator where we will create One step maintenance type in new function group named with the same as the view: ZCA_VMNTEVT.

Maintenance view 01

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.

Events 01

Click on the SAVE button and then on the button in the Editor column.

Events 02

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.

Events 03

When the code editor is displayed enter the following piece of code.

Events 04

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

Update of maintenance view 01

Double click on the module and you’ll be prompted for another include name. Enter desired name or just confirm.

Update of maintenance view 02

When code editor is displayed enter the following piece of code.

Update of maintenance view 03

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.

Update of maintenance view 04

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:

Hiding a column via 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.

Update of maintenance view 05

Go to transaction SE16, open table ZCA_MNTEVT and verify the GUID has been generated for all new rows.

Update of maintenance view 06

2 thoughts on “Events in database table maintenance view

  1. 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?

Leave a Reply