February 27, 2015

Table Maintenance options and ABAP

One of the traits I like about SAP is that you have several facilities to achieve more. One of those characteristics is in transaction ‘SE11’. This transaction is used to create tables and it comes with a feature where you can generate it’s own screen (dynpro) and basic validations, like, unique index and others.

This screen(s) can be modified with our own logic and validations and even the layout. You can add more detail as you wish. Maybe you could make this maintenance screen making a module pool in SE80 however the point here is that with transaction ‘SE11’ you don’t start from zero. This trait is very important because you can have a lot of features incorporated.

Let’s begin creating a table.

1. Execute transaction ‘SE11’ and name the table whatever you want but remember to use ‘Z’ or ‘Y’ as first letter.

2. Click on ‘Create’ button.

3. Add a description to table (This step is mandatory). Choose ‘A’ option for 'Delivery class' and ‘Display/Maintenance allowed‘ on the 'Delivery and maintenance’ tab. Check image.


4. Select ‘Fields’ tab
  1. Add the following fields:
    1. Add as a first field ‘MANDT’ with type ‘MANDT’.
    2. Add field ‘CODE’ type CHAR08.
    3. Add field ‘NAME’ type STRING.
    4. Add field ERNAM type ERNAM
    5. Add field ‘ERDAT’ type ‘ERDAT’
    6. Add field ‘AENAM’ type ‘AENAM’
    7. Add field ‘LAEDA’ type ‘LAEDA’.


5. Setup the ‘Technical Settings’ where you will set 'Data class' will be 'APP0L' and 'Size Category '0'. Also check 'Log data changes' and 'Write access only with JAVA', these 2 options are optional. Here you'll be asked to save and a package before this screen, I suggest to click on 'Local object' button.



6. Choose the 'Enhancement Category' in Extras menu. Select 'Can be enhanced (character-type or numeric)' option.



7. Activate.


The next thing we should do is to generate the maintenance screen. The option we need here is in ‘Utilities’ menu where you select the ‘Table Maintenance Generator’ option. Here we have some things to configure;


First you need to indicate the authorization group, here it depends on what kind of restriction you would like this program to make, for this example type ‘&NC&’ which means ‘w/o auth. group’. The second thing to set is the function group, personally I would recommend to use the table name, however is up to you which name you set here.



The third thing would be to set the screens of the block ‘Maintenance screens’. In this section you have two options:
  • One step
  • Two step
And the difference is that in the first option you make inserts and modifications in only one dynpro, here SAP sets you a grid to make all the actions on your data. The second option consists in specifying 2 dynpros; one for the grid and the second for issuing the data. The first dynpro shows you the data but in order to make inserts or changes you must make a double click to show you the data.

In our example select the first option (One step) and type '100' in the ‘Overview screen’.


Now, click on 'Create' button or press 'F6'.


The next step is to make use of events. This option is found in the menu ‘Environment’/’Events’.


If you get the following message box click the 'Ok' button.


You will get through the following screen where you must choose what events are going to be raised.

01 Before saving the data in the database
02 After saving the data in the database
03 Before deleting the data displayed
04 After deleting the data displayed
05 Creating a new entry
06 After completely performing the function 'Get original'
07 Before correcting the contents of a selected field
08 After correcting the contents of a selected field
09 After getting the original of an entry
10 After creating the header entries for the change task (E071)
11 After changing a key entry for the change task (E071K)
12 After changing the key entries for the change task (E071K)
13 Exit editing (exit main function module)
14 After lock/unlock in the main function module
15 Before retrieving deleted entries
16 After retrieving deleted entries
17 Do not use. Before print: Event 26
18 After checking whether the data has changed
19 After initializing global variables, field symbols, etc.
20 after input in date subscreen (time-dep. tab./views)
21 Fill hidden fields
22 Go to long text maintenance for other languages
23 Before calling address maintenence screen
24 After restricting an entry (time-dep. tab./views)
25 Individual authorization checks
26 Before creating a list
27 After creation or copying a GUID (not a key field)
28 After entering a date restriction for time-dep. views
AA Instead of the standard data read routine
AB Instead of the standard database change routine
AC Instead of the standard 'Get original' routine
AD Instead of the standard RO field read routine
AE Instead of standard positioning coding
AF Instead of reading texts in other languages

Just for example let’s use the events ‘05’ (Creating new entry) and ‘21’ (Fill hidden fields). Let’s say we want to put the user name and the date when the record is created and modified it.

  1. Type event ‘05’ and on the ‘FORM Routine’ column type ‘on_create’.
  2. Type event ‘21’ and on the ‘FORM Routine’ column type ‘on_change’.


3. Next, click on column editor the button to type the code. You’ll be asked to make a PAI include. Click on button ‘OK’.



4. Paste the following code.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
form on_create.
  ztesttab-ernam = sy-uname.
  ztesttab-erdat = sy-datum.
  ztesttab-aenam = sy-uname.
  ztesttab-laeda = sy-datum.
endform.

form on_change.
  ztesttab-aenam = sy-uname.
  ztesttab-laeda = sy-datum.
endform.

5. Return to the event entries screen and click the save button and go back to the ‘Table Maintenance’ screen and also save the configuration.

If you have the following message box ‘Function group ZTESTTAB cannot be processed’ then go to transaction ‘SE80’ and select the function group ‘ZTESTTAB’ and activate it but first change the ‘Change’ state of the table to ‘Display’. Check the images below.



6. Create entries. Go to 'Utilities'/'Table contents'/'Create Entries' menu.


7. Finally click on button ‘New Entries’, fill the fields ‘+’ and ‘Last Name’ and press enter. And you’ll see that fields ‘Created by’, ‘Created On’, ‘Changed by’ and ‘Changed on’ now have the values we set in the ‘Creating a new entry’ event. The same will occur when you change it with another user.



One last comment is that in order to protect those fields from being modified you must edit the dynpro '100' you set in the 'Utilities'/'Table Maintenance Generator' menu and set the ‘Input‘ column to ‘Not possible’ value in the ‘Special Attributes’ tab on the columns ‘ERNAM’, ‘ERDAT’, ‘AENAM’ and ‘LAEDA’.


Hope it helps. See you on the next.

Please Share it! :)

1 comment :