6

Auto fill a timestamp field at database level

 6 months ago
source link: https://community.sap.com/t5/enterprise-resource-planning-q-a/auto-fill-a-timestamp-field-at-database-level/qaq-p/12557407
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Auto fill a timestamp field at database level

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)

andrefischer

Product and Topic Expertandrefischer

Product and Topic Expert

‎12-19-2023

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

andrefischer

Product and Topic Expertandrefischer

Product and Topic Expert

‎04-25-2022

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,

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK