0% found this document useful (0 votes)
58 views120 pages

Extended Table Maintenance

The document discusses enhancing the table maintenance generator in SAP to automatically record user and timestamp information for data entries. It outlines steps for creating a table, modifying the maintenance screen to hide certain fields, and implementing custom logic to populate user and date fields during record creation and modification. Additionally, it explains how to use events in the table maintenance process to implement custom checks on user-entered data.

Uploaded by

aaamir khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views120 pages

Extended Table Maintenance

The document discusses enhancing the table maintenance generator in SAP to automatically record user and timestamp information for data entries. It outlines steps for creating a table, modifying the maintenance screen to hide certain fields, and implementing custom logic to populate user and date fields during record creation and modification. Additionally, it explains how to use events in the table maintenance process to implement custom checks on user-entered data.

Uploaded by

aaamir khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 120

Enhanced Table Maintenance with Automatic

Change Recording
Posted on: April 10, 2014 | By: Pawan Kesari – 9 Comments
Table maintenance generator is very powerful tool to generate simple data entry
screen for tables. For tables which store configuration data i.e. rarely modified it not
worth spending time creating module pool program for data entry. Table
maintenance generator also gives programmer opportunity to modify standard
behaviour by including additional logic. In this blog I will enhance standard table
maintenance to automatically record created by and created date/time and also last
modified by and last modified date/time.

I have this table which record additional information per plant. Instead of hard-coding
this text we decided to create a table and put these values there in case it requires
change in future.

Create table with ‘Display/Maintenance Allowed’

I have fields ERNAM, ERDAT, ERZET, AENAM, AEDAT, AEZET apart from fields
which will hold actual data.
Create table maintenance from menu option Utilities->Table Maintenance Generator.
Make sure to select ‘one step’ in Maintenance type.

With standard table maintenance you will have all field active and ready for input.
Since we username and date times field to be filled automatically by program logic
we need to hide them from table maintenance screen. To do that, in table
maintenance screen double click on screen number.
It will take you to the flow logic of screen. Add module modify_element in PBO of
screen.

1
2 PROCESS BEFORE OUTPUT.
3 MODULE LISTE_INITIALISIEREN.
4
*--------------------------------------------------------------------*
5 * Hide user name and date/time column
6 *--------------------------------------------------------------------*
7 MODULE modify_element .
8 *--------------------------------------------------------------------*
9
LOOP AT EXTRACT WITH CONTROL
10
TCTRL_ZSD_PLANT_CODE CURSOR NEXTLINE.
11 MODULE LISTE_SHOW_LISTE.
12 ENDLOOP.
13 *
14
Save and double click on modify_element module to create module in new include.

If it comes back saying you are already editing main program then close everything,
open table in display mode and navigate to PBO in display mode and try again with
double click.
In module modify_element copy following code. This code is going through the table
control structure to hide columns.

1 *----------------------------------------------------------------------*
***INCLUDE LZSD_PLANT_CODEO01 .
2
3
4
*----------------------------------------------------------------------*
5 *&---------------------------------------------------------------------*
6 *& Module MODIFY_ELEMENT OUTPUT
7 *&---------------------------------------------------------------------*
8 * text
*----------------------------------------------------------------------*
9 MODULE modify_element OUTPUT.
10
11 LOOP AT <vim_tctrl>-cols INTO vim_tc_cols.
12 IF vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-ERNAM' OR
13 vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-ERDAT' OR
14 vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-ERZET' OR
vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-AENAM' OR
15 vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-AEDAT' OR
16 vim_tc_cols-screen-name = 'ZSD_PLANT_CODE-AEZET' .
17
18 vim_tc_cols-invisible = 1 .
19 MODIFY <vim_tctrl>-cols FROM vim_tc_cols .
ENDIF.
20
ENDLOOP.
21
22 ENDMODULE. " MODIFY_ELEMENT OUTPUT
23
24
Save and activate all objects. Make sure the function group where table
maintenance generator code is active including screen and our new include.

If you run table maintenance now you should not see these field.

Now it’s time to add code which will fill user name, date and time when records are
created or changed.

Table Maintenance Generator offers events that during program processing and we
programmer can add our own code to execute at this point. Very similar to user-
exits. Events in which we are interested in are 05 which executes when new entry is
create and event 01 which triggers before saving the data in database. We are going
to add code at these event which will populate our fields.
Open Table Maintenance Generator in change mode and choose menu option
Environment->Modification->Events.

Click ok on dialog box which say do not change SAP data. On next screen press
‘New Entries’ and add modules at 05 and 01 events.

Click on the editor button next to form routine, create include if required, and put
following code in each of these form routines.

1
*&---------------------------------------------------------------------*
2 *& Form ZSDPLANT_NEW_ENTRY
3 *&---------------------------------------------------------------------*
4 FORM zsdplant_new_entry .
5 zsd_plant_code-ernam = sy-uname .
zsd_plant_code-erdat = sy-datum .
6
zsd_plant_code-erzet = sy-uzeit .
7 ENDFORM. "zsdplant_new_entry
8
1
2
3 *&---------------------------------------------------------------------*
4 *& Form ZSDPLANT_MODIFY_SAVE
5 *&---------------------------------------------------------------------*
6 FORM zsdplant_modify_save .
7
FIELD-SYMBOLS : <fs_field> TYPE ANY .
8
9 LOOP AT total .
10 CHECK <action> EQ aendern.
11 ASSIGN COMPONENT 'AENAM' OF STRUCTURE <vim_total_struc> TO <fs_field> .
12 IF sy-subrc = 0 .
<fs_field> = sy-uname .
13 ENDIF.
14
15 ASSIGN COMPONENT 'AEDAT' OF STRUCTURE <vim_total_struc> TO <fs_field> .
16 IF sy-subrc = 0 .
17 <fs_field> = sy-datum .
18 ENDIF.
19
ASSIGN COMPONENT 'AEZET' OF STRUCTURE <vim_total_struc> TO <fs_field> .
20 IF sy-subrc = 0 .
21 <fs_field> = sy-uzeit .
22 ENDIF.
23
24 READ TABLE extract WITH KEY <vim_xtotal_key>.
IF sy-subrc = 0.
25
extract = total .
26 MODIFY extract INDEX sy-tabix.
27 ENDIF.
28
29 MODIFY total.
30 ENDLOOP.
31 ENDFORM . "ZSDPLANT_MODIFY_SAVE
32
33
Save and Activate all objects. To activate function group you can go to SE80 and
activate from there.

I have created two entries in table maintenance and then changed one. This is how
table contents look like.
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:
a. Add as a first field ‘MANDT’ with type ‘MANDT’.
b. Add field ‘CODE’ type CHAR08.
c. Add field ‘NAME’ type STRING.
d. Add field ERNAM type ERNAM
e. Add field ‘ERDAT’ type ‘ERDAT’
f. Add field ‘AENAM’ type ‘AENAM’
g. 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.
https://alltechtricks9.wordpress.com/2016/06/20/sap-abap-data-dictionary-interview-questions

Use case

A typical business case for the use of additional checks is the implementation of
additional checking logic for data which the user entered. In my case, I’ll use the same
table as last time, which has the company code as a key field. I will implement a check to
verify that the company code that is entered actually exists.

Using table maintenance dialog events

The implementation of custom logic in table maintenance dialogs is done using so-called
events. To get access to these, select Environment > Modification > Events from the menu
while in the table maintenance generator screen.

How to call the events screen


You will get a popup informing you that you’re changing SAP data, which you can safely
ignore. In the list that is opened, you have to select which event you want to use. Each
event is tied to a certain point in the data maintenance process – if you’re familiar with the
hooks programming pattern, that’s exactly what it is.

Your next task will be to pick the correct event for the job you want to do. Since there are
close to 40 different events available, it’s best to use the SAP documentation for extended

table maintenance events, which you can also access via the information button ( ).
For my example, I want to perform a check after data was entered. The correct event for
this is 05. You also need to enter a form routine name. Click Save after you’ve entered your
data (important!) and click on the button in the Editor column afterwards.

Adding a new event implementation

After you have added your include, you’re taken to the ABAP Editor. This is the place
where you can implement your custom check logic. Before I’m going into the details of the
programming itself, let me explain which variables are available to work with the data in
the table.

Interface variables to work with used data

The interface for these hooks is always the same. There’s a set of variables and internal
tables that let you work with the data in the table control. It’s documented for each event
induvidually (such as for event 01), but the generally available variables are the following.

Internal table TOTAL

The internal table TOTAL contains the complete dataset that is held in the table you are
working with. Its structure is a combination of the base table structure and the
structure VIMTBFLAGS. This structure contains fields that indicate the processing status of
the table row.

Field symbols <ACTION> and <ACTION_TEXT>

Via these field symbols, you can access the processing status of the current table row of
table TOTAL, which means they mark if the record was created, updated, or deleted.
These field symbols should only be used for events that are called once for each table
entry, meaning that they are executed in a loop.

If you want to read the processing status of table rows manually, it’s better to use the
field VIM_ACT from the structure VIMTBFLAGS. <ACTION> indicates the processing status
of the table itself. <ACTION_TEXT> is used if your underlying data table has a text table
attached, and indicates the processing status of the text table.
The following constants are available to check the processing status.

 NEUER (value “N”) – new entry


 AENDERN (value “U”) – updated entry
 GELOESCHT (value “D”) – deleted entry
 ORIGINAL (value “”) – unchanged entry
 NEUER_GELOESCHT (value “X”) – new entry, deleted again
 UPDATE_GELOESCHT (value “Y”) – updated entry, deleted again

Internal table EXTRACT

While the table TOTAL contains all of the data that is in the data table, EXTRACT is the data
subset that the user is currently working with. The exact contents of this table depend on
the function the user is currently executing within the SM30 transaction. If he is adding
new lines, the table EXTRACT will contain only the newly entered lines, while the
table TOTAL will contain all old lines plus the new lines. The table EXTRACT has exactly the
same structure as the table TOTAL. More information on table extracts can be found
here: SAP documentation for table extracts.

Field symbols <XACT> and <XACT_TEXT>

These field symbols work exactly in the same way as


the <ACTION> and <ACTION_TEXT> ones, but for the EXTRACT table. They, too, should
only be used with events that are called in a loop.

Field symbol <STATUS>

This field symbol provides access to some general information. Especially important is the
field <STATUS>-UPD_FLAG, which indicates if any data was changed in the table control.

Structure with the name of your table

Especially important for the event 05 (after adding new entries), this structure will hold the
newly-entered data before it is moved to the main table. It can be accessed via the name
of your custom table (in my case, the name is ZMYTABLE) and can be used for data checks.

Some of the available variables for extended table maintenance

These are the most important variables that are available in the extended table
maintenance interface. There are a few more, but they are used only in special cases or
only in a few events. On the next page, I will show you how to use these variables to
implement a simple check on entered data.
Implementation of custom table maintenance logic in ABAP

Remember the include file you were taken to when you clicked the Editor button in the
events screen? That’s where we’ll continue now. I hope you remember the name of the
FORM you provided in the events overview, because this is the routine we have to
implement now. Unfortunately, it’s not generated automatically. It takes no parameters,
so the first step is to add just a simple FORM with no parameters to your include.

*----------------------------------------*
***INCLUDE LZMYTABLE_MAINTF01.
*----------------------------------------*
FORM check_data.

ENDFORM. "check_data

This is what we’re starting out with. Now, it’s important to know what we want to actually
check. Since the event 05 is called in a loop for each new entry made by the user, we have
a rather simple job. We don’t need to check any flags or processing statuses. All we need
to do is take the user-entered data and do a check with it. The complete implementation
of the event looks like this.

Complete event implementation

FORM check_data.

DATA lv_bukrs TYPE bukrs.

* Check the company code that was entered


SELECT SINGLE bukrs
FROM t001
INTO lv_bukrs
WHERE bukrs = zmytable-bukrs.

IF sy-subrc <> 0.
MESSAGE e000
WITH 'This Company Code does not exist.'.
ENDIF.

ENDFORM. "check_data

Notice that here, I’ve used the zmytable structure to read the user data. The reason for
this is the point in time at which event 05 is called. Here, the entered data has not been
transferred to TOTAL or EXTRACT yet, because we have a chance to do checks on the data
first.
Now, whenever the user enters a company code, the FORM routine will check if it is valid.
If it’s not, then an error message will be shown and the user has a chance to correct the
data.

The custom check is working perfectly.

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 form on_create.
2 ztesttab-ernam = sy-uname.
ztesttab-erdat = sy-datum.
3 ztesttab-aenam = sy-uname.
4 ztesttab-laeda = sy-datum.
5 endform.
6
7 form on_change.
8 ztesttab-aenam = sy-uname.
9 ztesttab-laeda = sy-datum.
10 endform.
11

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.

What are the Table Maintenance


Generator Events?
The Table Maintenance Generator is an SAP tool that allows for the
necessary configuration to modify a table (specifically, generate the table
maintenance program), directly from a standard interface. It can be
accessed from the SE11 – ABAP Dictionary Maintenance or SE54 –
Generate table view transactions.
With this tool, it is possible to introduce and modify entries in the table,
establish the Authorization Group, modify the interface, and even the
programs associated with the maintenance of this table; in this case, we
will focus on the Events.
The TMG Events allow us to associate a new FORM routine with a
specific event that can occur during the maintenance of a table. This
routine will effectively be a new ABAP program that will execute at
the time indicated by the event. Therefore, it is possible to include in
this ABAP code any behavior desired. SAP provides a wide variety of
events, several examples of which can be seen in the image above.

How to implement a custom


restriction?
Using the Events discussed earlier, our goal is to implement a custom
restriction in the modification of a custom table, ensuring that only users
authorized for a particular organizational value can modify the rows
corresponding to that organizational value.
We start by creating and configuring a custom table using
the SE11 transaction. Our table is enabled for modification and consists of
4 fields:


 Client (MANDT): necessary to make the table client-specific.
 Company Code (Z_BUKRS): the organizational value with which
we will apply the restriction.
 Sales Organization (Z_VKORG): a second organizational value.
 Approver (Z_APPROVER): an approver user according to the
combination of previous organizational values.
In the TMG, we have assigned an authorization group for our table and a
function group for the maintenance program. In addition, we have
selected the one-step maintenance type and obtained the screen number
1 using Find Scr. Number(s):
At this point, our table is ready to be modified using the TMG itself.

In this example, we went a bit further and decided to create a custom


transaction (parameter transaction of the SM30 – Call View
Maintenance) that facilitates the modification of this table. The new
transaction was created using the SE93 – Maintain Transaction Codes
transaction:
To configure the new routine we want to execute, we access the Events
section of the TMG and add a new entry:
We select the event we want to use, give a name to the routine, and click
the ‘Editor’ button.
We select the option to add a new Include, which will open an ABAP editor
where we can enter the code of our routine according to our needs.
According to our example, we were interested in adding a restriction with
the organizational value Company Code (Z_BUKRS) when the user tried
to modify the table. For this, we used a very simple code and event 01, as
it allows us to check new entries, modifications, and deletions.

Seleccionamos la opción de añadir un nuevo Include, lo cual nos abrirá un


editor ABAP donde podremos introducir el código de nuestra rutina según
nuestras necesidades. Según nuestro ejemplo, nos interesaba añadir una
restricción con el valor organizativo Company Code (Z_BUKRS) cuando
el usuario intentara modificar la tabla. Para ello hemos utilizado un código
muy simple y el evento 01, ya que nos permite comprobar nuevas
entradas, modificaciones y eliminaciones.
In this code, we decided to implement an authorization check with the
object F_BKPF_BUK and the organizational value Company
Code (Z_BUKRS in our table, BUKRS in the standard), checking the
activity ’02’ (modification). The authorization object should always be
used according to the organizational value being checked, and a
new custom object could even be created to avoid expanding
authorizations in other critical standard transactions.

Conclusion
The TMG routines and events are a very versatile tool that allows
enhancing the functionality of tables in general. Many companies today
use SAP’s custom tables to expand and adapt the standard functionality to
their business processes; using this tool, it is possible to reduce the
necessary developments to achieve the goal and improve functionality
according to the more specific needs of each company. We could be
including additional validations to the information included in the table, or
we could modify the way it is displayed, to give some examples.

In our specific case, we have managed to introduce an authorization


check with an organizational value, something that the standard does not
contemplate for tables and that is often a valuable addition for the
company, which requires its structure to be properly segregated.
he problem with filtering in extended table maintenance

Generated table maintenance dialogs have some filtering capabilities by default. It is


possible to restrict the displayed values via the menu entry Selection > By Contents, but
the interface is quite complicated and cumbersome.

The standard filtering in extended table maintenance is not very usable.

Wouldn’t it be much nicer if we could just have a selection screen to restrict the displayed
values, just like we know from SE16 and any report transaction? Well, we can! SAP
provides the event AA: Instead of the Standard Data Read Routine to do just that. Let’s
walk through the necessary steps to create a custom selection screen for
the SM30 maintenance functionality.

How to build a custom selection screen for SM30

The first step is to add the hook AA to the events overview. If you’ve read my last post
about extended table maintenance, you already know how to do this. Open your table and
go to the table maintenance generator. Then select Environment > Modification > Events to
open the events overview. Add the event AA, enter a FORM name and save.

Adding the event for custom selection screens

Now go to the editor. The first thing we need is, of course, the selection screen that we’re
going to show. In my example, I’m defining a simple screen with just the company code as
a parameter to restrict the values shown. In code, it looks like this.

* Define a custom selection screen.


SELECTION-SCREEN: BEGIN OF SCREEN 10.
PARAMETERS p_bukrs TYPE bukrs.
SELECTION-SCREEN: END OF SCREEN 10.
Next, we need to define the FORM routine that is called by the event AA.

* This form is called by the event AA


FORM custom_selscreen.

Since we’re implementing our own data reading routine, we would now have to read the
data in table ZMYTABLE from the database. We could use OpenSQL for that, but there’s a
better way. There are already pre-defined FORM routines that do the data reading job for
us. They are:

 TABLE_GET_DATA if the underlying object is a table


 GET_DATA_<viewname> if the underlying object is a view.

In this case I’m using TABLE_GET_DATA since the maintenance generator is based directly
on the data table.

* Read all data into TOTAL first


PERFORM table_get_data.

After executing this call, all the data from the database is in the internal table TOTAL. After
that is done, we can show our selection screen. Here it’s done as a modal popup by using
the addition STARTING AT, but we could also omit that and display it as full-screen. After
the popup has been executed, we have the filter value in the parameter P_BUKRS. I’ve
added a statement that doesn’t apply the filter when the value is empty, but that’s
optional.

* Call the custom selscreen as a popup


CALL SCREEN 10 STARTING AT 20 10.

* If the user didn't enter anything, don't filter


CHECK p_bukrs IS NOT INITIAL.

Now, all we need to do is loop over the data in the table TOTAL, apply the filter condition,
and remove the record from the table if it doesn’t match. In order to have structured
access to the table, we need to define a structured variable first that the data is moved
into. Remember: the structure of the TOTAL table equals the base table plus the
structure VIMTBFLAGS.

* Define a structured variable to read data


DATA BEGIN OF ls_total.
INCLUDE TYPE zmytable.
INCLUDE TYPE vimtbflags.
DATA END OF ls_total.

* Now apply the filter


LOOP AT total.

* Move data so it is accessible via structure


ls_total = total.
* Check if the given BUKRS is contained
IF NOT ls_total-bukrs = p_bukrs.
* Filter row
DELETE total.
ENDIF.

ENDLOOP.

And we’re done! Check out the result of our programming by calling SM30 with your base
table as parameter. The popup will look like this.

SM30 custom selection screen

The resulting table view will only contain entries that adhere to the filtering conditions.
That concludes today’s post.

Full ABAP Source Code for Custom Selection Screen

This is the entire FORM routine that is needed to implement a custom selection screen
for SM30 with the event AA.

* Define a custom selection screen.


SELECTION-SCREEN BEGIN OF SCREEN 10.
PARAMETERS p_bukrs TYPE bukrs.
SELECTION-SCREEN END OF SCREEN 10.

* This form is called to restrict the selection


FORM custom_selscreen.

* Read all data into TOTAL first


PERFORM table_get_data.

* Call the custom selscreen as a popup


CALL SCREEN 10 STARTING AT 20 10.

* If the user didn't enter anything, don't filter


CHECK p_bukrs IS NOT INITIAL.

* Define a structured variable to read data


DATA BEGIN OF ls_total.
INCLUDE TYPE zmytable.
INCLUDE TYPE vimtbflags.
DATA END OF ls_total.

* Now apply the filter


LOOP AT total.
* Move data so it is accessible via structure
ls_total = total.

* Check if the given BUKRS is contained


IF NOT ls_total-bukrs = p_bukrs.
* Filter rows
DELETE total.
ENDIF.

ENDLOOP.

ENDFORM.

Custom Validation on Table Maintenance Generator (SM30)


September 13, 2010marcpontyLeave a commentGo to comments

To add a validation to prevent invalid data input while using table maintenance transaction (SM30)
is a common situation. However, it may be tricky at first if we don’t know the trick behind. So,
below is the step to add the custom validation.

In this example I will use table with definition as below:

For example, I want to add validation on CURR field, which should not be empty, and must have
value either ‘USD’ or ‘IDR’.

1. Create Action on Appropriate Event in Table Maintenance Generator


I assume that the table maintenance generator is already created. Now, we have to define where
the validation will take place. Go to Environment –> Modification –> Events

There, we could register subroutine call to an event. For list of event, just press F4 on the left most
column, which will bring up a list of event code and its event description. For our case, we want to
do validation before data is saved, so we will pick the event ’01’ – Before saving data in the
database.

After that, we have to define a name of subroutine, for example ‘F_VALIDATE_ENTRY’. Click on the
‘editor’ button, and a popup asking where to put the new subroutine will come. Create new include.
2. Add the validation code
In the new include, add below code:

form f_validate_entry.

DATA lwa_row TYPE ztesttable.

LOOP AT total.
clear lwa_row.
if <vim_total_struc> is ASSIGNED.
MOVE-CORRESPONDING <vim_total_struc> to lwa_row.
endif.

if <action> NE 'D' and <action> is NOT INITIAL and <action> NE 'X'.


if lwa_row-curr NE 'USD' and lwa_row-curr NE 'IDR'.
MESSAGE 'Currency must be USD or IDR' TYPE 'S' DISPLAY LIKE 'E'.
vim_abort_saving = 'X'.
exit.
endif.
endif.
ENDLOOP.
ENDFORM.
There are some global variable used in this code, which make it
tricky if we don’t know what it contains. Variable ‘total’ will contain all entries in the table: new
entries, newly deleted entries, and existing entries, along with the action performed on that entry
(Insert/Update/Delete/None). However, this variable come with only one field struct, so we have to
do string offset, which is not really elegant way. Fortunately, in each loop of ‘total’, it will
automatically assign itself to <vim_total_struc> which have the same struct with the table. From
there, we could validate the entry. There’s also <action> variable, which also automatically
assigned during loop, that show the action performed for that entries (value list as below) The
variable ‘vim_abort_saving’ will be flag to abort the save.
List of value for action
N = New entry
U = Updated entry
D = Deleted entry
X = Deleted new entry

ZEVOLVING
SEARCH

 Welcome !
Welcome to Zevolving - place where you find one of the best articles, tutorials for ABAP

 Recent Posts

Write Green Programs


It’s not about setting the background green of your code editor or setting up all the code lines t...
Display ALV Grid on List Generated by WRITE
Ever wondered how to generate the ALV Grid on the list generated by WRITE statement. Lets see today ...

Why NOT to have a wrapper around Exception (RAISE) ?


Class based exception are more powerful compared to the "legacy" exceptions. But you don't want to c...

o More Post →
 OO Concepts
o Abstract class vs Interface
o Multiple Inheritance
o When to use Local Class
o Class Based Exceptions
o Constructors
o More »
 Design Patterns
o Singleton
o Model View Controller
o Singleton Factory
o Decorator
o Observer
o More »
 Performance
o FieldSymobls vs WA
o Parallel Cursor
o ITAB Copy
o FOR ALL Entries
o Between breakpoints
o More »
 Concepts
o New TYPE Category BOXED
o Pragmas replacing Pseudo Comments
o Method Chaining
o ITAB Secondary Keys
o More »
 Tutorials
o SALV Table Display
o SALV HS Table Display
o Classic
o Generic Object Services (GOS)
o Dynamic ITAB
o Case Studies

SEARCH Search in Zevolvi

o Or Explore Archives
 Code Snippets

 Home
 Table Maintenance
 Capture Changed content after the FM VIEW_MAINTENANCE_CALL

Capture Changed content after


the FM
VIEW_MAINTENANCE_CALL
By Naimesh Patel | September 11, 2008 | Table Maintenance | 10,017 | 1

The requirement is to capture the changed contents – updated, deleted or inserted –


after the table maintenance call using the FM VIEW_MAINTENANCE_CALL.

The simple solution to handle this requirement is:


1. Get all the data from the database table for which we will call the FM
VIEW_MAINTENANCE_CALL.
2. Call FM VIEW_MAINTENANCE_CALL
3. Get all the data from the database table again in separate internal table Compare the
contents of the data using some utility.

This kind of generic solution would be possible, but the performance of the report would
be slow. I thought of having something which can tell us directly just after the FM call,
which line was changed: update or deleted or inserted. Suddenly, I thought of
implementing the Event and use the same data which are there in the global tables of
the Maintenance Function.

Based on the thought, new steps to achieve this solution would be:
1. Implement Event in the Maintenance. Export the Main internal table to ABAP memory,
which can be accessed later from the calling program.
2. Call the FM VIEW_MAINTENANCE_CALL
3. Import the data from the ABAP memory
In this later approach, we can get the data instantly from the memory. Since we will have
the indicators (ACTION field in the table) which will help us to identify the type of change
made to table entries.

You can find more information on the Events of the Table Maintenance at: Extended
Table Maintenance Events

To implement the solution, I have used the Event 01 – Before Saving the data into
Database. We need to create the subroutine which can be called when the event gets
hit. When we create a subroutine, it will be created in the same Function group in which
we have created the Table mainteinance. Hence, it will provide us the access to all the
global tabbles. From all of these tables, we will export the internal table TOTAL to the
memory.

TOTAL table contains the fields: ACTION and MARK.

Content of the ACTION field would help us to indetify the type of change:
D – Delete
U – Update
N – New Entry

Code Snippet to Export data in Event 01

*&------------------------------------------------------------------
---*
*& Form EXPORT_TOTAL_TABLE
*&------------------------------------------------------------------
---*
* This form is called in the Event 01 of the table maintain
ence
* events
*-------------------------------------------------------------------
---*
FORM EXPORT_TOTAL_TABLE.
*
* Table of the same structure of the TOTAL which can be exported
DATA: BEGIN OF ITAB OCCURS 0.
INCLUDE STRUCTURE ZTEST_NP_EVENT.
INCLUDE STRUCTURE VIMFLAGTAB.
DATA: END OF ITAB.
*
* Moving data to ITAB from total
ITAB[] = TOTAL[].
*
* Clearing memory
FREE MEMORY ID 'ZTEST_EVENT'.
*
* Exporting data to Memory
EXPORT ITAB = ITAB TO MEMORY ID 'ZTEST_EVENT'.
*
ENDFORM. "EXPORT_TOTAL_TABLE
Code Snippet of the Report

*&------------------------------------------------------------------
---*
*& Report ZTEST_NP_EVENT
*&------------------------------------------------------------------
---*
*& This Report will start the Table Maintainence and after saving
the
*& data in the table maintinence, it will generate a list which
will
*& what data has been newly added, updated or deleted
*&------------------------------------------------------------------
---*
REPORT ZTEST_NP_EVENT.
*
* Table with the Same structure of the table which is exported.
DATA: BEGIN OF ITAB OCCURS 0.
INCLUDE STRUCTURE ZTEST_NP_EVENT.
INCLUDE STRUCTURE VIMFLAGTAB.
DATA: END OF ITAB.
*
* Output table
TYPES: BEGIN OF TY_OUT.
INCLUDE TYPE ZTEST_NP_EVENT.
INCLUDE TYPE VIMFLAGTAB.
TYPES: END OF TY_OUT.
*
DATA: IT_OUTPUT TYPE STANDARD TABLE OF TY_OUT.
*
* Output ALV reference
DATA: O_ALV TYPE REF TO CL_SALV_TABLE.
*
*
START-OF-SELECTION.
* Start the Table maintainence
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
ACTION = 'U'
VIEW_NAME = 'ZTEST_NP_EVENT'
EXCEPTIONS
CLIENT_REFERENCE = 1
FOREIGN_LOCK = 2
INVALID_ACTION = 3
NO_CLIENTINDEPENDENT_AUTH = 4
NO_DATABASE_FUNCTION = 5
NO_EDITOR_FUNCTION = 6
NO_SHOW_AUTH = 7
NO_TVDIR_ENTRY = 8
NO_UPD_AUTH = 9
ONLY_SHOW_ALLOWED = 10
SYSTEM_FAILURE = 11
UNKNOWN_FIELD_IN_DBA_SELLIST = 12
VIEW_NOT_FOUND = 13
MAINTENANCE_PROHIBITED = 14
OTHERS = 15.
IF SY-SUBRC <> 0.
ENDIF.
*
* Importing the memory from the Memory ID
* Table has been exported in the Event 01 of the Table
* maintenance events.
IMPORT ITAB TO ITAB FROM MEMORY ID 'ZTEST_EVENT'.
*
* Clear the memory id
FREE MEMORY ID 'ZTEST_EVENT'.
*
* Moving data to output
IT_OUTPUT = ITAB[].
DELETE IT_OUTPUT WHERE ACTION IS INITIAL.
*
* New ALV Instance
TRY.
CL_SALV_TABLE=>FACTORY(
EXPORTING
LIST_DISPLAY = ABAP_FALSE
IMPORTING
R_SALV_TABLE = O_ALV
CHANGING
T_TABLE = IT_OUTPUT ).
CATCH CX_SALV_MSG. "#EC NO_HANDL
ER
ENDTRY.
*
* Display the ALV
O_ALV->DISPLAY( ).

VIEW_MAINTENANCE_CALL

ABAP Objects: Overriding (Redefinition)


Dynamic Background Colors in Smartforms
Adjusting Table Maintenance Generator without re-
generating it, when Table Structure changes

former_member207874

Explorer
Options

2016 Feb 16 3:02 AM


7 Kudos

46,308

 SAP Managed Tags:

 ABAP Development

Purpose:

Suppose we have a table in the dictionary and it has a maintenance


generator which contains many events and lot of features (display a field
as drop down, check box or field header text) incorporated manually in
the function group of the maintenance generator. At this moment if the
table structures changes and it requires one extra field to be appended
and maintenance generator needs to be there as it was previously with
the amended of the new field then changing the table structure and re-
generating the maintenance generator will not provide the solution. If we
re-generate the maintenance generator after changing the table structure
then it will incorporate the new field but all the events and other features
will be deleted from the maintenance generator. So same features and
events needs to be coded again.

This can be avoided by adjusting the maintenance generator manually


and not re-generating it using the following steps:

Step1:

Create a table ZTEST_EMP using tcode SE11 with a maintenance


generator.

Now Utilities->Table Maintenance Generator and create the Maintenance


Generator:
Now from SM30 tcode we can create new entries to the table:
Display table ZTEST_EMP:

Step2:

Change the table structure with the addition of new field ‘EMP_AGE’ and
activate it:
Now if we display the table it will also display the new field with initial
value:

But the table maintenance generator will not contain the new field:

Step3:
Now we will adjust the Table Maintenance Generator so that this
additional field is added and other functionalities in the Table Maintenance
Generator remains intact.

Get the Function Group from the Table Maintenance Generator Display:

Go to tcode SE80 and open the function group and select the screen
number and click on Layout from toolbar.
This Design Screen will appear:

Add the extra column (input/output field) manually:


Name the new column as the same updated in the table structure.

Add the column header text as follows: Name the header text field as-
*ZTEST_EMP-EMP_AGE
Save and Back. Go to Flow Logic tab and add the following line indicated:
Go to Element List->General Tab: Tick the red marked field as dictionary
field.

Save it. Following pop up will be prompted. (Select your choice


accordingly and click ok)
Then the following popup will come. (Click as per your requirement. Here
we choose yes as we want new table field to be in Table Maintenance
Generator)

Finally Activate the Table Maintenance Generator. If activated successfully


then go to tcode SM30 to maintain data.

We will change Employee age as 30 and save the record. In the table
display we can see that age is updated.
Internal Table "TOTAL" (View
Cluster)
Definition

The table "TOTAL" contains all data which are read, changed, and created in the view cluster maintenance.

The data is sorted in ascending order.

You can access the table "TOTAL" for a view cluster subobject via the field symbol <VCL_TOTAL>, if the

routine VCL_SET_TABLE_ACCESS_FOR_OBJ has been called previously for this subobject.

Structure

Structure

For views or tables without a text table, The internal table has the structure of the view or table, and also a

processing and selection flag.

Example

INCLUDE STRUCTURE <view name> or <table name>

INCLUDE STRUCTURE VIMFLAGTAB

For tables with a text table, connected via the foreign key relationship TEXT, the structure of the table

consists of the structure of the entity table, text table, and also two processing flags and a selection flag.

Example

INCLUDE STRUCTURE <table name>

INCLUDE STRUCTURE <text table name>

INCLDUE STRUCTURE VIMTBFLAGS

Note

The structure of the table "TOTAL" is not transparent and the table has no header line. To access the table

fields, it isadvisable to define a record with the appropriate structure. The fields can be accessed via the
record after assigning an "TOTAL" table entry to the record, e.g. in a loop over the table or in a READ
TABLE statement.

Processing and Selection Flags

Each record in the table "TOTAL" contains processing and selection flags . They can be found in a loop for

each record in the table.

Changing "TOTAL"

If the table "TOTAL" is to be changed, for example, to create, delete, or change hidden entries, the form

routine EDIT_VIEW_ENTRY must be called as external perform in the function group containing the

generated maintenance dialog modules for the subobject. The routine changes the entry in the data tables,

sets the processing flag and updates the view maintenance internal status information for the subobject.

EDIT_VIEW_ENTRY routine interface

Specify parameters:

Parameter Explanation

EXTRACT Data table 'EXTRACT' of subobject

TOTAL Data table 'TOTAL' of subobject

HEADER Subobject header entry management table

NAMTAB Subobject field information management table

SELLIST Selection conditions against which the validity of the entry to be created is checked

ENTRY Subobject entry to be changed

ACTION Type of change to be made. Possible values:

'DEL' : ENTRY is to be deleted

'UPD' : ENTRY is to be created if no entry with that key exists, or to be changed

'UDL' : ENTRY is to be retrieved from deletion

The routine returns the return code SY-SUBRC = 0 if the action was successful.

Delete an entry:
data: error_flag(1) type c,
Teilobjekt_wa like 'Teilobjektname'.
* Zugriff auf Daten und Verwaltungstabellen für Teilobjekt bereitstellen
vcl_set_table_access_for_obj using 'Teilobjektname'
changing error_flag.
Teilobjekt_wa =....

perform edit_view_entry(saplfugr)
* saplfugr ist das Rahmenprogramm, der zur Generierung
* benutzten Funktionsgruppe
tables <vcl_extract> <vcl_total>
<vcl_header> <vcl_namtab>
<vcl_dpl_sellist>
using Teilobjekt_wa 'DEL'.

Note

Create a new entry:

The entry to be created is checked against the conditions in the parameter SELLIST. If the subobject

contains subset fields, an appropriate list of conditions must be passed for this entry.

We generally use TMG to create, change and delete entries from the DB
table. By following the steps mentioned in this post, you can change the
look and feel of the screen as per your requirement.

Note: This is only applicable to Custom Tables.

Step 1: Select a Custom Database Table or create a new table based on


your requirements.

In my case, I’m using the DB Table with the structure illustrated below.
Step 2: Create TMG for the Table.
I’ve used ‘One Step’ as a maintenance type and Overview Screen ‘110’.

Step 3: Double click on screen number, it will navigate to Module Pool.


You can now find the ‘Layout’ and ‘Attributes’ option on the screen as
illustrated above.

Step 4: Click on the ‘Layout’ option, it will navigate to the screen painter.
If there are several fields, we need to scroll the page to view the fields.

But we can avoid the above case by changing the value in the Attributes
section.
Step 5: Proceed to attributes section in step 3.

In the Attributes section, you can find the Editing field in the Other
Attributes section.

Step 6: Change it as per the requirement and make use of excess space
on the screen.

Here, I’ve changed it from 80 to 100 so that I can view all the fields at a
time without the need to scroll.

Resultant layout would be as illustrated below.


If you would like to change the position of the field, you can do so by
following the next step.

Step 7:
Double click on the tab below the field that you would like to move and
change the value of the column field.

For Example: In my case, the layout would be as illustrated below.


I would like to change the position of the Password field to the last i.e.
5th position.

So, I need to change the value in the column field.


After changing the value, the layout would be as illustrated below.
In the above image you can see that the length of the field ‘Last
Name’ is less.

If you would like to change the visible length of the field, you can do so by
changing the Vis. Length field.
Step 8: Double click on the field which you would like to modify the
properties.

In my case, I’ve changed the visible length of the Last Name field to 20.
Now, the screen layout would be as below.

You can also change label of field without changing the data-element or
domain.
You can do so by changing the Text field.

Step 9: Double click on the field that you would like to change the
properties.

In my case, I’ve changed it from Name to First Name.


So, we’ve seen how to

1. change the label,

2. change the column position and

3. change the visible length of the field.

The final output in TMG would be as below.


The operations mentioned in this post will be applicable only in TMG, it will
not reflect in SE16.

Thanks for reading.

Hope this post would be helpful.

 abap

Table Maintenance
Maintaining Custom subroutine in view V_TVIMF for extracting
data while creating table entries thru transaction SM30.
Generally for inserting new records into custom table thru
transaction SM30, we need to enter all the values manually and
save the record.
When certain data for the key fields needs to be populated
automatically while creating entries, the steps involved are:

1. Maintaining the subroutine in view V_TVIMF for a particular


custom table.
2. Logic for extracting relevant data for the fields entered,
when user press enter button.

Steps Involved
As an example, let's create a Custom table with fields related to
customer master using transaction SE11 and maintenance of
that table by transaction SM30.
In this example we will consider 3 fields.
KUNNR – Customer number
NAME1 – Customer name
LAND1 – Country key

1 .Create Table ZCUST with these fields

2. Generate table maintenance for this table.


3 For maintaining data in this table we need to do thru
transaction SM30.
Creating routine for Custom table ZCUST.
Logic to extract customer name and country key for the
customer needs to be written in the subroutine maintained in
view V_TVIMF.

4. Go to SE11 – Enter View V_TVIMF .


Utilities – Contents – Enter (table name) (Table name for which
subroutine to be maintained) In this case table ZCUST. Press
enter.
Following screen appears – Press New entries.

5. We need to maintain two fields in this screen


1.Table maintenance dialog event
2.FORM Routine name
Table maintenance dialog event
Key for a pre-defined time within extended table maintenance.
The key is defined in the domain and is displayed with the
possible entries
(F4). Use of this field :
If this pre-defined time is reached in extended table
maintenance, the FORM routine specified for the current view
and for this time is processed. This is useful, for example, for
performing consistency checks before saving or specific actions
when creating new entries.
The view, time and FORM routine are set in table TVIMF, which
must currently be maintained directly using transaction SM30
(view name: V_TVIMF). Key for a pre-defined time within
extended table maintenance. The key is defined in the domain
and is displayed with the possible entries (F4).
FORM Routine
Name of FORM routine (extended table maintenance)
Name of the FORM routine, which is processed at particular pre-
defined times during extended table maintenance.
Dependencies
The FORM routine must belong to the function group, to which
the maintenance modules for the view are assigned.

6. Enter Table maintenance dialog event = ’05’ (Here we are


writing logic when new entries are created) Depending upon
the requirement other events can be used, which are available
in F4 values with relevant description.

7. Enter Subroutine name as GET_CUSTOMER_DATA as shown


in the screen and press enter. Select the line and press icon
available in the editor field.

8. Enter new include LZCUSTF01 and press enter, an entry with


this include will get inserted in the function group main
program.
9. Write following code in the routine. Activate program and go
to transaction SM30 for maintaining records for customer.
Code to be written in the subroutine
*---------------------------------------------------------*
***INCLUDE LZCUSTF01 .
*---------------------------------------------------------*
FORM GET_CUSTOMER_DATA.
* Get customer name
select single name1 land1
into (zcust-name1,zcust-land1)
from kna1
where kunnr = zcust-kunnr.
ENDFORM. "GET_CUSTOMER_DATA

Output Result
10. Now, if you enter customer number in transaction SM30 and
press enter it will extract Customer name and Country key from
the custom routine (GET_CUSTOMER_DATA) maintained in view
V_TVIMF and displays on the screen.

Update and Create Events in Table Maintenance Generator

Former Member
Options

2019 Sep 26 8:54 AM


41 Kudos

196,610

 SAP Managed Tags:

 ABAP Development

INTRODUCTION:

I got the requirement to capture the Created by Created on


and Updated by Updated on logs for the custom table using
Table Maintenance Generator events.

Here is the step by step process to capture the table change


logs.
Step 1:

Create a custom table.

Step 2:

Click on utilities, go to table maintenance generator.


Step 3:

Enter the details of the function group, propose screen


numbers and click on save, we will provide the package
name.

There are two different maintenance screen types

1. one step and


2. Two step

one step

 In one step we will have only overview screen.

 Will able to see and maintain only through the overview


screen.

Two step

 We will have two screens. overview screen and


Single/Detail screen.

 overview screen will contain key fields and Single screen


will contain all the other fields.
Step 4:

For TMG events, In menu Click on Environment--


>Modifications-->Events
Following screen will be displayed. From the below list i have
used Update and Create Events.
Update Event

Select the Update event and press enter, the following


screen will appear.
Source Code

--------------------------------------------------------------
--------
***INCLUDE LZTEMP_DTLSF01.
--------------------------------------------------------------
--------
FORM update.
** -- Data Declarations
DATA: lv_timestamp TYPE tzonref-tstamps.
*-- Time stamp conversion
CALL FUNCTION 'ABI_TIMESTAMP_CONVERT_INTO'
EXPORTING
iv_date = sy-datum
iv_time = sy-uzeit
IMPORTING
ev_timestamp = lv_timestamp
EXCEPTIONS
conversion_error = 1
OTHERS = 2.
FIELD-SYMBOLS: <fs_field> TYPE any .
LOOP AT total.
CHECK <action> EQ aendern.
** -- Updated By
ASSIGN COMPONENT 'UPDTD_BY' OF STRUCTURE <vim_total_struc> TO
<fs_field>.
IF sy-subrc EQ 0.
<fs_field> = sy-uname.
ENDIF.
** -- Updated On
ASSIGN COMPONENT 'UPDTD_ON' OF STRUCTURE <vim_total_struc> TO
<fs_field>.
IF sy-subrc EQ 0.
<fs_field> = lv_timestamp.
ENDIF.
READ TABLE extract WITH KEY <vim_xtotal_key>.
IF sy-subrc EQ 0.
extract = total.
MODIFY extract INDEX sy-tabix.
ENDIF.
IF total IS NOT INITIAL.
MODIFY total.
ENDIF.
ENDLOOP.
ENDFORM.

Once the code is completed then we need check and activate


the include.Here we need to activate the below two objects.
Create Event

Select the Create event and press enter, the following screen
will appear.

Same process we have to go for the Create event.


Source Code

--------------------------------------------------------------
--------
***INCLUDE LZTEMP_DTLSF02.
--------------------------------------------------------------
--------
FORM create.
** -- Data Declarations
DATA: lv_timestamp TYPE tzonref-tstamps.
*-- Time stamp conversion
CALL FUNCTION 'ABI_TIMESTAMP_CONVERT_INTO'
EXPORTING
iv_date = sy-datum
iv_time = sy-uzeit
IMPORTING
ev_timestamp = lv_timestamp
EXCEPTIONS
conversion_error = 1
OTHERS = 2.
** -- Created On & Created By
ztemp_dtls-crtd_by = sy-uname.
ztemp_dtls-crtd_on = lv_timestamp.
ENDFORM.

Check and activate it.


Step 5:

Now To test the Update and Create events Go to Table


maintenance generator ( SM30 Tcode) and Click on maintain
button as per shown below.
Next, Create the data by clicking on new entries and click on
save then we will able to see the Create logs.
Update the existing data then click on save, then we will able
to see the Update logs.
Conclusion:

By following the above steps,we are able to see the table


create and update logs for a custom table, which contains the
fields "Date on which record was created" and "Name of the
person who created the object".
Adding F4 help in table maintainace
*----------------------------------------------------------------------*
***INCLUDE LZHR_DHARMOFFF01.
*----------------------------------------------------------------------*

FORM get_org.

TYPES:
BEGIN OF ty_t527x,
orgeh TYPE orgeh,
orgtx TYPE orgtx,
END OF ty_t527x.

DATA:
lwa_t527x TYPE ty_t527x,
lt_t527x TYPE TABLE OF ty_t527x,
lt_retval TYPE TABLE OF ddshretval,
lwa_retval TYPE ddshretval,
lt_fields TYPE TABLE OF dynpread,
lwa_fields LIKE LINE OF lt_fields.

DATA:
lv_line TYPE string.

**Get Org Unit

SELECT SINGLE orgeh


orgtx FROM t527x INTO lwa_t527x WHERE sprsl = sy-langu AND
orgeh = zhr_dharmoff-orggh.

zhr_dharmoff-orgex = lwa_t527x-orgtx.
ENDFORM. "get_org
*---------------------------------------------------------------------*
* view related PAI modules
* generation date: 12.02.2015 at 15:21:28 by user ABAP05
* view maintenance generator version: #001407#
*---------------------------------------------------------------------*

INCLUDE lsvimitx . "base table related PAI modules

*----------------------------------------------------------------------*
* MODULE get_org
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE get_org.

TYPES:
BEGIN OF ty_t527x,
orgeh TYPE orgeh,
orgtx TYPE orgtx,
END OF ty_t527x.

DATA:
lwa_t527x TYPE ty_t527x,
lt_t527x TYPE TABLE OF ty_t527x,
lt_retval TYPE TABLE OF ddshretval,
lwa_retval TYPE ddshretval,
lt_fields TYPE TABLE OF dynpread,
lwa_fields LIKE LINE OF lt_fields.

data:
lv_line TYPE string.

**Get Org Unit

SELECT orgeh orgtx FROM t527x INTO TABLE lt_t527x WHERE sprsl = sy-langu.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'


EXPORTING
retfield = 'ORGEH'
value_org = 'S'
dynprofield = 'ORGEH'
TABLES
value_tab = lt_t527x
return_tab = lt_retval
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.

READ TABLE lt_retval INTO lwa_retval INDEX 1.

get CURSOR LINE lv_line.

lwa_fields-fieldname = 'ZHR_DHARMOFF-ORGGH'.
lwa_fields-fieldvalue = lwa_retval-fieldval.
lwa_fields-STEPL = lv_line.
APPEND lwa_fields TO lt_fields.
CLEAR: lwa_fields.

READ TABLE lt_t527x INTO lwa_t527x WITH KEY orgeh = lwa_retval-fieldval.


lwa_fields-fieldname = 'ZHR_DHARMOFF-ORGEX'.
lwa_fields-fieldvalue = lwa_t527x-orgtx.
lwa_fields-STEPL = lv_line.
APPEND lwa_fields TO lt_fields.
CLEAR: lwa_fields.

IF lt_fields IS NOT INITIAL.

CALL FUNCTION 'DYNP_VALUES_UPDATE'


EXPORTING
dyname = sy-cprog
dynumb = sy-dynnr
TABLES
dynpfields = lt_fields
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request =5
no_fielddescription = 6
undefind_error =7
OTHERS = 8.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.

ENDMODULE. "get_org
*----------------------------------------------------------------------*
***INCLUDE LZHR_MAS_TIDI01.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module GET_PERSA INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE get_persa INPUT.
TYPES:
BEGIN OF ty_T500P,
PERSA TYPE persa,
name1 TYPE PBTXT,
END OF ty_T500P.

DATA:
lwa_T500P TYPE ty_T500P,
lt_T500P TYPE TABLE OF ty_T500P,
lt_retval TYPE TABLE OF ddshretval,
lwa_retval TYPE ddshretval,
lt_fields TYPE TABLE OF dynpread,
lwa_fields LIKE LINE OF lt_fields.
data:
lv_line TYPE string.

**Get employee subgroup


*break abap07.
SELECT PERSA NAME1 FROM T500P INTO TABLE lt_T500P. " WHERE sprsl = sy-langu.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'


EXPORTING
retfield = 'PERSA'
value_org = 'S'
dynprofield = 'PERSA'
TABLES
value_tab = lt_T500P
return_tab = lt_retval
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.

READ TABLE lt_retval INTO lwa_retval INDEX 1.

get CURSOR LINE lv_line.

lwa_fields-fieldname = 'ZHR_MAS_TID-PERSA'.
lwa_fields-fieldvalue = lwa_retval-fieldval.
lwa_fields-STEPL = lv_line.
APPEND lwa_fields TO lt_fields.
CLEAR: lwa_fields.

READ TABLE lt_T500P INTO lwa_T500P WITH KEY PERSA = lwa_retval-fieldval.


lwa_fields-fieldname = 'ZHR_MAS_TID-NAME1'.
lwa_fields-fieldvalue = lwa_T500P-NAME1.
lwa_fields-STEPL = lv_line.
APPEND lwa_fields TO lt_fields.
CLEAR: lwa_fields.
IF lt_fields IS NOT INITIAL.

CALL FUNCTION 'DYNP_VALUES_UPDATE'


EXPORTING
dyname = sy-cprog
dynumb = sy-dynnr
TABLES
dynpfields = lt_fields
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request =5
no_fielddescription = 6
undefind_error =7
OTHERS = 8.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.

ENDMODULE. " GET_PERSA INPUT

*********************************************************************
*********************************************************************

*----------------------------------------------------------------------*
***INCLUDE LZHR_MAS_TIDI02.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module GET_BTRTL INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE get_btrtl INPUT.

TYPES:
BEGIN OF ty_T001P,
BTRTL TYPE BTRTL,
BTEXT TYPE PBTXT,
END OF ty_T001P.

DATA:
lwa_T001P TYPE ty_T001P,
lt_T001P TYPE TABLE OF ty_T001P,
lt_retval1 TYPE TABLE OF ddshretval,
lwa_retval1 TYPE ddshretval,
lt_fields1 TYPE TABLE OF dynpread,
lwa_fields1 LIKE LINE OF lt_fields1.

data:
lv_line1 TYPE string.

**Get employee subgroup


*break abap07.
SELECT BTRTL BTEXT FROM T001P INTO TABLE lt_T001P. " WHERE sprsl = sy-langu.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'


EXPORTING
retfield = 'BTRTL'
value_org = 'S'
dynprofield = 'BTRTL'
TABLES
value_tab = lt_T001P
return_tab = lt_retval1
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.

READ TABLE lt_retval1 INTO lwa_retval1 INDEX 1.

get CURSOR LINE lv_line1.

lwa_fields1-fieldname = 'ZHR_MAS_TID-BTRTL'.
lwa_fields1-fieldvalue = lwa_retval1-fieldval.
lwa_fields1-STEPL = lv_line1.
APPEND lwa_fields1 TO lt_fields1.
CLEAR: lwa_fields1.

READ TABLE lt_T001P INTO lwa_T001P WITH KEY BTRTL = lwa_retval1-fieldval.


lwa_fields1-fieldname = 'ZHR_MAS_TID-BTEXT'.
lwa_fields1-fieldvalue = lwa_T001P-BTEXT.
lwa_fields1-STEPL = lv_line1.
APPEND lwa_fields1 TO lt_fields1.
CLEAR: lwa_fields1.

IF lt_fields1 IS NOT INITIAL.

CALL FUNCTION 'DYNP_VALUES_UPDATE'


EXPORTING
dyname = sy-cprog
dynumb = sy-dynnr
TABLES
dynpfields = lt_fields1
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request =5
no_fielddescription = 6
undefind_error =7
OTHERS = 8.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.

ENDMODULE. " GET_BTRTL INPUT

You might also like