This commit is contained in:
danrega
2025-03-10 16:30:46 +01:00
parent d95fb33a69
commit 4295ca5afe
4 changed files with 95 additions and 44 deletions

View File

@@ -675,7 +675,7 @@ DATA(it_e) = VALUE it_type( ( carrid = 'XY' carrname = 'XY Airlines' )
( carrid = 'YZ' carrname = 'Air YZ' ) ).
"Not providing any table lines means the table is initial
"and has the same effect as the declaration of it_f.
"and has the same effect as the declaration of it_g.
DATA(it_f) = VALUE string_table( ).
DATA it_g TYPE string_table.

View File

@@ -1915,7 +1915,7 @@ DATA(utcl2tsl) = cl_abap_tstmp=>utclong2tstmp( ts2utcl ).
<tr>
<td> <code>XCO_CP_TIME</code> </td>
<td> <code>XCO_CP_TIME</code><br><code>XCO_CP</code> </td>
<td>
Class of the XCO time library that provides abstractions for getting and working with date and time information. Find more details <a href="https://help.sap.com/docs/btp/sap-business-technology-platform/time-library">here</a>.
<br><br>

View File

@@ -139,24 +139,36 @@ DATA(utc_date) = cl_abap_context_info=>get_system_date( ).
"Using XCO
"Notes:
"- The result of the following chained statement is of type string.
"- 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.
"- The 'date' method has a 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.
"e.g. 20240101
DATA(date_1) = xco_cp=>sy->date( )->as( xco_cp_time=>format->iso_8601_basic )->value.
"e.g. 2024-01-01
DATA(date_2) = xco_cp=>sy->date( )->as( xco_cp_time=>format->iso_8601_extended )->value.
"Specifying the default time zone explicitly
" is applied to the time. Several options are available.
"- The 'date' 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 'date' method. In
" this case, the user time zone is used implicitly.
"- specify an specific format in the 'as' method.
"e.g. 20250101
DATA(date_abap) = xco_cp=>sy->date( )->as( xco_cp_time=>format->abap )->value.
"e.g. 20250101
DATA(date_basic) = xco_cp=>sy->date( )->as( xco_cp_time=>format->iso_8601_basic )->value.
"e.g. 2025-01-01
DATA(date_ext) = xco_cp=>sy->date( )->as( xco_cp_time=>format->iso_8601_extended )->value.
"Specifying the time zone explicitly in the 'date' method
"The following method call retrieves the current user date.
DATA(date_3) = xco_cp=>sy->date( xco_cp_time=>time_zone->user
)->as( xco_cp_time=>format->iso_8601_extended
DATA(date_user_tz) = xco_cp=>sy->date( xco_cp_time=>time_zone->user
)->as( xco_cp_time=>format->iso_8601_basic
)->value.
"Specifying UTC
DATA(date_4) = xco_cp=>sy->date( xco_cp_time=>time_zone->utc
)->as( xco_cp_time=>format->iso_8601_extended
"Specifying the UTC time zone
DATA(date_utc_tz) = xco_cp=>sy->date( xco_cp_time=>time_zone->utc
)->as( xco_cp_time=>format->iso_8601_basic
)->value.
"--------------------- Retrieving current date values (XCO) --------------------
@@ -492,11 +504,37 @@ The code snippet below provides examples of time processing, such as retrieving
DATA(utc_time) = cl_abap_context_info=>get_system_time( ).
"Using XCO
"Note the optional time zone specification.
"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 an 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.
"Result: e.g. 14:39:10
DATA(time_w_xco) = xco_cp=>sy->time( xco_cp_time=>time_zone->user
)->as( xco_cp_time=>format->iso_8601_extended
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.
```
@@ -748,25 +786,38 @@ More information: [`utclong_current`](https://help.sap.com/doc/abapdocu_cp_index
DATA(ts1) = utclong_current( ).
"Using XCO
"In the case of XCO, the return value is of type string.
"Retrieving a time stamp in the user's time zone (which is the default)
"e.g. 2024-01-01T08:54:39
DATA(ts2) = xco_cp=>sy->moment( xco_cp_time=>time_zone->user
)->as( xco_cp_time=>format->iso_8601_extended
"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 'moment' 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 'moment' method. In
" this case, the user time zone is used implicitly.
"- specify an specific format in the 'as' method.
"e.g. 20250101162319
DATA(ts_abap) = xco_cp=>sy->moment( )->as( xco_cp_time=>format->abap )->value.
"e.g. 20250310T162320
DATA(ts_basic) = xco_cp=>sy->moment( )->as( xco_cp_time=>format->iso_8601_basic )->value.
"e.g. 2025-01-01T16:23:20
DATA(ts_ext) = xco_cp=>sy->moment( )->as( xco_cp_time=>format->iso_8601_extended )->value.
"Specifying the time zone explicitly in the 'moment' method
"The following method call retrieves the current user time stamp.
DATA(ts_user_tz) = xco_cp=>sy->moment( xco_cp_time=>time_zone->user
)->as( xco_cp_time=>format->iso_8601_basic
)->value.
"Current time stamp in UTC
"e.g. 2024-01-01T08:54:39
DATA(ts3) = xco_cp=>sy->moment( xco_cp_time=>time_zone->utc
)->as( xco_cp_time=>format->iso_8601_extended
"Specifying the UTC time zone
DATA(ts_utc_tz) = xco_cp=>sy->moment( xco_cp_time=>time_zone->utc
)->as( xco_cp_time=>format->iso_8601_basic
)->value.
"Different formatting options
DATA(ts_xco) = xco_cp=>sy->moment( xco_cp_time=>time_zone->utc ).
""e.g. 20240101123455
DATA(ts4) = ts_xco->as( xco_cp_time=>format->abap )->value.
"e.g. 20240101T123455
DATA(ts5) = ts_xco->as( xco_cp_time=>format->iso_8601_basic )->value.
"As used above, e.g. 2024-01-01T12:34:55
DATA(ts6) = ts_xco->as( xco_cp_time=>format->iso_8601_extended )->value.
```
<p align="right"><a href="#top">⬆️ back to top</a></p>

View File

@@ -1,6 +1,6 @@
version = 1
SPDX-PackageName = "abap-cheat-sheets"
SPDX-PackageSupplier = "Daniel Reger <daniel.reger@sap.com>"
SPDX-PackageSupplier = "<ospo@sap.com>"
SPDX-PackageDownloadLocation = "https://github.com/SAP-samples/abap-cheat-sheets"
SPDX-PackageComment = "The code in this project may include calls to APIs (\"API Calls\") of\n SAP or third-party products or services developed outside of this project\n (\"External Products\").\n \"APIs\" means application programming interfaces, as well as their respective\n specifications and implementing code that allows software to communicate with\n other software.\n API Calls to External Products are not licensed under the open source license\n that governs this project. The use of such API Calls and related External\n Products are subject to applicable additional agreements with the relevant\n provider of the External Products. In no event shall the open source license\n that governs this project grant any rights in or to any External Products,or\n alter, expand or supersede any terms of the applicable additional agreements.\n If you have a valid license agreement with SAP for the use of a particular SAP\n External Product, then you may make use of any API Calls included in this\n project's code for that SAP External Product, subject to the terms of such\n license agreement. If you do not have a valid license agreement for the use of\n a particular SAP External Product, then you may only make use of any API Calls\n in this project for that SAP External Product for your internal, non-productive\n and non-commercial test and evaluation of such API Calls. Nothing herein grants\n you any rights to use or access any SAP External Product, or provide any third\n parties the right to use of access any SAP External Product, through API Calls."