SAP Tutorials Blog


 


 


The code snippet below provides examples of time processing, such as retrieving the current time, accessing time values, creating time values, and performing time calculations. You can also utilize the XCO library in different scenarios. Note that the return value in most of the code snippets using XCO is of type string.


Retrieving the Current Time

*&---------------------------------------------------------------------*

*& Retrieving the current time

*&---------------------------------------------------------------------*


"Retrieving the current time in UTC, e.g. 152450

DATA(utc_time) = cl_abap_context_info=>get_system_time( ).


"Using XCO

"Notes:

"- The results of the following chained statements are of type string.

"- With the 'as' method, a given format (available via xco_cp_time=>format)

"  is applied to the time. Several options are available.

"- The 'time' method has an optional importing parameter for specifying the

"  time zone. By default, the user's time zone is used. For the specification,

"  you can use xco_cp_time=>time_zone.


"The following three examples

"- do not specify the optional importing parameter for the 'time' method. In

"  this case, the user time zone is used implicitly.

"- specify a specific format in the 'as' method.


"e.g. 160907

DATA(time_abap) = xco_cp=>sy->time( )->as( xco_cp_time=>format->abap )->value.


"e.g. 160907

DATA(time_basic) = xco_cp=>sy->time( )->as( xco_cp_time=>format->iso_8601_basic )->value.


"e.g. 16:09:07

DATA(time_ext) = xco_cp=>sy->time( )->as( xco_cp_time=>format->iso_8601_extended )->value.


"Specifying the time zone explicitly in the 'time' method

"The following method call retrieves the current user time.

DATA(time_user_tz) = xco_cp=>sy->time( xco_cp_time=>time_zone->user

                                )->as( xco_cp_time=>format->iso_8601_basic

                                )->value.


"Specifying the UTC time zone

DATA(time_utc_tz) = xco_cp=>sy->time( xco_cp_time=>time_zone->utc

                                )->as( xco_cp_time=>format->iso_8601_basic

                                )->value.


Serkan AKKAVAK

Computer Engineer BSc

Head of SAP & Software Department

Contact : serkurumsal@yandex.com