在创建表维护时,有时需要记录创建人,创建日期,更改人,更改日期等,有时还需自动填入相关字段值得,这里可以在表维护的事务件中写入事件代码 代码 来实现。
比如,以一是在在创建时自动填入创建人,创建日期,的一段代码 例子。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
*----------------------------------------------------------------------* ***INCLUDE LZTRT2900F02. *----------------------------------------------------------------------* FORM new_entries. IF <table1> IS ASSIGNED. PERFORM fill_value USING 'ERDAT' sy-datum. PERFORM fill_value USING 'ERNAM' sy-uname. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form FILL_VALUE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM fill_value USING VALUE(p_fieldname) VALUE(p_value). FIELD-SYMBOLS <fs_value> TYPE any. ASSIGN COMPONENT p_fieldname OF STRUCTURE <table1> TO <fs_value>. IF sy-subrc = 0. <fs_value> = p_value. ENDIF. ENDFORM. FORM fill_hidden_field . FIELD-SYMBOLS <fs_value> TYPE any. ASSIGN COMPONENT 'ERDAT' OF STRUCTURE <table1> TO <fs_value>. IF sy-subrc = 0 AND <fs_value> IS NOT INITIAL. PERFORM fill_value USING 'AEDAT' sy-datum. PERFORM fill_value USING 'AENAM' sy-uname. ENDIF. ENDFORM. |
1.例子二
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
*----------------------------------------------------------------------* ***INCLUDE LZRVCO005AF01. *----------------------------------------------------------------------* FORM ZPF_CREATE_SAVE. ZRVCO005A-ERNAME = SY-UNAME . ZRVCO005A-ERDAT = SY-DATUM . ZRVCO005A-ERTIM = SY-UZEIT . **-检查历史数据是否有重复期间 SELECT COUNT(*) FROM ZRTCO005A WHERE WERKS = ZRVCO005A-WERKS AND ( ( ZDATE1 <= ZRVCO005A-ZDATE1 AND ZDATE2 >= ZRVCO005A-ZDATE1 ) OR ( ZDATE1 <= ZRVCO005A-ZDATE2 AND ZDATE2 >= ZRVCO005A-ZDATE2 ) ) AND MATNR = ZRVCO005A-MATNR . IF SY-SUBRC = 0. MESSAGE E000(ZRMM) WITH '时间与已有条目存在交叉,不能重复创建'. ENDIF. **-检查当前新增保存的是否有重复期间 DATA:LT_ZDATA TYPE TABLE OF ZRVCO005A, LS_ZDATA TYPE ZRVCO005A. FIELD-SYMBOLS : <FS_FIELD> TYPE ANY . LOOP AT TOTAL . IF <ACTION> <> 'N'. CONTINUE. ENDIF. MOVE-CORRESPONDING <VIM_TOTAL_STRUC> TO LS_ZDATA. IF LS_ZDATA-WERKS = ZRVCO005A-WERKS AND LS_ZDATA-MATNR = ZRVCO005A-MATNR AND ( ( LS_ZDATA-ZDATE1 <= ZRVCO005A-ZDATE1 AND LS_ZDATA-ZDATE2 >= ZRVCO005A-ZDATE1 ) OR ( LS_ZDATA-ZDATE1 <= ZRVCO005A-ZDATE2 AND LS_ZDATA-ZDATE2 >= ZRVCO005A-ZDATE2 ) ). MESSAGE E000(ZRMM) WITH '与新增条目时间交叉,不能重复创建'. ENDIF. ASSIGN COMPONENT 'CRNAME' OF STRUCTURE <VIM_TOTAL_STRUC> TO <FS_FIELD> . ENDLOOP. ENDFORM. FORM ZPF_MODIFY_SAVE. FIELD-SYMBOLS : <FS_FIELD> TYPE ANY . LOOP AT TOTAL . CHECK <ACTION> EQ AENDERN. ASSIGN COMPONENT 'CRNAME' OF STRUCTURE <VIM_TOTAL_STRUC> TO <FS_FIELD> . IF SY-SUBRC = 0 . <FS_FIELD> = SY-UNAME . ENDIF. ASSIGN COMPONENT 'CRDAT' OF STRUCTURE <VIM_TOTAL_STRUC> TO <FS_FIELD> . IF SY-SUBRC = 0 . <FS_FIELD> = SY-DATUM . ENDIF. ASSIGN COMPONENT 'CRTIM' OF STRUCTURE <VIM_TOTAL_STRUC> TO <FS_FIELD> . IF SY-SUBRC = 0 . <FS_FIELD> = SY-UZEIT . ENDIF. READ TABLE EXTRACT WITH KEY <VIM_XTOTAL_KEY>. IF SY-SUBRC = 0. EXTRACT = TOTAL . MODIFY EXTRACT INDEX SY-TABIX. ENDIF. MODIFY TOTAL. ENDLOOP. * ENDFORM. |