‎2007 Feb 06 7:35 PM
Hello,
I have been playing with events to progamatically maintain a couple of audit fields. Here is the code for the events...
----
INCLUDE LZEBPL_GLAABTM *
----
----
Form AT_NEWENTRY.
----
Set G/L Account Short Description, Where Applicable
IF ZEBP_GLACCTASSGN-SAKTX = SPACE.
select single TXT20 from SKB1 as a
inner join SKAT as b on asaknr = bsaknr
into ZEBP_GLACCTASSGN-SAKTX
where a~SAKNR = ZEBP_GLACCTASSGN-SAKNR
and a~BUKRS = ZEBP_GLACCTASSGN-BUKRS
and b~SPRAS = sy-LANGU.
ENDIF.
Set Create Audit Fields, Where Applicable.
IF ZEBP_GLACCTASSGN-CRTDT = 0.
ZEBP_GLACCTASSGN-CRTDT = sy-DATUM.
ZEBP_GLACCTASSGN-CRTTM = sy-UZEIT.
ZEBP_GLACCTASSGN-CRTBY = sy-UNAME.
ENDIF.
Set Change Audit Fields.
ZEBP_GLACCTASSGN-CHGDT = sy-DATUM.
ZEBP_GLACCTASSGN-CHGTM = sy-UZEIT.
ZEBP_GLACCTASSGN-CHGBY = sy-UNAME.
EndForm.
----
Form AT_BEFORESAVE.
----
Set G/L Account Short Description, Where Applicable
select single TXT20 from SKB1 as a
inner join SKAT as b on asaknr = bsaknr
into ZEBP_GLACCTASSGN-SAKTX
where a~SAKNR = ZEBP_GLACCTASSGN-SAKNR
and a~BUKRS = ZEBP_GLACCTASSGN-BUKRS
and b~SPRAS = sy-LANGU.
Set Change Audit Fields.
ZEBP_GLACCTASSGN-CHGDT = sy-DATUM.
ZEBP_GLACCTASSGN-CHGTM = sy-UZEIT.
ZEBP_GLACCTASSGN-CHGBY = sy-UNAME.
SY-SUBRC = 0.
EndForm.
On the create, the fields are maintained but when I go in and change a value in the record, the routine is executed, but the data in the audit fields is not updated. What am I missing?
Regards, Dean.
‎2007 Dec 11 1:59 PM
This seems to work...
----
INCLUDE LZEBPL_GLAABTM *
----
----
Form AT_NEWENTRY.
----
Set G/L Account Short Description, Where Applicable
IF ZEBP_GLACCTASSGN-SAKTX = SPACE.
select single TXT20 from SKB1 as a
inner join SKAT as b on asaknr = bsaknr
into ZEBP_GLACCTASSGN-SAKTX
where a~SAKNR = ZEBP_GLACCTASSGN-SAKNR
and a~BUKRS = ZEBP_GLACCTASSGN-BUKRS
and b~SPRAS = sy-LANGU.
ENDIF.
Set Create Audit Fields, Where Applicable.
IF ZEBP_GLACCTASSGN-CRTDT = 0.
ZEBP_GLACCTASSGN-CRTDT = sy-DATUM.
ZEBP_GLACCTASSGN-CRTTM = sy-UZEIT.
ZEBP_GLACCTASSGN-CRTBY = sy-UNAME.
ENDIF.
Set Change Audit Fields.
ZEBP_GLACCTASSGN-CHGDT = sy-DATUM.
ZEBP_GLACCTASSGN-CHGTM = sy-UZEIT.
ZEBP_GLACCTASSGN-CHGBY = sy-UNAME.
EndForm.
----
Form AT_BEFORESAVE.
----
data: F_INDEX LIKE SY-TABIX.
data begin of TOTAL_S.
include structure ZEBP_GLACCTASSGN.
data ACTION.
data MARK.
data end of TOTAL_S.
data EXTRACT_S like TOTAL_S.
Loop Through Internal Maintenance Table <TOTAL>
loop at TOTAL.
if <ACTION> = 'U'.
move TOTAL to TOTAL_S.
read table EXTRACT with key TOTAL.
if SY-SUBRC eq 0.
F_INDEX = SY-TABIX.
else.
clear F_INDEX.
endif.
(Make Desired Changes to The Line TOTAL)
Set G/L Account Short Description, Where Applicable
select single TXT20 from SKB1 as a
inner join SKAT as b on asaknr = bsaknr
into TOTAL_S-SAKTX
where a~SAKNR = TOTAL_S-SAKNR
and a~BUKRS = TOTAL_S-BUKRS
and b~SPRAS = sy-LANGU.
Set Change Audit Fields.
TOTAL_S-CHGDT = sy-DATUM.
TOTAL_S-CHGTM = sy-UZEIT.
TOTAL_S-CHGBY = sy-UNAME.
move TOTAL_S to TOTAL.
modify TOTAL.
check F_INDEX gt 0.
EXTRACT = TOTAL.
modify EXTRACT index F_INDEX.
endif.
endloop.
SY-SUBRC = 0.
EndForm.