Update
This commit is contained in:
@@ -1639,7 +1639,7 @@ DATA(s2) = |{ some_string WIDTH = 10 ALIGN = (right) }<---|. "' ##<---'
|
||||
|
||||
"The following example uses method chaining with methods of the class
|
||||
"cl_abap_random_int to get a random integer value (in the range of 1 - 3).
|
||||
"The get_next method has a returning parameter, and returns and integer value.
|
||||
"The get_next method has a returning parameter, and returns an integer value.
|
||||
DO 5 TIMES.
|
||||
DATA(s3) = |{ some_string WIDTH = 10 ALIGN = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
|
||||
min = 1 max = 3 )->get_next( ) }<---|.
|
||||
@@ -1821,9 +1821,9 @@ DATA elemdobj TYPE elemtype.
|
||||
DATA strucdobj TYPE structype.
|
||||
DATA tabledobj TYPE strtabtype.
|
||||
|
||||
DATA(tdo_by_data_elem) = cl_abap_typedescr=>describe_by_data( 'ELEMTYPE' ).
|
||||
DATA(tdo_by_data_struc) = cl_abap_typedescr=>describe_by_data( 'STRUCTYPE' ).
|
||||
DATA(tdo_by_data_itab) = cl_abap_typedescr=>describe_by_data( 'STRTABTYPE' ).
|
||||
DATA(tdo_by_data_elem) = cl_abap_typedescr=>describe_by_data( elemdobj ).
|
||||
DATA(tdo_by_data_struc) = cl_abap_typedescr=>describe_by_data( strucdobj ).
|
||||
DATA(tdo_by_data_itab) = cl_abap_typedescr=>describe_by_data( tabledobj ).
|
||||
|
||||
"... using the cl_abap_typedescr=>describe_by_data_ref method
|
||||
"In this case, a data reference variable is used.
|
||||
|
||||
@@ -258,6 +258,7 @@ embedded ABAP
|
||||
[expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenexpression_glosry.htm "Glossary Entry")
|
||||
within a pair of delimiters (`|...|`) if these expressions can be converted to `string`.
|
||||
- To embed expressions, you enclose them in curly brackets: `{ ... }`.
|
||||
- Among the expressions that can be specified in the curly brackets are data objects and [functional method calls](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfunctional_method_call_glosry.htm) that have a [return value](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreturn_value_glosry.htm). The expression result must be convertible to type `string`.
|
||||
|
||||
> **💡 Note**<br>
|
||||
> - String templates form a [string
|
||||
@@ -278,6 +279,33 @@ DATA(s3) = |{ s1 } { s2 }|. "Hallo NAME! How are you?
|
||||
|
||||
"Chaining of string templates using &&
|
||||
DATA(s4) = |{ s1 }| && ` ` && |{ s2 }|. "Hallo NAME! How are you?
|
||||
|
||||
"Selection of possible expressions:
|
||||
"Data objects, as in the examples above
|
||||
DATA(dobj1) = `Hallo`.
|
||||
DATA(dobj2) = '!'.
|
||||
|
||||
"Hallo!
|
||||
DATA(s5) = |{ dobj1 }{ dobj2 }|.
|
||||
|
||||
"NOT INITIAL
|
||||
DATA(s6) = |{ COND #( WHEN s5 IS INITIAL THEN `INITIAL` ELSE `NOT INITIAL` ) }|.
|
||||
|
||||
"Functional method calls, built-in functions
|
||||
"Your user alias: XXXX...
|
||||
DATA(s7) = |Your user alias: { cl_abap_context_info=>get_user_alias( ) }|.
|
||||
|
||||
"Some random number: 39 (example)
|
||||
DATA(s8) = |Some random number: { cl_abap_random_int=>create( seed = cl_abap_random=>seed( ) min = 1 max = 100 )->get_next( ) }|.
|
||||
|
||||
"Length of string s5: 6
|
||||
DATA(s9) = |Length of string s5: { strlen( s5 ) }|.
|
||||
|
||||
"Current UTC time stamp: 2024-01-11 14:27:54.1514090 (example)
|
||||
DATA(s10) = |Current UTC time stamp: { utclong_current( ) }|.
|
||||
|
||||
"HALLO!
|
||||
DATA(s11) = |{ to_upper( s5 ) }|.
|
||||
```
|
||||
|
||||
- String templates interpret certain character combinations as [control
|
||||
|
||||
@@ -1471,6 +1471,10 @@ Typed literal:
|
||||
- Literal whose data types is defined by specifying a [built-in dictionary type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_builtin_types.htm) explicitly.
|
||||
- Available for most but not all ABAP Dictionary data types.
|
||||
- Can be used in ABAP SQL and in ABAP CDS.
|
||||
- Advantages of typed literals over untyped literals
|
||||
- Allow type-safe use of literals
|
||||
- Eliminate the need for (implicit type) conversions and casts, which can lead to surprising or erroneous results; also consider the conversion costs in terms of performance (typed literals are passed to the database and evaluated there without ABAP-specific type conversions).
|
||||
- For better readability (you can immediately see what type is being used)
|
||||
- More information: Typed literals in [ABAP SQL](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_typed_literals.htm) ([cast expressions in ABAP SQL](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_cast.htm)) and [ABAP CDS](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_typed_literal_v2.htm)
|
||||
|
||||
```abap
|
||||
@@ -1512,7 +1516,7 @@ SELECT SINGLE
|
||||
"Untyped literal
|
||||
'ABAP' AS txt
|
||||
WHERE fldate = dats`20240102`
|
||||
INTO @DATA(wa_misc_typed_literal).
|
||||
INTO @DATA(wa_misc_typed_literals).
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
@@ -476,7 +476,7 @@ DATA(random_num1) = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
|
||||
min = 1
|
||||
max = 100 ).
|
||||
DO 3 TIMES.
|
||||
APPEND random_num1->get_next( ) TO int_tab.
|
||||
APPEND random_num1->get_next( ) TO int_tab.
|
||||
ENDDO.
|
||||
|
||||
"Getting a random integer in one go using method chaining
|
||||
@@ -788,7 +788,7 @@ DATA(comp) = xco_cp=>string( `some_value` )->split( `_` )->compose( xco_cp_strin
|
||||
"some_value
|
||||
DATA(decomp) = xco_cp=>string( `someValue` )->decompose( xco_cp_string=>decomposition->camel_case )->join( `_` )->value.
|
||||
|
||||
"------ Processing Base64 Representations of Raw Binary Data ------
|
||||
"------ Processing Base64 representations of raw binary data ------
|
||||
DATA(a_string) = `Hello world`.
|
||||
"string -> xstring
|
||||
"Result: 48656C6C6F20776F726C64
|
||||
|
||||
@@ -29,10 +29,7 @@
|
||||
- [`CL_ABAP_TSTMP`: Calculating and Converting Time Stamps in Packed Numbers](#cl_abap_tstmp-calculating-and-converting-time-stamps-in-packed-numbers)
|
||||
- [Excursion: Unix Time Stamps](#excursion-unix-time-stamps)
|
||||
- [Date, Time, and Time Stamps in String Templates](#date-time-and-time-stamps-in-string-templates)
|
||||
- [Excursions](#excursions)
|
||||
- [Typed Literals in ABAP SQL](#typed-literals-in-abap-sql)
|
||||
- [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)
|
||||
- [Excursion: Date and Time Functions in ABAP SQL and ABAP CDS](#excursion-date-and-time-functions-in-abap-sql-and-abap-cds)
|
||||
- [More Information](#more-information)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
@@ -1152,14 +1149,11 @@ tz_str = |{ utclong_current( ) TIMEZONE = 'EST' COUNTRY = 'US ' }|. "12/30/2024
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Excursions
|
||||
### Typed Literals in ABAP SQL
|
||||
## Excursion: Date and Time Functions in ABAP SQL and ABAP CDS
|
||||
|
||||
The following code snippets use [typed literals](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentyped_literal_glosry.htm). For more information, refer to the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_typed_literals.htm) and the [Typed Literals in ABAP SQL](/16_Data_Types_and_Objects.md#typed-literals-in-abap-sql) section of the *Data Types and Data Objects* cheat sheet.
|
||||
|
||||
### Date and Time Functions in ABAP SQL
|
||||
|
||||
More information: [Date Functions and Time Functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_date_time_functions.htm)
|
||||
> **💡 Note**<br>
|
||||
> - Date and time functions are available for both [ABAP SQL](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_date_time_functions.htm) and [ABAP CDS](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_date_time_functions_v2.htm). They have the same names. See the [overview](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_date_time_functions.htm) to find out which functions are available. The followig code snippet uses ABAP SQL.
|
||||
> - The following code snippets use [typed literals](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentyped_literal_glosry.htm) to have self-contained examples. For more information, refer to the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_typed_literals.htm) and the [Typed Literals in ABAP SQL](/16_Data_Types_and_Objects.md#typed-literals-in-abap-sql) section of the *Data Types and Data Objects* cheat sheet.
|
||||
|
||||
```abap
|
||||
"The following demo ABAP SQL SELECT statement selects from a
|
||||
@@ -1253,17 +1247,6 @@ INTO @DATA(wa).
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Date and Time Functions in ABAP CDS
|
||||
Date and time functions are available for [ABAP CDS](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_cds_glosry.htm). They have the same names as the functions in ABAP SQL. See the [overview](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_date_time_functions.htm) to find out which functions are available.
|
||||
|
||||
More information:
|
||||
- [Date and time functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_date_time_functions_v2.htm)
|
||||
- [Overview of date and time functions for ABAP SQL and ABAP CDS](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_date_time_functions.htm)
|
||||
|
||||
Find examples in the ABAP Keyword Documentation and a small selection of functions in the examples of the CDS view entities cheat sheet in [this example artifact](src/zdemo_abap_cds_ve_sel.ddls.asddls).
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## More Information
|
||||
|
||||
- [Date and Time Processing](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendate_time_processing.htm)
|
||||
|
||||
@@ -1308,7 +1308,7 @@ DATA(line_index2) = line_index( itab_em[ comp2 = 'd' ] ).
|
||||
"Note: A hashed table does not have a primary table index. The result is -1.
|
||||
DATA(line_index3) = line_index( itab_sec[ KEY primary_key comp1 = 1 ] ).
|
||||
|
||||
"Hashed tables can be assigned a secondary table index using a seoncary
|
||||
"Hashed tables can be assigned a secondary table index using a secondary
|
||||
"table key.
|
||||
"4
|
||||
DATA(line_index4) = line_index( itab_sec[ KEY sk comp2 = 'd' ] ).
|
||||
@@ -1415,7 +1415,7 @@ SELECT SINGLE
|
||||
"case-sensitive by default (case_sensitive parameter can be specified)
|
||||
"Notes on the 1 = found, 0 = not found
|
||||
"1
|
||||
like_regexpr( pcre = '\..', "Period that is followed by any character
|
||||
like_regexpr( pcre = '\..', "Period that is followed by any character
|
||||
value = url ) AS like_regex,
|
||||
|
||||
"Returns position of a substring in an expression,
|
||||
@@ -1427,15 +1427,15 @@ SELECT SINGLE
|
||||
"Searches a PCRE pattern, returns offset of match;
|
||||
"many optional parameters: occurrence, case_sensitive, start, group
|
||||
"21
|
||||
locate_regexpr( pcre = '\..', "Period followed by any character
|
||||
locate_regexpr( pcre = '\..', "Period followed by any character
|
||||
value = url,
|
||||
occurrence = 2 ) "2nd occurrence in the string
|
||||
occurrence = 2 ) "2nd occurrence in the string
|
||||
AS locate_regexpr,
|
||||
|
||||
"Searches a PCRE pattern, returns offset of match + 1;
|
||||
"many optional parameters: occurrence, case_sensitive, start, group
|
||||
"2
|
||||
locate_regexpr_after( pcre = '.', "Any character
|
||||
locate_regexpr_after( pcre = '.', "Any character
|
||||
value = url,
|
||||
occurrence = 1 ) AS locate_regexpr_after,
|
||||
|
||||
@@ -1446,7 +1446,7 @@ SELECT SINGLE
|
||||
|
||||
"Counts all occurrences of found PCRE patterns
|
||||
"2
|
||||
occurrences_regexpr( pcre = '\..', "Period that is followed by any character
|
||||
occurrences_regexpr( pcre = '\..', "Period that is followed by any character
|
||||
value = url ) AS occ_regex,
|
||||
|
||||
"Replaces the 2nd argument with the 3rd in an expression
|
||||
@@ -1456,7 +1456,7 @@ SELECT SINGLE
|
||||
"Replaces a found PCRE expression;
|
||||
"more parameters possible: occurrence, case_sensitive, start
|
||||
"http://www#ufthansa#om
|
||||
replace_regexpr( pcre = '\..', "Period that is followed by any character
|
||||
replace_regexpr( pcre = '\..', "Period that is followed by any character
|
||||
value = url,
|
||||
with = '#' ) AS replace_regex,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user