‎2008 Aug 28 10:48 AM
Hi all,
I have created a custom table. In addition to custom fields, we need "changed Date(AEDTM)" and "changed by" fields in this table.
User is not going to fill these fields, system should fill this automatically.
for example: whenever a new record is created(using sm31), changed date = today's date, and changed by = user name.
How to achieve this?
Any idea?
Thanks
Krishna
‎2008 Aug 28 11:39 AM
Using the Table Maintenance event you can populate those fields.
You need to use the event 01
FORM f_actions_event_01.
IF vim_abort_saving IS INITIAL.
* Update Change history fields
INCLUDE ZZFSAI086_UPD_CHG_HSTY .
ENDIF.
ENDFORM. " f_actions_event_01
include code
DATA:
lv_index1 TYPE sy-tabix, "Index for Table 'TOTAL'
lv_index2 TYPE sy-tabix, "Index for Table 'EXTRACT'
lr_data TYPE REF TO data, "Reference Data object
lv_action TYPE char1, "Variable for View action
lv_mark TYPE char1. "Variable for View mark
FIELD-SYMBOLS:
<lf_fval> TYPE any, "For field value
<ls_str> TYPE any, "For data string
<ls_xfrom> TYPE x, "Hexadecimal value of from value
<ls_xto> TYPE x. "Hexadecimal value of to value
* Dynamic creation of data object using the table name
CREATE DATA lr_data TYPE (x_header-viewname).
ASSIGN lr_data->* TO <ls_str>.
CLEAR: lv_index1, lv_index2, lr_data.
* Looping through all the records in the M.View
LOOP AT total.
CLEAR lv_index1.
lv_index1 = sy-tabix.
READ TABLE extract WITH KEY total.
IF sy-subrc EQ 0.
lv_index2 = sy-tabix.
ELSE.
CLEAR lv_index2.
ENDIF.
ASSIGN total TO <ls_xfrom> CASTING.
ASSIGN <ls_str> TO <ls_xto> CASTING.
<ls_xto> = <ls_xfrom>.
MOVE:
<action> TO lv_action,
<mark> TO lv_mark.
CASE <action>.
WHEN neuer_eintrag. " New entry
* If there is a new entry fill created by / date
ASSIGN COMPONENT 'CRNAM' OF STRUCTURE <ls_str> TO <lf_fval>.
IF sy-subrc = 0.
<lf_fval> = sy-uname.
ENDIF.
ASSIGN COMPONENT 'CRDAT' OF STRUCTURE <ls_str> TO <lf_fval>.
IF sy-subrc = 0.
<lf_fval> = sy-datum.
ENDIF.
* If Changed by / date have to be blanked out if e.g. an entry is
copied
assign component 'AENAM' of structure <ls_str> to <lf_fval>.
IF sy-subrc = 0.
CLEAR <lf_fval>.
ENDIF.
ASSIGN COMPONENT 'AEDAT' OF STRUCTURE <ls_str> TO <lf_fval>.
IF sy-subrc = 0.
CLEAR <lf_fval>.
ENDIF.
WHEN aendern. "Updated entry
* Update to an existing entry fill in changed by / date
ASSIGN COMPONENT 'AENAM' OF STRUCTURE <ls_str> TO <lf_fval>.
IF sy-subrc = 0.
<lf_fval> = sy-uname.
ENDIF.
ASSIGN COMPONENT 'AEDAT' OF STRUCTURE <ls_str> TO <lf_fval>.
IF sy-subrc = 0.
<lf_fval> = sy-datum.
ENDIF.
ENDCASE.
*(make desired changes to the line total)
* Changes to be incorporated only when update or new entry.
CHECK <action> EQ aendern OR <action> EQ neuer_eintrag.
CLEAR: total,extract.
ASSIGN <ls_str> TO <ls_xfrom> CASTING.
ASSIGN total TO <ls_xto> CASTING.
<ls_xto> = <ls_xfrom>.
MOVE :
lv_action TO <action>,
lv_mark TO <mark>.
CONCATENATE total lv_action lv_mark INTO total.
MODIFY total FROM total INDEX lv_index1.
* modify extract if this is necessary
CHECK lv_index2 GT 0.
extract = total.
MODIFY extract FROM extract INDEX lv_index2.
ENDLOOP.
‎2008 Aug 28 10:52 AM
Hi,
In my opinion, you can do that with events :
using SE11 then Utility -> maintenance screen generator
Then via the menu -> environment -> modifications -> events
There you have to choose the appropriate event and define a FORM routine. This FORM routine is created within a form-include of the function group containing the maintenance dialogs.
If you want to set the default value at the start of the dialog and when the user creates new entries you will need events '21' (fill hidden fields) and '05' (creating a new entry).
For the events define a form routine within an include in your function group. There you have access to the structure of the view (e.g. z_tabl_view). There you fill z_tabl_view-column = <fixed value>.
For checking data before saving you will need event 01 (before saving the data in the database).
For detailed information please refer to the SAP online documentation:
http://help.sap.com/saphelp_erp2005vp/helpdata/en/91/ca9f0ea9d111d1a5690000e82deaaa/content.htm
Hope this helps,
Erwan
‎2008 Aug 28 11:20 AM
Table maintenance screen generator
environment -> modifications -> events
write your code here
‎2008 Aug 28 11:39 AM
Using the Table Maintenance event you can populate those fields.
You need to use the event 01
FORM f_actions_event_01.
IF vim_abort_saving IS INITIAL.
* Update Change history fields
INCLUDE ZZFSAI086_UPD_CHG_HSTY .
ENDIF.
ENDFORM. " f_actions_event_01
include code
DATA:
lv_index1 TYPE sy-tabix, "Index for Table 'TOTAL'
lv_index2 TYPE sy-tabix, "Index for Table 'EXTRACT'
lr_data TYPE REF TO data, "Reference Data object
lv_action TYPE char1, "Variable for View action
lv_mark TYPE char1. "Variable for View mark
FIELD-SYMBOLS:
<lf_fval> TYPE any, "For field value
<ls_str> TYPE any, "For data string
<ls_xfrom> TYPE x, "Hexadecimal value of from value
<ls_xto> TYPE x. "Hexadecimal value of to value
* Dynamic creation of data object using the table name
CREATE DATA lr_data TYPE (x_header-viewname).
ASSIGN lr_data->* TO <ls_str>.
CLEAR: lv_index1, lv_index2, lr_data.
* Looping through all the records in the M.View
LOOP AT total.
CLEAR lv_index1.
lv_index1 = sy-tabix.
READ TABLE extract WITH KEY total.
IF sy-subrc EQ 0.
lv_index2 = sy-tabix.
ELSE.
CLEAR lv_index2.
ENDIF.
ASSIGN total TO <ls_xfrom> CASTING.
ASSIGN <ls_str> TO <ls_xto> CASTING.
<ls_xto> = <ls_xfrom>.
MOVE:
<action> TO lv_action,
<mark> TO lv_mark.
CASE <action>.
WHEN neuer_eintrag. " New entry
* If there is a new entry fill created by / date
ASSIGN COMPONENT 'CRNAM' OF STRUCTURE <ls_str> TO <lf_fval>.
IF sy-subrc = 0.
<lf_fval> = sy-uname.
ENDIF.
ASSIGN COMPONENT 'CRDAT' OF STRUCTURE <ls_str> TO <lf_fval>.
IF sy-subrc = 0.
<lf_fval> = sy-datum.
ENDIF.
* If Changed by / date have to be blanked out if e.g. an entry is
copied
assign component 'AENAM' of structure <ls_str> to <lf_fval>.
IF sy-subrc = 0.
CLEAR <lf_fval>.
ENDIF.
ASSIGN COMPONENT 'AEDAT' OF STRUCTURE <ls_str> TO <lf_fval>.
IF sy-subrc = 0.
CLEAR <lf_fval>.
ENDIF.
WHEN aendern. "Updated entry
* Update to an existing entry fill in changed by / date
ASSIGN COMPONENT 'AENAM' OF STRUCTURE <ls_str> TO <lf_fval>.
IF sy-subrc = 0.
<lf_fval> = sy-uname.
ENDIF.
ASSIGN COMPONENT 'AEDAT' OF STRUCTURE <ls_str> TO <lf_fval>.
IF sy-subrc = 0.
<lf_fval> = sy-datum.
ENDIF.
ENDCASE.
*(make desired changes to the line total)
* Changes to be incorporated only when update or new entry.
CHECK <action> EQ aendern OR <action> EQ neuer_eintrag.
CLEAR: total,extract.
ASSIGN <ls_str> TO <ls_xfrom> CASTING.
ASSIGN total TO <ls_xto> CASTING.
<ls_xto> = <ls_xfrom>.
MOVE :
lv_action TO <action>,
lv_mark TO <mark>.
CONCATENATE total lv_action lv_mark INTO total.
MODIFY total FROM total INDEX lv_index1.
* modify extract if this is necessary
CHECK lv_index2 GT 0.
extract = total.
MODIFY extract FROM extract INDEX lv_index2.
ENDLOOP.
‎2010 Dec 23 2:23 PM
‎2011 May 06 10:19 AM
Hi Vijaya,
just like to thank you for the codes. It works perfectly for me. keep up the good work. Thanks again.
Regards
Edwin