SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software SAP ABAP Programming and HANA Database Tutorials
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Windows, Windows Phone, SAP and ABAP, like SAP UI5, Screen Personas, etc.

CRM Companies List
Web Based CRM Software

Get Current Timestamp and Calculate Time Difference in ABAP

ABAP developers can calculate execution time by calculating time difference between two timestamp variables in their ABAP programs by code. In this ABAP tutorial, I want to share how to read current timestamp value into a local variable and use timestamp variables to calculate time difference between two events.

How to get current timestamp value in ABAP

If you develop code using ABAP for SAP, you frequently require to get current timestamp into ABAP variables. ABAP programmers can read current timestamp value into a variable using following ABAP code.

get time stamp field data(lv_timestamp).

This code will define a new variable named lv_timestamp (for local variable timestamp) and set its value.
The timestamp value will include time data including years to time in seconds detail.

Calculate time difference in ABAP using timestamp variables

If you want to calculate time difference between two statement execution, following ABAP code can help programmers time passed during execution of a LOOP statement in sample SAP report for example.

* start time
get time stamp field data(lv_ts_start).

* sample task
loop at lt_data reference into data(lr_data).

* end time
get time stamp field data(lv_ts_end).

* calculate time difference between timestamp values in ABAP
data(lv_timepassed_seconds) = cl_abap_tstmp=>subtract(
 tstmp1 = lv_ts_end
 tstmp2 = lv_ts_start ).

ABAP code for timestamp calculations

Please note that I have used ABAP class cl_abap_tstmp (Arithmetic and Conversion for Time Stamps) and its subtract method to calculate the difference between two timestamp values.

ABAP timestamp variables in debug mode

SAP Tutorials

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table

Copyright © 2004 - 2017 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems