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.
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.
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.