FavoriteLoading
0

如何在SM30维护表时自动写入表字段的默认值-事件(EVENT)

在使用sm30维护表数据时,经常会要求一些字段是不可输入的,它们的值要自动带出来,也就是给一个默认值,比如一些描述字段,表数据的维护人,维护日期以及时间。这些是通过SE54中的“事件(EVENT)”来实现的。

下面以一个小例子详细说一下具体的实现过程。

1,首先要有一个表,咔嚓~~~下面这个表就创建好了,4个字段,包括2个描述字段-物料组描述和采购组描述,这两个字段就打算在表维护视图中做成不可输入,自动根据物料组和采购组读出来的。

2,SE54创建表维护视图

单击概述屏幕1,将屏幕中的两个描述字段修改为不可输入

将输入字段的勾去掉

3,SE54中进入事件屏幕,对表维护视图进行增强,

创建新条目,选择05事件,写入子例程名字也就是form名,然后点击编辑器按钮进入code editor

05事件就是在表维护视图保存的时候出发的事件,当然也可以通过其他事件来实现写入默认值功能,比如01-在数据库保存之前触发,21-填充隐藏字段(这个看名字可以实现此功能,但是没亲自测试过,05能实现就行,还要啥自行车)

把ABAP代码磊上,取出各自的描述,

结果就是下面这样,输入物料组之后点击保存按钮,物料组描述就会自动带出来。

附一个事件大全:

对应英语为:

List of Events available in Table maintenance
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 sub screen (time-dep. tab. /views)
21         Fill hidden fields
22         Go to long text maintenance for other languages
23         Before calling address maintenance 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
AG       Instead of 'Get original' for texts in other languages
AH        Instead of DB change for texts in other languages
ST        GUI menu main program name
AI         Internal use only

以上。