From 4295ca5afef2667c178b147e842cce1dfebfa76a Mon Sep 17 00:00:00 2001 From: danrega <16720986+danrega@users.noreply.github.com> Date: Mon, 10 Mar 2025 16:30:46 +0100 Subject: [PATCH] Update --- 01_Internal_Tables.md | 2 +- 22_Released_ABAP_Classes.md | 2 +- 23_Date_and_Time.md | 133 +++++++++++++++++++++++++----------- REUSE.toml | 2 +- 4 files changed, 95 insertions(+), 44 deletions(-) diff --git a/01_Internal_Tables.md b/01_Internal_Tables.md index 7dc5b77..609fe93 100644 --- a/01_Internal_Tables.md +++ b/01_Internal_Tables.md @@ -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. diff --git a/22_Released_ABAP_Classes.md b/22_Released_ABAP_Classes.md index 1b00091..5db331a 100644 --- a/22_Released_ABAP_Classes.md +++ b/22_Released_ABAP_Classes.md @@ -1915,7 +1915,7 @@ DATA(utcl2tsl) = cl_abap_tstmp=>utclong2tstmp( ts2utcl ). - XCO_CP_TIME + XCO_CP_TIME
XCO_CP Class of the XCO time library that provides abstractions for getting and working with date and time information. Find more details here.

diff --git a/23_Date_and_Time.md b/23_Date_and_Time.md index 809616c..acb1586 100644 --- a/23_Date_and_Time.md +++ b/23_Date_and_Time.md @@ -139,25 +139,37 @@ 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 - )->value. -"Specifying UTC -DATA(date_4) = xco_cp=>sy->date( xco_cp_time=>time_zone->utc - )->as( xco_cp_time=>format->iso_8601_extended - )->value. +DATA(date_user_tz) = xco_cp=>sy->date( xco_cp_time=>time_zone->user + )->as( xco_cp_time=>format->iso_8601_basic + )->value. + +"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) -------------------- "e.g. 01 @@ -492,12 +504,38 @@ 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 - )->value. +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. ``` ### Accessing Time Values @@ -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 - )->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 - )->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. +"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. + +"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. ```

⬆️ back to top

diff --git a/REUSE.toml b/REUSE.toml index 0056da6..f356362 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -1,6 +1,6 @@ version = 1 SPDX-PackageName = "abap-cheat-sheets" -SPDX-PackageSupplier = "Daniel Reger " +SPDX-PackageSupplier = "" 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."