Get Example source ABAP code based on a different SAP table
Rounding Time Stamps in Packed Numbers This example demonstrates different rounding behaviors for time stamps stored in packed numbers.
ABAP_SOURCE_CODE DEMO CL_DEMO_ROUND_TIME_STAMP
ABAP_DESCRIPTION A short packed number time stamp of type TIMESTAMP>, a long packed number time stamp of type TIMESTAMPL> and a time stamp in a time stamp field of type utclong> are created at almost the same point in time. The example shows the different rounding behaviors when time stamps with fractional seconds are converted to time stamps of type TIMESTAMP> without fractional seconds:
Using method UTCLONG2TSTMP_SHORT> of class CL_ABAP_TSTMP>> to convert a time stamp field rounds down.
Using a simple assignment involving the conversion rule from p> to p>> rounds half up (commercial rounding).
Using method MOVE_TO_SHORT> of class CL_ABAP_TSTMP>> to convert a long time stamp stored as a packed number field rounds half up (commercial rounding).
Using method MOVE> of class CL_ABAP_TSTMP>> to convert a long time stamp stored as a packed number field rounds half up (commercial rounding).
Using built-in function round >> without specifying mode> for a long time stamp stored as a packed number field rounds half up (commercial rounding).
Using built-in function round >> with specifying the appropriate mode mode> for a long time stamp stored as a packed number field rounds down.
Using built-in function trunc>> for a long time stamp stored as a packed number field rounds down. Since only rounding down a long time stamp stored as a packed number gives the same result as the statement GET TIME STAMP>> and if that is the expected behavior, the built-in function round>> with an appropriate mode or trunc>> should be used instead of the methods from CL_ABAP_TSTMP>.