Update
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
- [Improving Read Performance with Secondary Table Keys](#improving-read-performance-with-secondary-table-keys)
|
||||
- [Searching and Replacing Substrings in Internal Tables with Character-Like Data Types](#searching-and-replacing-substrings-in-internal-tables-with-character-like-data-types)
|
||||
- [Ranges Tables](#ranges-tables)
|
||||
- [Getting Table Type Information and Creating Internal Tables at Runtime](#getting-table-type-information-and-creating-internal-tables-at-runtime)
|
||||
- [More Information](#more-information)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
@@ -1708,6 +1709,17 @@ SELECT * FROM @inttab AS tab
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Getting Table Type Information and Creating Internal Tables at Runtime
|
||||
|
||||
Using [Runtime Type Services (RTTS)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_services_glosry.htm "Glossary Entry")
|
||||
you can ...
|
||||
- get type information on data objects, data types or [instances](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninstance_glosry.htm "Glossary Entry") at runtime ([Runtime Type Identification (RTTI)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm "Glossary Entry")).
|
||||
- define and create new data types as [type description objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentype_object_glosry.htm) at runtime ([Runtime Type Creation (RTTC)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_creation_glosry.htm "Glossary Entry")).
|
||||
|
||||
For more information, see the [Dynamic Programming](06_Dynamic_Programming.md) cheat sheet.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## More Information
|
||||
Topic [Internal Tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenitab.htm) in the ABAP Keyword Documentation.
|
||||
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
- [Using the CORRESPONDING Operator and MOVE-CORRESPONDING Statements](#using-the-corresponding-operator-and-move-corresponding-statements)
|
||||
- [Clearing Structures](#clearing-structures)
|
||||
- [Processing Structures](#processing-structures)
|
||||
- [Excursion: Including Structures](#excursion-including-structures)
|
||||
- [Excursions](#excursions)
|
||||
- [Including Structures](#including-structures)
|
||||
- [Getting Structured Type Information and Creating Structures at Runtime](#getting-structured-type-information-and-creating-structures-at-runtime)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
## Introduction
|
||||
@@ -670,7 +672,9 @@ MODIFY TABLE itab FROM struc.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Excursion: Including Structures
|
||||
## Excursions
|
||||
|
||||
### Including Structures
|
||||
|
||||
- [`INCLUDE TYPE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapinclude_type.htm)
|
||||
and [`INCLUDE STRUCTURE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapinclude_type.htm) statements
|
||||
@@ -710,9 +714,20 @@ TYPES BEGIN OF address_type.
|
||||
TYPES END OF address_type.
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Getting Structured Type Information and Creating Structures at Runtime
|
||||
|
||||
Using [Runtime Type Services (RTTS)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_services_glosry.htm "Glossary Entry")
|
||||
you can ...
|
||||
- get type information on data objects, data types or [instances](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninstance_glosry.htm "Glossary Entry") at runtime ([Runtime Type Identification (RTTI)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm "Glossary Entry")).
|
||||
- define and create new data types as [type description objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentype_object_glosry.htm) at runtime ([Runtime Type Creation (RTTC)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_creation_glosry.htm "Glossary Entry")).
|
||||
|
||||
For more information, see the [Dynamic Programming](06_Dynamic_Programming.md) cheat sheet.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
|
||||
## Executable Example
|
||||
[zcl_demo_abap_structures](./src/zcl_demo_abap_structures.clas.abap)
|
||||
|
||||
|
||||
@@ -1126,68 +1126,176 @@ ENDCASE.
|
||||
## FILTER
|
||||
|
||||
- The
|
||||
`FILTER` operator constructs an internal table according to a specified type (which can be an explicitly specified, non-generic table type or the # character as a symbol for the [operand type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenoperand_type_glosry.htm) before the first parenthesis).
|
||||
[`FILTER`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_filter.htm) operator constructs an internal table according to a specified type (which can be an explicitly specified, non-generic table type or the `#` character as a symbol for the [operand type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenoperand_type_glosry.htm) before the first parenthesis).
|
||||
- The lines for the new internal table are taken from an
|
||||
existing internal table based on conditions specified in a `WHERE` clause. Note that the table type of the existing internal table must be convertible to the specified target type.
|
||||
existing internal table based on conditions specified in a `WHERE` condition. Note that the table type of the existing internal table must be convertible to the specified target type.
|
||||
- The conditions can either be based on single values or a [filter
|
||||
table](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expr_filter_table.htm).
|
||||
- Additions:
|
||||
|
||||
|Addition |Details |
|
||||
|---|---|
|
||||
|`USING KEY` | Specifies the [table key](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentable_key_glosry.htm "Glossary Entry") with which the `WHERE` condition is evaluated: either a [sorted key](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensorted_key_glosry.htm "Glossary Entry") or a [hash key](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhash_key_glosry.htm "Glossary Entry"). If the internal table has neither of them, a [secondary table key](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensecondary_table_key_glosry.htm "Glossary Entry") must be available for the internal table which must then be specified after `USING KEY`. |
|
||||
| `EXCEPT` | The specification of `EXCEPT` means that those lines of the existing table are used that do not meet the condition specified in the `WHERE` clause. Hence, if `EXCEPT` is not specified, the lines of the existing table are used that meet the condition. |
|
||||
- The source table must have at least one [sorted key](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensorted_key_glosry.htm "Glossary Entry") or a [hash key](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhash_key_glosry.htm "Glossary Entry") for accessing. If the table does not have such a primary table key, a [secondary table key](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensecondary_table_key_glosry.htm "Glossary Entry") must be available.
|
||||
- Syntax options for the using the table key (i.e. specifying its components):
|
||||
- Using the [primary table key](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenprimary_table_key_glosry.htm) without the `USING KEY` addition
|
||||
- Using the default name `primary_key` for the primary key with `USING KEY`
|
||||
- Using the secondary table key with `USING KEY`
|
||||
- Notes on the `WHERE` condition:
|
||||
- The conditions for the table key components can be specified as follows:
|
||||
- Hash keys: Only the comparison operator `=` is allowed
|
||||
- Sorted key: `=`/`EQ`, `<>`/`NE`, `<`/`LT`, `>`/`GT`, `<=`/`LE`, `>=`/`GE`
|
||||
- Multiple comparisons can be combined using `AND`; boolean operators such as `NOT` or `OR` cannot be specified.
|
||||
- Notes on the filter table:
|
||||
- The line types of the source and filter table need not be identical.
|
||||
- Refer to the [documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expr_filter_table.htm) for all syntax options. For example, depending on where `USING KEY` is specified, the table key is specified for the source or filter table for the access.
|
||||
- Notes on the `EXCEPT` addition: The specification of `EXCEPT` means that those lines of the table are used that do not meet the condition specified in the `WHERE` condition. Therefore, if `EXCEPT` is not specified, the lines of the table are used that meet the condition.
|
||||
|
||||
|
||||
Examples:
|
||||
```abap
|
||||
"FILTER and conditions based on single values
|
||||
"Assumption the component num is of type i.
|
||||
DATA itab1 TYPE SORTED TABLE OF struc WITH NON-UNIQUE KEY num.
|
||||
DATA itab2 TYPE STANDARD TABLE OF struc WITH NON-UNIQUE SORTED KEY sec_key COMPONENTS num.
|
||||
DATA itab3 TYPE HASHED TABLE OF struc WITH UNIQUE KEY num.
|
||||
"Internal tables to work with in the example
|
||||
TYPES: BEGIN OF fi_str,
|
||||
a TYPE i,
|
||||
b TYPE c LENGTH 3,
|
||||
c TYPE c LENGTH 3,
|
||||
END OF fi_str.
|
||||
|
||||
"The lines meeting the condition are respected.
|
||||
"Note: The source table must have at least one sorted or hashed key.
|
||||
"Here, the primary key is used
|
||||
DATA(f1) = FILTER #( itab1 WHERE num >= 3 ).
|
||||
DATA fi_tab1 TYPE SORTED TABLE OF fi_str WITH NON-UNIQUE KEY a.
|
||||
DATA fi_tab2 TYPE STANDARD TABLE OF fi_str WITH NON-UNIQUE SORTED KEY sec_key COMPONENTS a.
|
||||
DATA fi_tab3 TYPE HASHED TABLE OF fi_str WITH UNIQUE KEY a.
|
||||
DATA fi_tab4 TYPE STANDARD TABLE OF fi_str WITH UNIQUE HASHED KEY sec_hash_key COMPONENTS a b.
|
||||
|
||||
"USING KEY primary_key explicitly specified; same as above
|
||||
DATA(f2) = FILTER #( itab1 USING KEY primary_key WHERE num >= 3 ).
|
||||
"Populating internal tables with demo data
|
||||
fi_tab1 = VALUE #( ( a = 1 b = 'aaa' c = 'abc' )
|
||||
( a = 2 b = 'bbb' c = 'def' )
|
||||
( a = 3 b = 'ccc' c = 'hij' )
|
||||
( a = 4 b = 'ddd' c = 'klm' )
|
||||
( a = 5 b = 'eee' c = 'nop' ) ).
|
||||
|
||||
"EXCEPT addition
|
||||
DATA(f3) = FILTER #( itab1 EXCEPT WHERE num >= 3 ).
|
||||
DATA(f4) = FILTER #( itab1 EXCEPT USING KEY primary_key WHERE num >= 3 ).
|
||||
fi_tab2 = fi_tab1.
|
||||
fi_tab3 = fi_tab1.
|
||||
fi_tab4 = fi_tab1.
|
||||
|
||||
"Secondary table key specified after USING KEY
|
||||
DATA(f5) = FILTER #( itab2 USING KEY sec_key WHERE num >= 4 ).
|
||||
DATA(f6) = FILTER #( itab2 EXCEPT USING KEY sec_key WHERE num >= 3 ).
|
||||
"---------------- Basic form: Filtering using single values ----------------
|
||||
"Syntax options for using a WHERE condition and the table key
|
||||
|
||||
"Note: In case of a hash key, exactly one comparison expression for each key component is allowed;
|
||||
"only = as comparison operator possible.
|
||||
DATA(f7) = FILTER #( itab3 WHERE num = 3 ).
|
||||
"Using the primary table key without specifying USING KEY
|
||||
DATA(f1) = FILTER #( fi_tab1 WHERE a >= 4 ).
|
||||
|
||||
"Using a filter table
|
||||
"In the WHERE condition, the columns of source and filter table are compared. Those lines in the source table
|
||||
"are used for which at least one line in the filter table meets the condition. EXCEPT and USING KEY are also possible.
|
||||
*A B C
|
||||
*4 ddd klm
|
||||
*5 eee nop
|
||||
|
||||
DATA filter_tab1 TYPE SORTED TABLE OF i
|
||||
WITH NON-UNIQUE KEY table_line.
|
||||
"Using the primary table key by specifying the default name primary_key
|
||||
"and specifying USING KEY; the result in the example is the same as above
|
||||
DATA(f2) = FILTER #( fi_tab1 USING KEY primary_key WHERE a >= 4 ).
|
||||
|
||||
DATA filter_tab2 TYPE STANDARD TABLE OF i
|
||||
WITH EMPTY KEY
|
||||
WITH UNIQUE SORTED KEY line COMPONENTS table_line.
|
||||
*A B C
|
||||
*4 ddd klm
|
||||
*5 eee nop
|
||||
|
||||
DATA(f8) = FILTER #( itab1 IN filter_tab1 WHERE num = table_line ).
|
||||
"Using the secondary table key by specifying its name and USING KEY
|
||||
DATA(f3) = FILTER #( fi_tab2 USING KEY sec_key WHERE a < 3 ).
|
||||
|
||||
"EXCEPT addition
|
||||
DATA(f9) = FILTER #( itab1 EXCEPT IN filter_tab1 WHERE num = table_line ).
|
||||
*A B C
|
||||
*1 aaa abc
|
||||
*2 bbb def
|
||||
|
||||
"USING KEY is specified for the filter table
|
||||
DATA(f10) = FILTER #( itab2 IN filter_tab2 USING KEY line WHERE num = table_line ).
|
||||
"Note: When using a table with hash key, only the comparison operator =
|
||||
"can be used in the WHERE clause
|
||||
"The example uses the primary table key, which is a hash key.
|
||||
DATA(f4) = FILTER #( fi_tab3 WHERE a = 3 ).
|
||||
|
||||
"USING KEY is specified for the source table, including EXCEPT
|
||||
DATA(f11) = FILTER #( itab2 USING KEY sec_key EXCEPT IN filter_tab2 WHERE num = table_line ).
|
||||
*A B C
|
||||
*3 ccc hij
|
||||
|
||||
"The example table used in the following example has two components specified
|
||||
"for the table key. The key must be specified in full listing all components
|
||||
"and using AND.
|
||||
DATA(f5) = FILTER #( fi_tab4 USING KEY sec_hash_key WHERE a = 3 AND b = 'ccc' ).
|
||||
|
||||
*A B C
|
||||
*3 ccc hij
|
||||
|
||||
"Examples with the EXCEPT addition
|
||||
DATA(f6) = FILTER #( fi_tab1 EXCEPT WHERE a >= 4 ).
|
||||
|
||||
*A B C
|
||||
*1 aaa abc
|
||||
*2 bbb def
|
||||
*3 ccc hij
|
||||
|
||||
DATA(f7) = FILTER #( fi_tab1 EXCEPT USING KEY primary_key WHERE a >= 4 ).
|
||||
|
||||
*A B C
|
||||
*1 aaa abc
|
||||
*2 bbb def
|
||||
*3 ccc hij
|
||||
|
||||
"Secondary table key specified after USING KEY
|
||||
DATA(f8) = FILTER #( fi_tab2 USING KEY sec_key WHERE a <= 2 ).
|
||||
|
||||
*A B C
|
||||
*1 aaa abc
|
||||
*2 bbb def
|
||||
|
||||
DATA(f9) = FILTER #( fi_tab2 EXCEPT USING KEY sec_key WHERE a >= 4 ).
|
||||
|
||||
*A B C
|
||||
*1 aaa abc
|
||||
*2 bbb def
|
||||
*3 ccc hij
|
||||
|
||||
DATA(f10) = FILTER #( fi_tab4 EXCEPT USING KEY sec_hash_key WHERE a = 3 AND b = 'ccc' ).
|
||||
|
||||
*A B C
|
||||
*1 aaa abc
|
||||
*2 bbb def
|
||||
*4 ddd klm
|
||||
*5 eee nop
|
||||
|
||||
"---------------- Basic form: Filtering using a filter table ----------------
|
||||
|
||||
"In the WHERE condition, the columns of source and filter table are compared.
|
||||
"Those lines in the source table are used for which at least one line in the
|
||||
"filter table meets the condition. EXCEPT and USING KEY are also possible.
|
||||
"The following examples use simple tables with elementary line types. Note
|
||||
"that the line types of the tables in a FILTER epxression need not be identical.
|
||||
"Declaring and filling filter tables
|
||||
DATA filter_tab1 TYPE SORTED TABLE OF i WITH NON-UNIQUE KEY table_line.
|
||||
|
||||
DATA filter_tab2 TYPE STANDARD TABLE OF i
|
||||
WITH EMPTY KEY
|
||||
WITH UNIQUE SORTED KEY line COMPONENTS table_line.
|
||||
|
||||
filter_tab1 = VALUE #( ( 3 ) ( 5 ) ).
|
||||
filter_tab2 = filter_tab1.
|
||||
|
||||
"No further additions specified
|
||||
DATA(f11) = FILTER #( fi_tab1 IN filter_tab1 WHERE a = table_line ).
|
||||
|
||||
*A B C
|
||||
*3 ccc hij
|
||||
*5 eee nop
|
||||
|
||||
"Specifying EXCEPT addition
|
||||
DATA(f12) = FILTER #( fi_tab1 EXCEPT IN filter_tab1 WHERE a = table_line ).
|
||||
|
||||
*A B C
|
||||
*1 aaa abc
|
||||
*2 bbb def
|
||||
*4 ddd klm
|
||||
|
||||
"Specifying USING KEY for the filter table
|
||||
DATA(f13) = FILTER #( fi_tab2 IN filter_tab2 USING KEY line WHERE a = table_line ).
|
||||
|
||||
*A B C
|
||||
*3 ccc hij
|
||||
*5 eee nop
|
||||
|
||||
"Specifying USING KEY for the source table, including EXCEPT
|
||||
DATA(f14) = FILTER #( fi_tab2 USING KEY sec_key EXCEPT IN filter_tab2 WHERE a = table_line ).
|
||||
|
||||
*A B C
|
||||
*1 aaa abc
|
||||
*2 bbb def
|
||||
*4 ddd klm
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
@@ -1091,23 +1091,22 @@ DATA(gen_comp) = CONV string( <gen>-('COL2') ).
|
||||
DATA struc2string TYPE string.
|
||||
FIELD-SYMBOLS <strco> TYPE data.
|
||||
ASSIGN st TO <strco>.
|
||||
IF sy-subrc = 0.
|
||||
TRY.
|
||||
DATA(comps) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( <strco> ) )->components.
|
||||
DO.
|
||||
TRY.
|
||||
DATA(comp_name) = comps[ sy-index ]-name.
|
||||
struc2string = struc2string &&
|
||||
COND #( WHEN sy-index <> 1 THEN `, ` ) &&
|
||||
comp_name && `: "` &&
|
||||
<strco>-(sy-index) && `"`.
|
||||
CATCH cx_sy_assign_illegal_component cx_sy_itab_line_not_found.
|
||||
EXIT.
|
||||
ENDTRY.
|
||||
ENDDO.
|
||||
CATCH cx_sy_move_cast_error.
|
||||
ENDTRY.
|
||||
ENDIF.
|
||||
|
||||
TRY.
|
||||
DATA(comps) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( <strco> ) )->components.
|
||||
DO.
|
||||
TRY.
|
||||
DATA(comp_name) = comps[ sy-index ]-name.
|
||||
struc2string = struc2string &&
|
||||
COND #( WHEN sy-index <> 1 THEN `, ` ) &&
|
||||
comp_name && `: "` &&
|
||||
<strco>-(sy-index) && `"`.
|
||||
CATCH cx_sy_assign_illegal_component cx_sy_itab_line_not_found.
|
||||
EXIT.
|
||||
ENDTRY.
|
||||
ENDDO.
|
||||
CATCH cx_sy_move_cast_error.
|
||||
ENDTRY.
|
||||
"struc2string: COL1: "123", COL2: "ABAP", COL3: "Z"
|
||||
```
|
||||
|
||||
@@ -1627,7 +1626,7 @@ result = ptab[ name = 'R_TRIPLE' ]-('VALUE')->*. "9
|
||||
### Dynamic Formatting Option Specifications in String Templates
|
||||
|
||||
The following code snippet demonstrates a small selection of dynamic formatting option specifications in string templates.
|
||||
For more details and a complete list of options, refer to the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/abapcompute_string_format_options.htm), especially regarding the expected and supported input (attributes of the `CL_ABAP_FORMAT` class). General information on string templates can also be found there and in the [String Processing](/07_String_Processing.md#string-templates) cheat sheet.
|
||||
For more details and a complete list of options, refer to the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/abapcompute_string_format_options.htm), especially regarding the expected and supported input (attributes of the `CL_ABAP_FORMAT` class). General information on string templates can also be found there and in the [String Processing](07_String_Processing.md#string-templates) cheat sheet.
|
||||
|
||||
```abap
|
||||
"ALIGN
|
||||
|
||||
@@ -150,7 +150,7 @@ DATA: flag TYPE c LENGTH 1, "Built-in type
|
||||
char1 TYPE c_type, "Local type
|
||||
str2 LIKE str1, "Deriving type from a local data object
|
||||
str3 TYPE str_type, "Local type
|
||||
char2 TYPE s_toairp, "DDIC type (used e. g. for a field in a demo table)
|
||||
tstmp TYPE timestampl, "DDIC type
|
||||
char3 TYPE zdemo_abap_flsch-carrid. "Using the type of a DDIC table component
|
||||
|
||||
"You may also encounter declarations with type c and the length
|
||||
@@ -1651,13 +1651,25 @@ Character Sets, Ranges, Subgroups and Lookarounds
|
||||
| `(?!...)` | Negative lookahead, returns characters that are not followed by a specified pattern without including this pattern | `a(?!b)` | abc ade | abc <ins>**a**</ins>de | <ins>**a**</ins>bc ade |
|
||||
| `(?<=...)` | Positive lookbehind, returns characters that are preceded by a specified pattern without including this pattern | `(?<=\s)c` | ab c abcd | ab <ins>**c**</ins> abcd (it is preceded by a blank) | ab c ab<ins>**c**</ins>d |
|
||||
| `(?<!...)` | Negative lookbehind, returns characters that are not preceded by a specified pattern without including this pattern | `(?<!\s)c` | ab c abcd | ab c ab<ins>**c**</ins>d (it is not preceded by a blank) | ab <ins>**c**</ins> abcd |
|
||||
| `\n` | Backreference, refers to a previous capturing group; n represents the number of the group index that starts with 1 | `(a.)(\w*)\1` | abcdefabghij | <ins>**abcdefab**</ins>ghij <br>Note: Capturing group 1 holds `ab` in the example. The second capturing group captures all word characters until `ab` is found. | <ins>**ab**</ins>cdefabghij |
|
||||
| `\1` | Backreference, refers to a previous capturing group; 1 represents the number of the group index (the group index starts with 1) | `(a.)(\w*)\1` | abcdefabghij | <ins>**abcdefab**</ins>ghij <br>Note: Capturing group 1 holds `ab` in the example. The second capturing group captures all word characters until `ab` is found. | <ins>**ab**</ins>cdefabghij |
|
||||
| `\K` | Resets the starting point of a match, i.e. findings are excluded from the final match | `a.\Kc` | abcd | ab<ins>**c**</ins>d | <ins>**abc**</ins>d |
|
||||
|
||||
> **💡 Note**<br>
|
||||
> - Subgroups are useful in replacements. By using an expression with `$` and a number, such as `$1`, you can refer to a specific group. For example, you have a string `abcde`. A PCRE expression might be
|
||||
`(ab|xy)c(d.)`, where two subgroups are specified within two pairs of parentheses. In a replacement pattern, you can refer to the first group with `$1` and the second group with `$2`. Thus, the replacement pattern `$2Z$1` results in `deZab`.
|
||||
> - `(?:x)` creates a group but it is not captured. Example regular expression: `(?:ab)(ap)`. Example string: 'abap'. It matches 'abap', but `$1` will only contain 'ap'.
|
||||
> - Note that `.` does not include new line feeds among others. If you want to capture a new line, you can use `\n` as regular expression. The following example string includes a new line. All content between the HTML p tags should be replaced. You could use a regular expression to capture any character or new line as follows:
|
||||
> ```abap
|
||||
> DATA(str_a) = |<p>Hallo\n</p><p>Ciao!</p><p>Salut.</p>|.
|
||||
> DATA(str_b) = str_a.
|
||||
>
|
||||
> REPLACE ALL OCCURRENCES OF PCRE `(<p>)(.*?)(<\/p>)` IN str_a WITH `$1Hi$3`.
|
||||
> "<p>Hallo
|
||||
> "</p><p>Hi</p><p>Hi</p>
|
||||
>
|
||||
> "Regular expression: any character or a new line with zero or more repretitions
|
||||
> REPLACE ALL OCCURRENCES OF PCRE `(<p>)(.|\n)*?(<\/p>)` IN str_b WITH `$1Hi$3`.
|
||||
> "<p>Hi</p><p>Hi</p><p>Hi</p>
|
||||
|
||||
Anchors and Positions
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
- [BDEF Derived Types](#bdef-derived-types)
|
||||
- [Components of BDEF Derived Types](#components-of-bdef-derived-types)
|
||||
- [Secondary Table Keys of BDEF Derived Types](#secondary-table-keys-of-bdef-derived-types)
|
||||
- [Type Mapping for RAP](#type-mapping-for-rap)
|
||||
- [EML Syntax](#eml-syntax)
|
||||
- [EML Syntax for Modifying Operations](#eml-syntax-for-modifying-operations)
|
||||
- [EML Syntax for Reading Operations](#eml-syntax-for-reading-operations)
|
||||
@@ -884,6 +885,142 @@ DATA(line_e) = itab_cr[ KEY entity %key = VALUE #( key_field = 1 ) ].
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Type Mapping for RAP
|
||||
|
||||
**RAP-Specific Additions to the CORRESPONDING Operator**
|
||||
|
||||
The [`CORRESPONDING`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expr_corresponding.htm) operator offers RAP-specific additions for handling type mappings related to BDEF derived types and other types. For more information, see the [ABAP Keyword Documentation topic](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapeml_type_mapping.htm).
|
||||
|
||||
The following additions are available:
|
||||
```abap
|
||||
... CORRESPONDING ...( ... MAPPING FROM ENTITY ) ...
|
||||
... CORRESPONDING ...( ... MAPPING TO ENTITY ) ...
|
||||
... CORRESPONDING ...( ... USING CONTROL ) ...
|
||||
... CORRESPONDING ...( ... MAPPING FROM ENTITY USING CONTROL ) ...
|
||||
... CORRESPONDING ...( ... CHANGING CONTROL ) ...
|
||||
```
|
||||
|
||||
For some additions, a mapping needs to be specified in the BDEF. For more information, see the
|
||||
[ABAP Keyword Documentation topic](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbdl_type_mapping.htm).
|
||||
|
||||
The following example uses a BDEF derived type from the ABAP cheat sheets. It shows additions that do not require a type mapping to be specified.
|
||||
|
||||
```abap
|
||||
"BDEF derived type
|
||||
DATA derived_type TYPE STRUCTURE FOR UPDATE zdemo_abap_rap_ro_m.
|
||||
|
||||
"Other type
|
||||
"For simplicity, the structure has the same component names
|
||||
"and types to avoid further additions in the statement.
|
||||
DATA: BEGIN OF some_other_type,
|
||||
key_field TYPE i,
|
||||
field1 TYPE c LENGTH 10,
|
||||
field2 TYPE c LENGTH 10,
|
||||
field3 TYPE i,
|
||||
field4 TYPE i,
|
||||
END OF some_other_type.
|
||||
|
||||
derived_type = VALUE #( key_field = 1
|
||||
field1 = 'aaa'
|
||||
field2 = 'bbb'
|
||||
field3 = 2
|
||||
field4 = 3
|
||||
%control = VALUE #( key_field = if_abap_behv=>mk-on
|
||||
field1 = if_abap_behv=>mk-off
|
||||
field2 = if_abap_behv=>mk-on
|
||||
field3 = if_abap_behv=>mk-on
|
||||
field4 = if_abap_behv=>mk-off ) ).
|
||||
|
||||
"-------------------- USING CONTROL addition --------------------
|
||||
"This addition respects the %control component of BDEF derived types, i.e.
|
||||
"only those fields for which the %control field has been marked as enabled
|
||||
"are respected by the mapping. A disabled %control field means that the
|
||||
"mapping is not applied.
|
||||
|
||||
"In the example, components are marked as disabled in %control.
|
||||
"Consequently, the field values are not assigned, and the type-specific
|
||||
"initial values are used.
|
||||
some_other_type = CORRESPONDING #( derived_type USING CONTROL ).
|
||||
|
||||
*KEY_FIELD FIELD1 FIELD2 FIELD3 FIELD4
|
||||
*1 bbb 2 0
|
||||
|
||||
"-------------------- CHANGING CONTROL addition --------------------
|
||||
"This variant fills the %control structure of a BDEF-derived type based on
|
||||
"a non-BDEF-derived type that does not include control information.
|
||||
"In the example, two components are not assigned (i.e. they remain initial).
|
||||
"Consequently, when using the CORRESPONDING operator with CHANGING CONTROL,
|
||||
"the %control values are marked as disabled, the others as enabled.
|
||||
|
||||
some_other_type = VALUE #( key_field = 4 field1 = 'ccc' field4 = 5 ).
|
||||
|
||||
derived_type = CORRESPONDING #( some_other_type CHANGING CONTROL ).
|
||||
|
||||
*%CID_REF KEY_FIELD FIELD1 FIELD2 FIELD3 FIELD4 %CONTROL
|
||||
* 4 ccc 0 5 KEY_FIELD FIELD1 FIELD2 FIELD3 FIELD4
|
||||
* 01 01 00 00 01
|
||||
```
|
||||
|
||||
**ABAP SQL Statements with BDEF Derived Types**
|
||||
|
||||
The ABAP SQL statements `INSERT`, `UPDATE`, `MODIFY`, and `DELETE` offer the [`MAPPING FROM ENTITY`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmapping_from_entity.htmaddition) addition to handle BDEF derived types.
|
||||
|
||||
```abap
|
||||
"--------------- INSERT ---------------
|
||||
"Populating a BDEF derived type
|
||||
DATA cr_der_type TYPE STRUCTURE FOR CREATE zdemo_abap_rap_ro_m.
|
||||
"%control is not relevant in this example
|
||||
cr_der_type = VALUE #( key_field = 1
|
||||
field1 = 'aaa'
|
||||
field2 = 'bbb'
|
||||
field3 = 2
|
||||
field4 = 3 ).
|
||||
|
||||
INSERT zdemo_abap_rapt1 FROM @cr_der_type MAPPING FROM ENTITY.
|
||||
|
||||
*KEY_FIELD FIELD1 FIELD2 FIELD3 FIELD4
|
||||
*1 aaa bbb 2 3
|
||||
|
||||
"--------------- MODIFY ---------------
|
||||
cr_der_type = VALUE #( BASE cr_der_type
|
||||
field1 = 'YYY'
|
||||
field2 = 'ZZZ' ).
|
||||
|
||||
MODIFY zdemo_abap_rapt1 FROM @cr_der_type MAPPING FROM ENTITY.
|
||||
|
||||
*KEY_FIELD FIELD1 FIELD2 FIELD3 FIELD4
|
||||
*1 YYY ZZZ 2 3
|
||||
|
||||
"--- UPDATE with the INDICATORS SET STRUCTURE %control addition ---
|
||||
"Populating a BDEF derived type
|
||||
"%control is relevant in this example. Some %control values are enabled,
|
||||
"some are not.
|
||||
cr_der_type = VALUE #( key_field = 1
|
||||
field1 = '###'
|
||||
field2 = '...'
|
||||
field3 = 100
|
||||
field4 = 200
|
||||
%control = VALUE #( key_field = if_abap_behv=>mk-on
|
||||
field1 = if_abap_behv=>mk-on
|
||||
field2 = if_abap_behv=>mk-off
|
||||
field3 = if_abap_behv=>mk-off
|
||||
field4 = if_abap_behv=>mk-on ) ).
|
||||
|
||||
UPDATE zdemo_abap_rapt1 FROM @cr_der_type
|
||||
INDICATORS SET STRUCTURE %control MAPPING FROM ENTITY.
|
||||
|
||||
"--------------- DELETE ---------------
|
||||
*KEY_FIELD FIELD1 FIELD2 FIELD3 FIELD4
|
||||
*1 ### ZZZ 2 200
|
||||
|
||||
DELETE zdemo_abap_rapt1 FROM @cr_der_type MAPPING FROM ENTITY.
|
||||
```
|
||||
|
||||
> **💡 Note**<br>
|
||||
> More information and ABAP statements: [Type Mapping for RAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapeml_type_mapping.htm)
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## EML Syntax
|
||||
|
||||
The focus is here on selected EML statements. These statements can be
|
||||
@@ -1003,6 +1140,22 @@ MODIFY ENTITIES OF root_ent "full name of root entity
|
||||
MAPPED DATA(m) "Target variables declared inline
|
||||
FAILED DATA(f)
|
||||
REPORTED DATA(r).
|
||||
|
||||
"Note: You can use the AUTO FILL CID addition to fill %cid automatically. It is
|
||||
"also possible in the short form.
|
||||
MODIFY ENTITIES OF root_ent
|
||||
ENTITY root
|
||||
CREATE AUTO FILL CID WITH
|
||||
VALUE #( ( key_field = 3
|
||||
field1 = 'E'
|
||||
field2 = 'F'
|
||||
%control = VALUE #(
|
||||
key_field = if_abap_behv=>mk-on
|
||||
field1 = if_abap_behv=>mk-on
|
||||
field2 = if_abap_behv=>mk-on ) ) )
|
||||
MAPPED DATA(m2)
|
||||
FAILED DATA(f2)
|
||||
REPORTED DATA(r2).
|
||||
```
|
||||
|
||||
> **💡 Note**<br>
|
||||
|
||||
@@ -814,8 +814,12 @@ RAISE EXCEPTION TYPE cx_sy_zerodivide.
|
||||
"If the expression is false, the program is terminated and an uncatchable exception is raised
|
||||
"resulting in the runtime error ASSERTION_FAILED.
|
||||
|
||||
DATA(flag) = abap_false.
|
||||
DATA(number) = 0.
|
||||
ASSERT number IS INITIAL.
|
||||
ASSERT number > -1.
|
||||
ASSERT 1 = 1.
|
||||
|
||||
DATA(flag) = abap_false.
|
||||
ASSERT flag = abap_true.
|
||||
```
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
- [Notes on the Declaration Context](#notes-on-the-declaration-context)
|
||||
- [Excursions](#excursions)
|
||||
- [Enumerated Types and Objects](#enumerated-types-and-objects)
|
||||
- [Getting Type Information and Creating Types at Runtime](#getting-type-information-and-creating-types-at-runtime)
|
||||
- [Getting Type Information and Creating Types/Data Objects at Runtime](#getting-type-information-and-creating-typesdata-objects-at-runtime)
|
||||
- [Ranges Tables](#ranges-tables)
|
||||
- [Typed Literals in ABAP SQL](#typed-literals-in-abap-sql)
|
||||
- [Executable Example](#executable-example)
|
||||
@@ -1418,10 +1418,12 @@ Enumerated variables can be declared by referring to the enumerated type.
|
||||
They can only be assigned the enumerated values defined there that exist as the content of enumerated constants or components of an enumerated structure.
|
||||
|
||||
```abap
|
||||
"Using the enumerated type from above
|
||||
DATA dobj_enum_a TYPE t_enum.
|
||||
|
||||
dobj_enum_a = a.
|
||||
|
||||
"Data object declared inline, the typed derived is t_enum
|
||||
DATA(dobj_enum_b) = b.
|
||||
```
|
||||
|
||||
@@ -1429,11 +1431,16 @@ Find more information on enumerated types in the (commented code of the) cheat s
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Getting Type Information and Creating Types at Runtime
|
||||
Using [Runtime Type Identification (RTTI)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm "Glossary Entry"), you can get type information on data objects, data types or [instances](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninstance_glosry.htm "Glossary Entry") at runtime ([Runtime Type Identification (RTTI)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm "Glossary Entry")).
|
||||
Using [Runtime Type Creation (RTTC)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_creation_glosry.htm "Glossary Entry"), you can define and create new data types as [type description objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentype_object_glosry.htm) at runtime.
|
||||
### Getting Type Information and Creating Types/Data Objects at Runtime
|
||||
|
||||
Find more information in the [cheat sheet about dynamic programming](06_Dynamic_Programming.md#runtime-type-services-rtts).
|
||||
Using [Runtime Type Services (RTTS)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_services_glosry.htm "Glossary Entry")
|
||||
you can ...
|
||||
- get type information on data objects, data types or [instances](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninstance_glosry.htm "Glossary Entry") at runtime ([Runtime Type Identification (RTTI)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm "Glossary Entry")).
|
||||
- define and create new data types as [type description objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentype_object_glosry.htm) at runtime ([Runtime Type Creation (RTTC)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_creation_glosry.htm "Glossary Entry")).
|
||||
|
||||
For more information, see the [Dynamic Programming](06_Dynamic_Programming.md) cheat sheet.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Ranges Tables
|
||||
|
||||
|
||||
@@ -339,15 +339,15 @@ ENDTRY.
|
||||
"Creating demo XML data to be used in the example.
|
||||
DATA(xml_oo_read) = cl_abap_conv_codepage=>create_out( )->convert(
|
||||
`<?xml version="1.0"?>` &&
|
||||
`<node atta="123">` &&
|
||||
`<node attr_a="123">` &&
|
||||
` <subnode1>` &&
|
||||
` <status>A</status>` &&
|
||||
` <date format="mm-dd-yyyy">01-01-2024</date>` &&
|
||||
` </subnode1>` &&
|
||||
` <subnode2>` &&
|
||||
` <text attb="1" attc="a">abc</text>` &&
|
||||
` <text attb="2" attc="b">def</text>` &&
|
||||
` <text attb="3" attc="c">ghi</text>` &&
|
||||
` <text attr_b="1" attr_c="a">abc</text>` &&
|
||||
` <text attr_b="2" attr_c="b">def</text>` &&
|
||||
` <text attr_b="3" attr_c="c">ghi</text>` &&
|
||||
` </subnode2>` &&
|
||||
`</node>` ).
|
||||
|
||||
|
||||
@@ -241,6 +241,6 @@ This is not intended to be a contribution repository, so please do not create pu
|
||||
<br>
|
||||
|
||||
## 📜 License
|
||||
Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSE) file.
|
||||
Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSE) file.
|
||||
|
||||
[^1]: "A written [...] aid (such as a sheet of notes) that can be referred to for help in understanding or remembering something complex" (Definition for "cheat sheet" in Merriam-Webster Dictionary).
|
||||
Reference in New Issue
Block a user