sap提供了强大的扩展功能。 详见 :
http://help.sap.com/saphelp_nw04/helpdata/en/91/ca9f0ea9d111d1a5690000e82deaaa/frameset.htm
今天遇到了一个需求,给自建表创建维护程序,但是要求加上操作记录功能和校验功能。
使用了01事件(Event 01 before saving the data in the database )来给记录添加时间戳。
路径如下 :
实际上,也可以使用Event 21 fill hidden fields来实现的。
几个注意事项:1 不能使用error的信息,会跳出程序的。
2 internal table TOTAL 全部的数据,相当于
这样定义的
INCLUDE STRUCTURE <view name> or <table name>
INCLUDE STRUCTURE VIMTBFLAGS
internal table EXTRACT. 是有修改内容的表。
3 三种操作的常量
<ACTION> :
新增 N
更新 U
删除 D
下面是code:
Event 1的
FORM sub_check_before_save .
DATA: f_index LIKE sy-tabix. "Index to note the lines found
DATA : BEGIN OF ls_wa .
INCLUDE STRUCTURE zbranch.
INCLUDE STRUCTURE vimtbflags.
DATA END OF ls_wa .
LOOP AT total.
IF <action> = 'U' " Update
OR <action> = 'N' ."NEW
* 'D' " delete no need now
READ TABLE extract WITH KEY <vim_xtotal_key>.
IF sy-subrc EQ 0.
f_index = sy-tabix.
ELSE.
CLEAR f_index.
ENDIF.
* (make desired changes to the line total)
CLEAR ls_wa .
MOVE total TO ls_wa .
ls_wa-change_user = sy-uname .
ls_wa-change_date = sy-datum .
ls_wa-change_time = sy-uzeit .
CONCATENATE sy-datum sy-uzeit INTO ls_wa-change_stamp .
total = ls_wa .
* total-mandt = sy-mandt .
MODIFY total.
CHECK f_index GT 0.
extract = total.
MODIFY extract INDEX f_index.
ENDIF.
ENDLOOP.
sy-subrc = 0.
ENDFORM . "sub_check_before_save