Get Example source ABAP code based on a different SAP table
Evaluating Date Fields and Time Fields This example demonstrates calculations with date and time fields.
ABAP_SOURCE_CODE DEMO CL_DEMO_DATA_DATE_TIME
ABAP_DESCRIPTION In the first part of the main> method, the last day of the previous month is assigned to the date field ultimo>. First, ultimo> is filled with the current date. Then, the date is changed to the first day of the current month by specifying an offset. Finally, 1 is subtracted from ultimo> so that the content of the field is changed to the last day of the previous month. Before the subtraction takes place, the system converts ultimo> into the number of days since 01.01.0001 and converts the result back into a date. In the second part, the number of hours between midnight and the current time are calculated. First, the difference between the time fields is calculated. The difference is then converted into the total number of seconds using the MOD> operation. A positive difference remains unchanged. This step is only necessary for negative differences. Finally, the number of hours is calculated by dividing the number of seconds by 3600.