100% found this document useful (1 vote)
2K views14 pages

TMG Event 01 Changed Data

The document discusses populating automatic values in fields when records are created or changed using TMG (Transaction Model Generator). It provides code to write an event that will capture the current date, time, and user when a record is added or updated. The event uses internal TMG tables and field symbols to read from and write to the tables, updating the fields with current date, time, and user information.

Uploaded by

sumeetp87
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views14 pages

TMG Event 01 Changed Data

The document discusses populating automatic values in fields when records are created or changed using TMG (Transaction Model Generator). It provides code to write an event that will capture the current date, time, and user when a record is added or updated. The event uses internal TMG tables and field symbols to read from and write to the tables, updating the fields with current date, time, and user information.

Uploaded by

sumeetp87
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 14

TMG EVENT TO Populate Auto values

(EVENT-01)
Refrence link -http://scn.sap.com/thread/1851232

In Above screen shot there are 3 fields which needs to be populate automatically when user enter data
in table through TMG(SM30).
E.g. When add new record in table ,system automatically should take current date(record added date)
also when user change the exisitng record thorugh sm30 system shoul capture current date and time.
On change of table record we need to handle the changed record of table with field-symbols for
TABLES and EXTRACT .
Note- TABLES and EXTRACT are the two internal tables get automatically created when we
create the TMG .
-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)
So for this we have to write and read data in TABLES and EXTRACT internal table.
Below is the logic and snaps for same.

-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)

-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)

-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)

Above screen shot created on ,changed on , Time coloumns make it non-editable mode. Thorugh se51.

-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)

-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)

01 Event trigger for create and change (add record /change/delete from tmg table)

-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)

-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)

-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)

After creating event for TMG, Use FORM -ENDFORM. To write ABAP Code otherwise will get
"statement not accessible error" in TMG event editor.

FORM change_rec.
DATA: F_INDEX LIKE SY-TABIX. "Index to note the lines found
field-symbols : <fs> type any.
BREAK-POINT.
LOOP AT TOTAL.
-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)
IF <ACTION> = 'U'. " Update
READ TABLE EXTRACT WITH KEY <vim_xtotal_key>.
IF SY-SUBRC EQ 0.
F_INDEX = SY-TABIX.
ELSE.
CLEAR F_INDEX.
ENDIF.
check f_index <> 0.
* Update By
*
Assign component 'AENAM' of structure
*
<vim_total_struc> to <fs>.
*
<fs> = sy-uname.
* Update on
Assign component 'CHANGEDON' of structure
<vim_total_struc> to <fs>.
<fs> = sy-datum. "Lase Update Date
* Time
Assign component 'ZTIME' of structure
<vim_total_struc> to <fs>.
<fs> = sy-uzeit. "Lase Update time
MODIFY TOTAL.
EXTRACT = TOTAL.
MODIFY EXTRACT INDEX f_index.
clear f_index.
elseif <ACTION> = 'N'. " Created By
READ TABLE EXTRACT WITH KEY <vim_xtotal_key>.
IF SY-SUBRC EQ 0.
F_INDEX = SY-TABIX.
ELSE.
CLEAR F_INDEX.
ENDIF.
check f_index <> 0.
* Update By
*
Assign component 'AENAM' of structure
*
<vim_total_struc> to <fs>.
*
<fs> = sy-uname.
* Update on
Assign component 'CREATEDON' of structure
<vim_total_struc> to <fs>.
<fs> = sy-datum. "Lase Update Date
-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)
* Time
Assign component 'ZTIME' of structure
<vim_total_struc> to <fs>.
<fs> = sy-uzeit. "Lase Update time
MODIFY TOTAL.
EXTRACT = TOTAL.
MODIFY EXTRACT INDEX f_index.
clear f_index.
ENDIF.

endloop.
ENDFORM.

"change_rec

Or below code.

*----------------------------------------------------------------------*
***INCLUDE LZCFCOLLF01 .
*----------------------------------------------------------------------*
FORM change_rec.
DATA: F_INDEX LIKE SY-TABIX. "Index to note the lines found
field-symbols : <fs> type any.
BREAK-POINT.
LOOP AT TOTAL.
IF <ACTION> = 'U'. " Update
READ TABLE EXTRACT WITH KEY <vim_xtotal_key>.
IF SY-SUBRC EQ 0.
F_INDEX = SY-TABIX.
ELSE.
CLEAR F_INDEX.
ENDIF.
check f_index <> 0.
* Update By
*
Assign component 'AENAM' of structure
*
<vim_total_struc> to <fs>.
*
<fs> = sy-uname.
* Update on
Assign component 'CHANGEDON' of structure

-Sumit Patil

TMG EVENT TO Populate Auto values


(EVENT-01)
*

<fs> = sy-datum.

<vim_total_struc> to <fs>.
"Lase Update Date

Time
Assign component 'ZTIME' of structure
<vim_total_struc> to <fs>.
<fs> = sy-uzeit.
"Lase Update time
MODIFY TOTAL.
EXTRACT = TOTAL.
MODIFY EXTRACT INDEX f_index.
clear f_index.

*
*
*
*
*

elseif <ACTION> = 'N'. " Created By


READ TABLE EXTRACT WITH KEY <vim_xtotal_key>.
IF SY-SUBRC EQ 0.
F_INDEX = SY-TABIX.
ELSE.
CLEAR F_INDEX.
ENDIF.
check f_index <> 0.
Update By
Assign component 'AENAM' of structure
<vim_total_struc> to <fs>.
<fs> = sy-uname.
Update on
Assign component 'CREATEDON' of structure
<vim_total_struc> to <fs>.
<fs> = sy-datum.
"Lase Update Date
Time
Assign component 'ZTIME' of structure
<vim_total_struc> to <fs>.
<fs> = sy-uzeit.
"Lase Update time
MODIFY TOTAL.
EXTRACT = TOTAL.
MODIFY EXTRACT INDEX f_index.
clear f_index.
ENDIF.

endloop.
ENDFORM.

-Sumit Patil

"change_rec

TMG EVENT TO Populate Auto values


(EVENT-01)

Thanks.
Sumit.Patil.

-Sumit Patil

You might also like