Manipulating Timestamps in ABAP


Actually, we should use time stamp in our abap programs instead of the traditional date and time fields. When we have to do some calculation on a time stamp is not as easy as on a date field.

For example, to add an hour to a timestamp, many people will:

convert the time stamp into a standard date and field, add an hour, convert back the date and time to a timestamp.

However, it is the slowest method you can use.

Instead, use class CL_ABAP_TSTMP. It enables you to make whatever calculation you want on a time stamp.

In the following example, 1 hour is added:

REPORT zdany_tstamp.
DATA : l_tstamp         TYPE timestamp,
               l_tstamp_out TYPE timestamp.
              GET TIME STAMP FIELD l_tstamp.
  CALL METHOD cl_abap_tstmp=>add    
   tstmp = l_tstamp       
   secs = 3600 “<<<===— 1 hour = 3600 seconds    
   r_tstmp = l_tstamp_out. 
  CATCH cx_parameter_invalid_range .
                 WRITE ‘invalid range’.               
  CATCH cx_parameter_invalid_type .
                 WRITE ‘invalid type’.
 WRITE l_tstamp time zone ‘UTC+5.5’.
 WRITE l_tstamp_out time zone ‘UTC+5.5’.


Output of the program is shown as below:

Output - Timestamps
Output - Timestamps


NOTE: Prior to 1972, this time was called Greenwich Mean Time (GMT) but is now referred to as Coordinated Universal Time or Universal Time Coordinated (UTC). It is a coordinated time scale, maintained by the Bureau International des Poids et Mesures (BIPM). It is also known a “Z time” or “Zulu Time”.


Please enter your comment!
Please enter your name here