This commit is contained in:
danrega
2024-03-18 15:47:47 +01:00
parent d2e0ff8abf
commit 09e6143714
8 changed files with 1773 additions and 19 deletions

View File

@@ -1624,7 +1624,7 @@ A RAP transaction is divided into two phases during the runtime of a RAP BO, whi
[RAP save sequence](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_save_seq_glosry.htm):
- The RAP save sequence is triggered by a `COMMIT ENTITIES` statement. In natively supported RAP scenarios, such as an SAP Fiori application using OData, the `COMMIT ENTITIES` call is implicitly and automatically performed by the RAP runtime engine.
- RAP saver methods are called in the RAP saver class, which inherits from the base class `CL_ABAP_BEHAVIOR_SAVER`.
- RAP saver methods are called in the RAP saver class, which inherits from the base class `CL_ABAP_BEHAVIOR_SAVER`, in a specific order.
- Is divided into the [RAP early save phase](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenearly_rap_save_phase_glosry.htm) (ensures that the RAP BO instances in the transactional buffer - all RAP BOs in the current RAP transaction are involved - are in a consistent state so that they can be saved to the database) and the [RAP late save phase](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenlate_rap_save_phase_glosry.htm) (to finally save data from the transactional buffer to the database).
(Optional:) Saver methods called in the RAP early save phase:

View File

@@ -8,7 +8,7 @@
Core data services (CDS) are an infrastructure for defining and consuming semantically rich data models on the [standard database](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_db_glosry.htm) of an [AS ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenas_abap_glosry.htm).
> **💡 Note**<br>
> - For cheat sheet content on CDS views, check out [this blog](https://blogs.sap.com/2022/10/24/feature-matrix-data-modeling-with-abap-core-data-services/).
> - For cheat sheet content on [CDS entities](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abencds_entity_glosry.htm), refer to [this blog](https://blogs.sap.com/2022/10/24/feature-matrix-data-modeling-with-abap-core-data-services/).
> - The executable example focuses on CDS view entities and covers a selection of features.
> - The sample CDS view entities are designed to demonstrate a selection of features with a limited number of artifacts. They are not intended to be role models for proper CDS view design. They focus on syntax options only. They are not intended to solve concrete programming tasks. You should always work out your own solution for each individual case.
@@ -31,7 +31,7 @@ The following links take you to the source code of the cheat sheet artifacts to
- String functions
- Coalesce function
- Date and time functions
- [zdemo_abap_cds_ve_agg_exp](zdemo_abap_cds_ve_agg_exp.ddls.asddls)
- [zdemo_abap_cds_ve_agg_exp](src/zdemo_abap_cds_ve_agg_exp.ddls.asddls)
- Aggregate expressions
- [zdemo_abap_cds_ve_joins](src/zdemo_abap_cds_ve_joins.ddls.asddls)
- Inner joins

View File

@@ -21,7 +21,7 @@ It provides references to more detailed information on the topic.
- The available ABAP language version is [ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_for_cloud_dev_glosry.htm) that presents a [restricted ABAP language version](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrestricted_version_glosry.htm).
- [Released APIs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreleased_api_glosry.htm):
- Access to SAP-delivered repository objects is restricted to objects released for ABAP for Cloud Development
- For example, most of the database tables provided by SAP cannot be read directly (although there are abstractions/CDS view entities for many that can be accessed).
- For example, most of the database tables provided by SAP cannot be read directly (although there are abstractions/[CDS entities](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_glosry.htm) for many that can be accessed).
- Libraries are available with predefined functionality.
- Note that repository objects can be classified by a [release contract](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrelease_contract_glosry.htm) (e.g. C0, C1 etc.).
- Tools:

View File

@@ -34,13 +34,14 @@
- [Date and Time Functions in ABAP SQL](#date-and-time-functions-in-abap-sql)
- [Date and Time Functions in ABAP CDS](#date-and-time-functions-in-abap-cds)
- [More Information](#more-information)
- [Executable Example](#executable-example)
This ABAP cheat sheet covers options of how to handle and process dates, times, and time stamps in ABAP. Note the different types when working with them in ABAP, such as for calculations, evaluations, or displaying on a user interface.
## Data Types for Date, Time and Time Stamp
The main data types for date, time, and time stamps in ABAP are as follows::
The main data types for date, time, and time stamps in ABAP are as follows:
- [Built-in ABAP types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuiltin_abap_type_glosry.htm): `d`, `t`, `utclong`
- [Built-in DDIC types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuiltin_ddic_type_glosry.htm) such as `dats`, `tims`, `utclong` and more. These types are mapped to ABAP types (e.g. `dats` is mapped to `d`, `utclong` is mapped to the identically named ABAP type `utclong`). Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_builtin_types.htm#@@ITOC@@ABENDDIC_BUILTIN_TYPES_6).
- Note that the built-in DDIC types are used in artifacts such as [DDIC database tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_db_table_glosry.htm) and [CDS entities](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_glosry.htm), but not in ABAP programs (except for [typed literals](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentyped_literal_glosry.htm)).
@@ -117,7 +118,7 @@ DATA(tz_w_xco_utc) = xco_cp_time=>time_zone->utc->value.
## Date
> **💡 Note**<br>
> - AS ABAP always implicitly references the Gregorian calendar. For output purposes, dates can be converted to country-specific calendars.
> - [AS ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenas_abap_glosry.htm) always implicitly references the Gregorian calendar. For output purposes, dates can be converted to country-specific calendars.
> - Regarding assignments of data objects with numeric data types and calculations: Valid values are converted to the number of days since 01.01.0001.
@@ -392,7 +393,9 @@ LOOP AT date_tab REFERENCE INTO DATA(ref_date).
ENDTRY.
ENDLOOP.
"Content of date_tab:
"Content of date_tab
"Note: The first entry in the table in your system may be different. The currently
"active date format is retrieved.
"EXT_DATE FORMAT INT_DATE
"02/02/2024 2 20240202
"02.02.2024 1 20240202
@@ -823,9 +826,9 @@ CONVERT DATE date2utcl
INTO UTCLONG DATA(utcl_inl2).
"Ensure that valid values are passed
"The following example explores invalid values that are passed.
"the valid time stamp, the exceptions raised and the error messages
"are added to an internal table.
"The following example explores ABAP statements with invalid values
"that are passed. The valid time stamp, the exceptions raised and
"the error messages are added to an internal table.
DATA error_checks TYPE string_table.
DATA date_test TYPE d.
DATA time_test TYPE t.
@@ -1019,17 +1022,15 @@ CONVERT DATE date4conv
INTO TIME STAMP ts_conv
TIME ZONE 'EST'.
"Using the long form with type timestampl as target type and
"setting the daylight saving time explicitly using the
"optional addition DAYLIGHT SAVING TIME. Find more
"details in the ABAP Keyword Documentation.
"Using the long form with type timestampl as target type.
"20240808152458.0
DATA tsl_conv TYPE timestampl.
CONVERT DATE CONV d( '20240101' )
TIME CONV t( '112458' )
DAYLIGHT SAVING TIME 'X'
TIME CONV t( '112458' )
INTO TIME STAMP tsl_conv
TIME ZONE 'EST'.
"Note that you can optionally specify the DAYLIGHT SAVING TIME addition.
```
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -1200,7 +1201,7 @@ SELECT SINGLE
CAST( substring( CAST( @tmstamp AS CHAR ), 9, 6 ) AS TIMS ) AS time,
'ABAP' AS txt "Untyped literal
WHERE TimeZoneID = CAST( char`EST` AS CHAR( 6 ) )
INTO @DATA(wa_some_typed_literal).
INTO @DATA(wa_some_typed_literals).
```
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -1317,4 +1318,12 @@ Find examples in the ABAP Keyword Documentation and a small selection of functio
- [Date and Time Processing](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendate_time_processing.htm)
- In [ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_for_cloud_dev_glosry.htm), do not use the date and time-related system fields such as `sy-datum`, `sy-uzeit`, `sy-timlo`, and `sy-datlo`.
<p align="right"><a href="#top">⬆️ back to top</a></p>
<p align="right"><a href="#top">⬆️ back to top</a></p>
## Executable Example
[zcl_demo_abap_date_time](./src/zcl_demo_abap_date_time.clas.abap)
> **💡 Note**<br>
> - The executable example covers the handling and processing of date, time, and time stamps. The snippets of this cheat sheets are included, as well as an excursion (*ABAP stopwatch*).
> - The steps to import and run the code are outlined [here](README.md#-getting-started-with-the-examples).
> - [Disclaimer](README.md#%EF%B8%8F-disclaimer)

View File

@@ -82,7 +82,7 @@ ABAP cheat sheets[^1] ...
|[Selection Screens and Classic Lists](20_Selection_Screens_Lists.md)|Provides a high-level overview of selection screens and classic lists with a focus on related statements. It includes an excursion into the SAP List Viewer (ALV). <br> 💡 The content of this cheat sheet and the executable examples are only relevant to [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm).|Program `ZDEMO_ABAP_SELSCR_LISTS_INTRO` (the "intro" program, from which the other related example programs can be started)|
|[Working with XML and JSON in ABAP](21_XML_JSON.md)|Covers processing XML using class libraries, XML transformations using XSLT and Simple Transformations (ST), serializations (ABAP to XML) and deserializations (XML to ABAP), dealing with JSON data|[zcl_demo_abap_xml_json](./src/zcl_demo_abap_xml_json.clas.abap)|
|[Misc ABAP Classes](22_Misc_ABAP_Classes.md)|Contains a selection of ABAP classes, serving as a quick introduction, along with code snippets to explore the functionality in action|-|
|[Date, Time, and Time Stamp](23_Date_and_Time.md)|Covers how to handle and process dates, times, and time stamps in ABAP|-|
|[Date, Time, and Time Stamp](23_Date_and_Time.md)|Covers how to handle and process dates, times, and time stamps in ABAP|[zcl_demo_abap_date_time](./src/zcl_demo_abap_date_time.clas.abap)|
<br>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,133 @@
"Note: This ABAP stopwatch is not intended to be used productively.
"The implementation is intended to be a playground for exploring
"time-related functions.
CLASS lcl_stopwatch DEFINITION.
PUBLIC SECTION.
CLASS-METHODS create
RETURNING
VALUE(sw_inst) TYPE REF TO lcl_stopwatch.
METHODS stop.
METHODS start.
METHODS store.
TYPES: BEGIN OF stored_times_struc,
interval TYPE i,
time_since_start TYPE string,
time_delta TYPE string,
END OF stored_times_struc.
TYPES stored_times_type TYPE SORTED TABLE OF stored_times_struc WITH UNIQUE KEY interval.
METHODS get_stored_times RETURNING VALUE(time) TYPE stored_times_type .
METHODS get_time RETURNING VALUE(time) TYPE string .
PROTECTED SECTION.
PRIVATE SECTION.
DATA time_start TYPE utclong.
DATA time_stop TYPE utclong.
DATA stopwatch_is_on TYPE abap_bool.
DATA interval_timer_is_on TYPE abap_bool.
TYPES: BEGIN OF time_struc,
days TYPE i,
hours TYPE i,
minutes TYPE int8,
seconds TYPE decfloat34,
END OF time_struc.
DATA time_elapsed TYPE time_struc.
TYPES cl2 TYPE c LENGTH 2.
DATA storage TYPE TABLE OF utclong WITH EMPTY KEY.
METHODS reset.
METHODS get_elapsed_time
IMPORTING start TYPE utclong
stop TYPE utclong
RETURNING VALUE(delta) TYPE time_struc.
METHODS time_output_prep
IMPORTING time TYPE time_struc
RETURNING VALUE(res) TYPE string.
ENDCLASS.
CLASS lcl_stopwatch IMPLEMENTATION.
METHOD create.
sw_inst = NEW #( ).
sw_inst->reset( ).
ENDMETHOD.
METHOD start.
"No multiple starts allowed
ASSERT stopwatch_is_on = abap_false.
ASSERT interval_timer_is_on = abap_false.
reset( ).
stopwatch_is_on = abap_true.
time_start = utclong_current( ).
ENDMETHOD.
METHOD stop.
ASSERT stopwatch_is_on = abap_true.
time_stop = utclong_current( ).
stopwatch_is_on = abap_false.
interval_timer_is_on = abap_false.
time_elapsed = get_elapsed_time( start = time_start
stop = time_stop ).
ENDMETHOD.
METHOD reset.
CLEAR: time_start,
time_stop,
time_elapsed,
stopwatch_is_on,
interval_timer_is_on,
storage.
ENDMETHOD.
METHOD get_elapsed_time.
cl_abap_utclong=>diff( EXPORTING high = stop
low = start
IMPORTING days = delta-days
hours = delta-hours
minutes = delta-minutes
seconds = delta-seconds ).
ENDMETHOD.
METHOD get_time.
"When the interval timer is on, it is not allowed to
"get the time. The get_stored_times method is to be used.
ASSERT interval_timer_is_on = abap_false.
IF stopwatch_is_on = abap_true.
stop( ).
ENDIF.
time = time_output_prep( time_elapsed ).
ENDMETHOD.
METHOD time_output_prep.
res = |{ COND #( WHEN time-days IS NOT INITIAL THEN time-days && ` days, ` ) }| &&
|{ COND #( WHEN numofchar( CONV cl2( time-hours ) ) = 1 THEN `0` && time-hours ELSE time-hours ) }:| &&
|{ COND #( WHEN numofchar( CONV cl2( time-minutes ) ) = 1 THEN `0` && time-minutes ELSE time-minutes ) }:| &&
|{ COND #( WHEN find( val = CONV string( time-seconds ) sub = `.` ) = 1 THEN `0` && time-seconds ELSE time-seconds ) }|.
ENDMETHOD.
METHOD store.
ASSERT stopwatch_is_on = abap_true.
interval_timer_is_on = abap_true.
APPEND utclong_current( ) TO storage.
ENDMETHOD.
METHOD get_stored_times.
IF interval_timer_is_on = abap_true.
stop( ).
ENDIF.
if lines( storage ) > 0.
LOOP AT storage REFERENCE INTO DATA(ref).
DATA(tabix) = sy-tabix.
DATA(time_since_start) = get_elapsed_time( start = time_start stop = ref->* ).
DATA(prep_time_since_start) = time_output_prep( time_since_start ).
DATA(time_delta) = get_elapsed_time( start = COND #( WHEN tabix = 1 THEN time_start ELSE storage[ tabix - 1 ] ) stop = ref->* ).
DATA(prep_time_delta) = time_output_prep( time_delta ).
INSERT VALUE #( interval = tabix
time_since_start = prep_time_since_start
time_delta = prep_time_delta ) INTO TABLE time.
ENDLOOP.
endif.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_DATE_TIME</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: Date, Time, and Time Stamp</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>