Monday, 6 January 2014

Date and Time Fields in SAP TABLES

Date and Time Fields in SAP TABLES

This section will look at some other data types which can be used in ABAP. So far, numeric fields have been used for performing calculations, and character strings have been exam-ined along with the ways these can be manipulated with ABAP statements. Now, date and time fields will be looked at.
Enter the ABAP editor (with transaction SE38) and make a copy of the previous program, alter the comment sections, and remove most of the code
Date and Time Fields in SAP TABLES

Date and Time Fields in SAP TABLES

        
        
 Date and time fields are not stored as numeric data types, but instead as character data types. Effectively, they are character strings which can be used in calculations. This is made possible by the inbuilt automatic data type conversions which have previously been discussed. Just like any other data type, the DATA statement is used to declare these fields.
For a date field, the data type is referred to with ‘d’, and is limited to 8 characters. The first 4 of these represent the year, the next 2 the month, and the final 2 the day. The VALUE addition is used to specify this, and if it is not used then the value, by default, is assigned as 8 zeros. In the example below, the date is the 1st of January, 2012
          
Date and Time Fields in SAP TABLES

The LIKE statement, of course, can also be used. SY-DATUM is a system variable, which always holds the value of the system’s date. Below, “my_date2” is defined in the same way as this system variable
         
Date and Time Fields in SAP TABLES

Time fields work similarly, but this time are limited to 6 characters. The first 2 refer to the hour, the second 2 the minute, and the final 2 the second. Again, the default value will be 6 zeros. The data type this time is ‘t’. Again, the LIKE statement can be used, here for the system’s time field, referred to with SY-UZEIT
Date and Time Fields in SAP TABLES

       

We can then use the WRITE statement to output the field contents:
Date and Time Fields in SAP TABLESDate and Time Fields in SAP TABLES


11 comments:

  1. thanks for posting such useful information its very helpful to us
    we are providing sap hybris online training with industry experts
    through out the world

    ReplyDelete