cancel
Showing results for 
Search instead for 
Did you mean: 

Auto fill a timestamp field at database level

carlos_codesal3
Explorer
0 Kudos
1,628

Hi all.

We need to automatically update a timestamp field with the current date and time in a table that is not updated via maintenance view (SM30), every time that a record is inserted or updated. Is it possible to do it? If this is the case, how it can be done?

In SAP I know how to do it if the table is updated via SM30, but this is not the case.

Thanks in advance.

Accepted Solutions (0)

Answers (2)

Answers (2)

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

This is true.

It will only work with fields where the underlying table uses appropriate data elements such as

created_at : abp_creation_tstmpl;

last_changed_at : abp_locinst_lastchange_tstmpl;

local_last_changed_at : abp_lastchange_tstmpl;

or TZNTSTMPL

or TIMESTAMPL

Regards,

Andre

Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

If it is not updated via SM30 how is it updated then?

Is it your own code in the Z-namespace?

Then you can simply store the current time that you get from the GET TIME STAMP command and store it in your DB table.

GET TIME STAMP - ABAP Keyword Documentation (sap.com)

In SAP S/4HANA you would use a RAP BO and you would add the following annotations to your CDS view and the framework would stored the data for you automatically.

      @Semantics.user.createdBy: true
      local_created_by      as LocalCreatedBy,
      @Semantics.systemDateTime.createdAt: true
      local_created_at      as LocalCreatedAt,
      @Semantics.user.lastChangedBy: true
      local_last_changed_by as LocalLastChangedBy,
      //local ETag field --> OData ETag
      @Semantics.systemDateTime.localInstanceLastChangedAt: true
      local_last_changed_at as LocalLastChangedAt,

      //total ETag field
      @Semantics.systemDateTime.lastChangedAt: true
      last_changed_at       as LastChangedAt,
sabarishlakshmanan
Discoverer

Hi Andre,

The annotation however does not seem to auto update isolated date and time fields.

For example, is there a way to auto-populate the fields for below example:

      @Semantics.user.createdBy: true
      local_created_by      as LocalCreatedBy,
      @Semantics.systemDate.createdAt: true
      local_created_date     as LocalCreatedDate,
@Semantics.systemTime.createdAt: true
local_created_time as LocalCreatedTime,
@Semantics.user.lastChangedBy: true local_last_changed_by as LocalLastChangedBy, //total ETag field @Semantics.systemDate.lastChangedDate: true last_changed_date as LastChangedAt,
@Semantics.systemTime.lastChangedAt: true
last_changed_time as LastChangedTime
szebenyib
Explorer
0 Kudos

The same behavior is present here: for some reason systemDate.lastChangedDate and systemDate.lastChangedAt never update, although they are handled just like other admin fields

godric
Explorer
0 Kudos
Understand that data type for time stamp needs to match but is it a pre condition for auto fill of created by and changed by as it's not working for me: