Update
This commit is contained in:
@@ -11,7 +11,10 @@
|
||||
- [Copying Internal Tables](#copying-internal-tables)
|
||||
- [Using INSERT and APPEND Statements to Populate Internal Tables](#using-insert-and-append-statements-to-populate-internal-tables)
|
||||
- [Creating and Filling Internal Tables Using Constructor Expressions](#creating-and-filling-internal-tables-using-constructor-expressions)
|
||||
- [Excursion: Using Internal Tables in ABAP SQL Statements](#excursion-using-internal-tables-in-abap-sql-statements)
|
||||
- [VALUE operator](#value-operator)
|
||||
- [CORRESPONDING operator](#corresponding-operator)
|
||||
- [FILTER Operator\*\*](#filter-operator)
|
||||
- [NEW Operator](#new-operator)
|
||||
- [Reading Single Lines from Internal Tables](#reading-single-lines-from-internal-tables)
|
||||
- [Determining the Target Area when Reading Single Lines](#determining-the-target-area-when-reading-single-lines)
|
||||
- [Reading a Single Line by Index](#reading-a-single-line-by-index)
|
||||
@@ -21,6 +24,9 @@
|
||||
- [Checking the Existence and the Index of a Line in an Internal Table](#checking-the-existence-and-the-index-of-a-line-in-an-internal-table)
|
||||
- [Processing Multiple Internal Table Lines Sequentially](#processing-multiple-internal-table-lines-sequentially)
|
||||
- [Iteration Expressions](#iteration-expressions)
|
||||
- [Operations with Internal Tables Using ABAP SQL SELECT Statements](#operations-with-internal-tables-using-abap-sql-select-statements)
|
||||
- [Internal Tables as Target Data Objects](#internal-tables-as-target-data-objects)
|
||||
- [Querying from Internal Tables](#querying-from-internal-tables)
|
||||
- [Sorting Internal Tables](#sorting-internal-tables)
|
||||
- [Modifying Internal Table Content](#modifying-internal-table-content)
|
||||
- [Deleting Internal Table Content](#deleting-internal-table-content)
|
||||
@@ -537,7 +543,9 @@ INSERT LINES OF itab2 INTO itab INDEX i.
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Creating and Filling Internal Tables Using Constructor Expressions
|
||||
The constructor expressions can be specified in/with various positions/statements in ABAP. In most of the following snippets, simple assignments are demonstrated.
|
||||
|
||||
#### VALUE operator
|
||||
As mentioned above, table lines that are constructed inline as
|
||||
arguments to the `VALUE` operator, for example, can be added to
|
||||
internal tables. In the following cases, internal tables are populated
|
||||
@@ -598,6 +606,7 @@ itab = VALUE #( ( comp1 = a comp2 = b ...)
|
||||
... ).
|
||||
```
|
||||
|
||||
#### CORRESPONDING operator
|
||||
|
||||
**Copying the content of another internal table** using the
|
||||
[`CORRESPONDING`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expr_corresponding.htm) operator.
|
||||
@@ -652,14 +661,14 @@ itab = CORRESPONDING #( itab2 DISCARDING DUPLICATES ).
|
||||
``` abap
|
||||
itab_nested2 = CORRESPONDING #( DEEP itab_nested1 ).
|
||||
|
||||
itab_nested2 = CORRESPONDING #( DEEP BASE ( itab_nested2 ) itab_nested1 )
|
||||
itab_nested2 = CORRESPONDING #( DEEP BASE ( itab_nested2 ) itab_nested1 ).
|
||||
|
||||
MOVE-CORRESPONDING itab_nested1 TO itab_nested2 EXPANDING NESTED TABLES.
|
||||
|
||||
MOVE-CORRESPONDING itab_nested1 TO itab_nested2 EXPANDING NESTED TABLES KEEPING TARGET LINES.
|
||||
```
|
||||
|
||||
**Using the `FILTER` operator**
|
||||
#### FILTER Operator**
|
||||
|
||||
To create an internal table by copying data from another internal table and
|
||||
filtering out lines that do not meet the `WHERE` condition, you can use the [`FILTER`
|
||||
@@ -735,107 +744,28 @@ DATA(f11) = FILTER #( itab2 USING KEY sec_key EXCEPT IN filter_tab2 WHERE num =
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Excursion: Using Internal Tables in ABAP SQL Statements
|
||||
For more details on ABAP SQL, see the [ABAP SQL](03_ABAP_SQL.md) cheat sheet.
|
||||
#### NEW Operator
|
||||
|
||||
**Adding multiple lines from a database table to an internal table** using
|
||||
[`SELECT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapselect.htm),
|
||||
for example, based on a condition. In the case below, the internal table
|
||||
is created inline.
|
||||
``` abap
|
||||
SELECT FROM dbtab
|
||||
FIELDS comp1, comp2 ...
|
||||
WHERE ...
|
||||
INTO TABLE @DATA(itab_sel).
|
||||
```
|
||||
Using the instance operator [`NEW`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_new.htm), you can create [anonymous data objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenanonymous_data_object_glosry.htm "Glossary Entry"), such as anonymous internal tables. You can access the lines, components or the entire data objects by [dereferencing](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendereferencing_operat_glosry.htm). For more information, refer to the [Dynamic Programming](06_Dynamic_Programming.md) and [Constructor Expressions](05_Constructor_Expressions.md) cheat sheets.
|
||||
|
||||
**Sequentially adding multiple rows** from a database table to an internal table using `SELECT ... ENDSELECT.`, for example, based on a condition. In this case, the selected data is first stored in a structure that can be further processed and added to an internal table.
|
||||
```abap
|
||||
TYPES: BEGIN OF s,
|
||||
a TYPE c LENGTH 3,
|
||||
b TYPE i,
|
||||
END OF s,
|
||||
tab_type TYPE TABLE OF s WITH EMPTY KEY.
|
||||
|
||||
``` abap
|
||||
SELECT FROM dbtab
|
||||
FIELDS comp1, comp2 ...
|
||||
WHERE ...
|
||||
INTO @DATA(struc_sel).
|
||||
"Creating and populating an anonymous data object
|
||||
DATA(dref_tab) = NEW tab_type( ( a = 'aaa' b = 1 )
|
||||
( a = 'bbb' b = 2 ) ).
|
||||
|
||||
IF sy-subrc = 0.
|
||||
APPEND struc_sel TO itab.
|
||||
...
|
||||
ENDIF.
|
||||
ENDSELECT.
|
||||
```
|
||||
|
||||
Adding multiple lines from a database table using `SELECT`, for example, based on a condition when the database table has a line type that is incompatible with the internal table. The `*` character means that all fields are selected. The other examples define specific fields.
|
||||
The `APPENDING CORRESPONDING FIELDS INTO TABLE` addition appends the selected data to the end of the table without deleting existing
|
||||
table entries. The `INTO CORRESPONDING FIELDS OF TABLE` addition adds lines and deletes existing table entries.
|
||||
``` abap
|
||||
SELECT FROM dbtab2
|
||||
FIELDS *
|
||||
WHERE ...
|
||||
APPENDING CORRESPONDING FIELDS OF TABLE @itab.
|
||||
|
||||
SELECT FROM dbtab2
|
||||
FIELDS *
|
||||
WHERE ...
|
||||
INTO CORRESPONDING FIELDS OF TABLE @itab.
|
||||
```
|
||||
Adding multiple lines from an internal table to another internal table using `SELECT`. Note the alias name that must be defined for the
|
||||
internal table.
|
||||
``` abap
|
||||
SELECT comp1, comp2, ...
|
||||
FROM @itab2 AS it_alias
|
||||
INTO TABLE @DATA(itab_sel).
|
||||
```
|
||||
|
||||
**Combining data from multiple tables into one internal table** using an [inner
|
||||
join](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninner_join_glosry.htm "Glossary Entry").
|
||||
The following example joins data of an internal and a database table
|
||||
using a `SELECT` statement and the [`INNER JOIN`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapselect_join.htm) addition. Note that the field list includes fields from both tables. The fields are referred to using `~`.
|
||||
``` abap
|
||||
SELECT it_alias~comp1, it_alias~comp2, dbtab~comp3 ...
|
||||
FROM @itab AS it_alias
|
||||
INNER JOIN dbtab ON it_alias~comp1 = dbtab~comp1
|
||||
INTO TABLE @DATA(it_join_result).
|
||||
```
|
||||
|
||||
Filling an internal table from a database table using
|
||||
[subqueries](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensubquery_glosry.htm "Glossary Entry").
|
||||
The following two examples fill an internal table from a database table. In the first example, a subquery is specified in the
|
||||
`WHERE` clause with the `NOT IN` addition. It checks whether a value matches a value in a set of values
|
||||
specified in parentheses. The second example fills an internal table depending on data in another table. A subquery with the `EXISTS` addition is specified in
|
||||
the `WHERE` clause. In this
|
||||
case, the result of the subquery, which is another
|
||||
`SELECT` statement, is checked to see if an entry exists in
|
||||
a table based on the specified conditions.
|
||||
|
||||
``` abap
|
||||
SELECT comp1, comp2, ...
|
||||
FROM dbtab
|
||||
WHERE comp1 NOT IN ( a, b, c ... )
|
||||
INTO TABLE @DATA(it_subquery_result1).
|
||||
|
||||
SELECT comp1, comp2, ...
|
||||
FROM dbtab
|
||||
WHERE EXISTS ( SELECT 'X' FROM @itab AS itab_alias
|
||||
WHERE comp1 = dbtab~comp1 )
|
||||
INTO TABLE @DATA(it_subquery_result2).
|
||||
```
|
||||
|
||||
Filling internal table from a table based on the existence of data in
|
||||
another table using the [`FOR ALL ENTRIES`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenwhere_all_entries.htm) addition.
|
||||
|
||||
> **💡 Note**<br>
|
||||
> Make sure that the internal table you are reading from is not initial. Therefore, it is recommended that you use a subquery as shown above: `... ( SELECT ... FROM @itab AS itab_alias WHERE ... ) ...`.
|
||||
|
||||
``` abap
|
||||
IF itab IS NOT INITIAL.
|
||||
|
||||
SELECT dbtab~comp1, dbtab~comp2, ...
|
||||
FROM dbtab
|
||||
FOR ALL ENTRIES IN @itab
|
||||
WHERE comp1 = @itab-comp1
|
||||
INTO TABLE @DATA(it_select_result).
|
||||
|
||||
ENDIF.
|
||||
"Access by derefencing
|
||||
DATA(copy_deref_itab) = dref_tab->*.
|
||||
DATA(read_line) = dref_tab->*[ 2 ].
|
||||
DATA(read_comp) = dref_tab->*[ 1 ]-a.
|
||||
dref_tab->*[ 1 ]-a = 'zzz'.
|
||||
ASSERT dref_tab->*[ 1 ]-a = 'zzz'.
|
||||
INSERT VALUE s( a = 'yyy' b = 3 ) INTO TABLE dref_tab->*.
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
@@ -871,7 +801,7 @@ The following code snippets include [`READ TABLE`](https://help.sap.com/doc/abap
|
||||
|
||||
- Assigning a line to a [field
|
||||
symbol](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm "Glossary Entry"),
|
||||
for example, using an inline declaration (`ASSIGNING <fs>`). When you then access the field symbol, it means that you access the found table line. There is no actual copying of
|
||||
for example, using an inline declaration (`... ASSIGNING FIELD-SYMBOL(<fs>) ...`). When you then access the field symbol, it means that you access the found table line. There is no actual copying of
|
||||
content. Therefore, modifying the field symbol means
|
||||
modifying the table line directly. Note that you cannot use the
|
||||
`TRANSPORTING` addition since the entire table is
|
||||
@@ -1035,7 +965,7 @@ READ TABLE it INTO wa WITH KEY b = 2.
|
||||
When reading single lines in general, you can also address individual
|
||||
components of the line using the [component
|
||||
selector](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencomponent_selector_glosry.htm "Glossary Entry")
|
||||
`-` (or the [dereferencing
|
||||
`-` (or the [object component selector](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenobject_component_select_glosry.htm) `->` or the [dereferencing
|
||||
operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendereferencing_operat_glosry.htm "Glossary Entry")
|
||||
`->*` in the case of data reference variables).
|
||||
``` abap
|
||||
@@ -1255,6 +1185,178 @@ The expressions are covered in the cheat sheet [Constructor Expressions](05_Cons
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Operations with Internal Tables Using ABAP SQL SELECT Statements
|
||||
|
||||
- In ABAP, database data is buffered in a [table buffer](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentable_buffer_glosry.htm) (internally, this happens in internal tables in the [shared memory](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenshared_memory_glosry.htm) of the ABAP server).
|
||||
- During read access, it is checked if the data is in the buffer, and if so, a read happens directly from there. If not, the data is first loaded into the buffer.
|
||||
- The [ABAP SQL engine](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_engine_glosry.htm) is involved in the read process. It processes reads and is used when tabular data is read (with a `SELECT` statement). This includes both buffered data from database tables in the table buffer and also internal tables of the current internal session.
|
||||
- Which means ABAP SQL is executed in this buffer on the ABAP server, not directly on the database.
|
||||
|
||||
So, ABAP SQL `SELECT` statements can be used for multiple purposes also on internal tables. The following snippets cover a selection. Find more details in the ABAP Keyword Documentation and in the [ABAP SQL cheat sheet](03_ABAP_SQL.md).
|
||||
|
||||
> **💡 Note**<br>
|
||||
> - No deep components (nested tables, strings) are allowed.
|
||||
> - Trailing blanks of short text fields are truncated.
|
||||
> - When joining multiple internal tables, it must be ensured that the ABAP SQL engine can handle it, which means only internal tables are used (no buffered database tables), no special features like hierarchies, aggregates, subselects, etc. are used.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Internal Tables as Target Data Objects
|
||||
|
||||
Adding multiple lines from a database table to an internal table using
|
||||
[`SELECT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapselect.htm),
|
||||
for example, based on a condition. In the case below, the internal table
|
||||
is created inline.
|
||||
``` abap
|
||||
SELECT FROM dbtab
|
||||
FIELDS comp1, comp2 ...
|
||||
WHERE ...
|
||||
INTO TABLE @DATA(itab_sel).
|
||||
```
|
||||
|
||||
Adding multiple lines from a database table using `SELECT`, for example, based on a condition when the database table has a line type that is incompatible with the internal table. The `*` character means that all fields are selected. The other examples define specific fields.
|
||||
The `APPENDING CORRESPONDING FIELDS INTO TABLE` addition appends the selected data to the end of the table without deleting existing
|
||||
table entries. The `INTO CORRESPONDING FIELDS OF TABLE` addition adds lines and deletes existing table entries.
|
||||
``` abap
|
||||
SELECT FROM dbtab2
|
||||
FIELDS *
|
||||
WHERE ...
|
||||
APPENDING CORRESPONDING FIELDS OF TABLE @itab.
|
||||
|
||||
SELECT FROM dbtab2
|
||||
FIELDS *
|
||||
WHERE ...
|
||||
INTO CORRESPONDING FIELDS OF TABLE @itab.
|
||||
```
|
||||
|
||||
Combining data from multiple database tables into one internal table using an [inner
|
||||
join](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninner_join_glosry.htm "Glossary Entry").
|
||||
The following example uses the [`INNER JOIN`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapselect_join.htm) addition. Note that the field list includes fields from both tables. The fields are referred to using `~`.
|
||||
``` abap
|
||||
SELECT db1~comp1, db1~comp2, db2~comp_abc, db2~comp_xyz ...
|
||||
FROM db1
|
||||
INNER JOIN db2 ON db1~comp1 = db2~comp1
|
||||
INTO TABLE @DATA(it_join_result).
|
||||
```
|
||||
|
||||
Filling an internal table from a database table using
|
||||
[subqueries](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensubquery_glosry.htm "Glossary Entry").
|
||||
The following two examples fill an internal table from a database table. In the first example, a subquery is specified in the
|
||||
`WHERE` clause with the `NOT IN` addition. It checks whether a value matches a value in a set of values
|
||||
specified in parentheses. The second example fills an internal table depending on data in another table. A subquery with the `EXISTS` addition is specified in
|
||||
the `WHERE` clause. In this
|
||||
case, the result of the subquery, which is another
|
||||
`SELECT` statement, is checked to see if an entry exists in
|
||||
a table based on the specified conditions.
|
||||
|
||||
``` abap
|
||||
SELECT comp1, comp2, ...
|
||||
FROM dbtab
|
||||
WHERE comp1 NOT IN ( a, b, c ... )
|
||||
INTO TABLE @DATA(it_subquery_result1).
|
||||
|
||||
SELECT comp1, comp2, ...
|
||||
FROM db1
|
||||
WHERE EXISTS ( SELECT 'X' FROM db2
|
||||
WHERE comp1 = db1~comp1 )
|
||||
INTO TABLE @DATA(it_subquery_result2).
|
||||
```
|
||||
|
||||
Populating an internal table from a table based on the existence of data in
|
||||
another table using the [`FOR ALL ENTRIES`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenwhere_all_entries.htm) addition.
|
||||
|
||||
> **💡 Note**<br>
|
||||
> Make sure that the internal table you are reading from is not initial. Therefore, it is recommended that you use a subquery as shown above: `... ( SELECT ... FROM ... WHERE ... ) ...`.
|
||||
|
||||
``` abap
|
||||
IF itab IS NOT INITIAL.
|
||||
|
||||
SELECT dbtab~comp1, dbtab~comp2, ...
|
||||
FROM dbtab
|
||||
FOR ALL ENTRIES IN @itab
|
||||
WHERE comp1 = @itab-comp1
|
||||
INTO TABLE @DATA(it_select_result).
|
||||
|
||||
ENDIF.
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Querying from Internal Tables
|
||||
In `SELECT` statements, internal tables can also be used as data sources.
|
||||
The snippet shows adding multiple lines from an internal table to another internal table using `SELECT`. Note the alias name that must be defined for the internal table.
|
||||
|
||||
``` abap
|
||||
SELECT comp1, comp2, ...
|
||||
FROM @itab AS it_alias
|
||||
INTO TABLE @DATA(itab_sel).
|
||||
```
|
||||
|
||||
Using the `LIKE` addition in the `WHERE` clause to extract internal table entries matching a specific pattern.
|
||||
```abap
|
||||
TYPES: BEGIN OF s,
|
||||
a TYPE c LENGTH 3,
|
||||
b TYPE i,
|
||||
END OF s,
|
||||
tab_type TYPE TABLE OF s WITH EMPTY KEY.
|
||||
DATA(itab) = VALUE tab_type( ( a = 'abc' b = 1 ) ( a = 'zbc' b = 2 )
|
||||
( a = 'bde' b = 3 ) ( a = 'yde' b = 4 ) ).
|
||||
|
||||
SELECT a, b
|
||||
FROM @itab AS it_alias
|
||||
WHERE a LIKE '%bc'
|
||||
INTO TABLE @DATA(itab_sel_like).
|
||||
|
||||
*A B
|
||||
*abc 1
|
||||
*zbc 2
|
||||
```
|
||||
|
||||
Using the `IN` addition in the `WHERE` clause to extract internal table entries based on values specified in an operand list.
|
||||
```abap
|
||||
SELECT a, b
|
||||
FROM @itab AS it_alias
|
||||
WHERE a IN ('bde', 'yde', 'zde')
|
||||
INTO TABLE @DATA(itab_in).
|
||||
|
||||
*A B
|
||||
*bde 3
|
||||
*yde 4
|
||||
```
|
||||
|
||||
Combining data from multiple internal tables into one internal table using an [inner
|
||||
join](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninner_join_glosry.htm "Glossary Entry"). See above.
|
||||
|
||||
```abap
|
||||
TYPES: BEGIN OF s,
|
||||
a TYPE c LENGTH 3,
|
||||
b TYPE c LENGTH 3,
|
||||
c TYPE i,
|
||||
END OF s,
|
||||
tab_type TYPE TABLE OF s WITH EMPTY KEY.
|
||||
|
||||
DATA(it1) = VALUE tab_type( ( a = 'aaa' b = 'bbb' c = 1 )
|
||||
( a = 'ccc' b = 'ddd' c = 1 )
|
||||
( a = 'eee' b = 'fff' c = 2 ) ).
|
||||
|
||||
DATA(it2) = VALUE tab_type( ( a = 'ggg' b = 'hhh' c = 1 )
|
||||
( a = 'iii' b = 'jjj' c = 1 )
|
||||
( a = 'kkk' b = 'lll' c = 3 ) ).
|
||||
|
||||
SELECT it_alias1~a, it_alias2~b
|
||||
FROM @it1 AS it_alias1
|
||||
INNER JOIN @it2 AS it_alias2 ON it_alias1~c = it_alias2~c
|
||||
INTO TABLE @DATA(it_join_result).
|
||||
|
||||
*A B
|
||||
*aaa hhh
|
||||
*aaa jjj
|
||||
*ccc hhh
|
||||
*ccc jjj
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Sorting Internal Tables
|
||||
|
||||
- Sorted tables are stored in the memory in an automatically sorted
|
||||
|
||||
@@ -57,7 +57,7 @@ TYPES: BEGIN OF struc_type,
|
||||
END OF struc_type.
|
||||
```
|
||||
|
||||
Alternatively, you can also use the following syntax. However, a chained statement provides better readability.
|
||||
Alternatively, you can also use the following syntax. However, a chained statement may provide better readability.
|
||||
``` abap
|
||||
TYPES BEGIN OF struc_type.
|
||||
TYPES comp1 TYPE ... .
|
||||
@@ -98,7 +98,8 @@ TYPES: BEGIN OF struc_type,
|
||||
|
||||
**Creating structures**
|
||||
|
||||
- To create a structure in an ABAP program, you can use the `DATA` keyword. - It works in the same way as the `TYPES` statement above.
|
||||
- To create a structure in an ABAP program, you can use the `DATA` keyword.
|
||||
- It works in the same way as the `TYPES` statement above.
|
||||
- Unlike the `TYPES` statement, you can use the [`VALUE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdata_options.htm) addition to set default values.
|
||||
|
||||
``` abap
|
||||
@@ -113,7 +114,7 @@ DATA: BEGIN OF struc,
|
||||
END OF struc.
|
||||
```
|
||||
|
||||
Alternatively, you can use the following syntax. Similar to above, a chained statement provides better readability.
|
||||
Alternatively, you can use the following syntax. Similar to above, a chained statement may provide better readability.
|
||||
|
||||
``` abap
|
||||
DATA BEGIN OF struc.
|
||||
@@ -177,7 +178,7 @@ FINAL(struc_11) = struc_9.
|
||||
"value assignments) ...
|
||||
DATA(struc_a) = VALUE struc_type( ).
|
||||
|
||||
"... yields the same result as the following declaration.
|
||||
"... is similar to the following declaration.
|
||||
DATA struc_b TYPE struc_type.
|
||||
|
||||
"Structures declared inline instead of an extra declared variable
|
||||
@@ -678,7 +679,7 @@ ENDLOOP.
|
||||
|
||||
**Inserting a single row into a database table from a structure** using ABAP SQL statements with
|
||||
[`INSERT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapinsert_dbtab.htm). The following statements can be considered as alternatives. The third statement shows that instead of inserting a row from an existing structure, you can create and fill a structure directly.
|
||||
Note that you should avoid inserting a row with a particular key into the database table if a row with the same key already exists.
|
||||
Note that you should avoid inserting a row with a particular key into the database table if a row with the same key already exists. Note that with this and the followig syntax, various options/expressions are possible.
|
||||
``` abap
|
||||
INSERT INTO dbtab VALUES @struc.
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
- [Introduction](#introduction)
|
||||
- [VALUE](#value)
|
||||
- [CORRESPONDING](#corresponding)
|
||||
- [NEW](#new)
|
||||
- [CONV](#conv)
|
||||
- [EXACT](#exact)
|
||||
- [REF](#ref)
|
||||
@@ -425,7 +424,7 @@ topic](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file
|
||||
| Addition | Details |
|
||||
|---|---|
|
||||
| `BASE` | Keeps original values. Unlike, for example, the operator `VALUE`, a pair of parentheses must be set around `BASE`. |
|
||||
| `MAPPING` | Enables the mapping of component names, i. e. a component of a source structure or source table can be assigned to a differently named component of a target structure or target table (e. g. `MAPPING c1 = c2`). |
|
||||
| `MAPPING` | Enables the mapping of component names, i. e. a component of a source structure or source table can be assigned to a differently named component of a target structure or target table (e. g. `MAPPING c1 = c2`). The `DEFAULT` addition is possible when using the `MAPPING` addition. It allows the assignment of values for a target component based on an expression. |
|
||||
| `EXCEPT` | You can specify components that should not be assigned content in the target data object. They remain initial. In doing so, you exclude identically named components in the source and target object that are not compatible or convertible from the assignment to avoid syntax errors or runtime errors. |
|
||||
| `DISCARDING DUPLICATES` | Relevant for tabular components. Handles duplicate lines and prevents exceptions when dealing with internal tables that have a unique primary or secondary table key. |
|
||||
| `DEEP` | Relevant for deep tabular components. They are resolved at every hierarchy level and identically named components are assigned line by line. |
|
||||
@@ -575,6 +574,89 @@ two statements are not the same:
|
||||
>MOVE-CORRESPONDING struc1 TO struc2.
|
||||
>```
|
||||
|
||||
`DEFAULT` addition when using `MAPPING`:
|
||||
- This addition allows the assignment of values for a target component based on an expression (which is evaluated before the `CORRESPONDING` expression).
|
||||
- `DEFAULT` can be preceded by the source component. In this case, the source component's value is assigned to the left-hand side only if the source component is not initial. If it is initial, the value of the expression following the `DEFAULT` addition is assigned.
|
||||
|
||||
´´´abap
|
||||
"Creating and populating data objects to work with
|
||||
DATA: BEGIN OF struc1,
|
||||
id1 TYPE i,
|
||||
a TYPE string,
|
||||
b TYPE string,
|
||||
c TYPE i,
|
||||
d TYPE string,
|
||||
e TYPE i,
|
||||
END OF struc1.
|
||||
|
||||
DATA: BEGIN OF struc2,
|
||||
id2 TYPE i,
|
||||
a TYPE string,
|
||||
b TYPE string,
|
||||
c TYPE i,
|
||||
d TYPE string,
|
||||
z TYPE i,
|
||||
END OF struc2.
|
||||
|
||||
DATA itab1 LIKE TABLE OF struc1 WITH EMPTY KEY.
|
||||
|
||||
"Populating structure
|
||||
struc1 = VALUE #( id1 = 1 a = `a` b = `b` c = 2 d = `d` e = 3 ).
|
||||
|
||||
"--------- Assignment using CORRESPONDING (DEFAULT only) ---------
|
||||
"- Component a: It is not specified but it is mapped anyway
|
||||
" due to the identical name and not being explicitly specified
|
||||
" for mapping
|
||||
"- The other components demonstrate various expressions
|
||||
" in combination with the DEFAULT addition.
|
||||
"- Component d: The internal table is initial in the example. The
|
||||
" DEFAULT addition to the VALUE operator avoids a runtime error
|
||||
" and specifies a default value in case of a non-existent table
|
||||
" line.
|
||||
struc2 = CORRESPONDING #(
|
||||
struc1 MAPPING id2 = id1
|
||||
b = DEFAULT `ha` && `llo`
|
||||
c = DEFAULT 1 + 5
|
||||
d = DEFAULT VALUE #( itab1[ 1 ]-d DEFAULT `hi` )
|
||||
z = DEFAULT cl_abap_random_int=>create(
|
||||
seed = cl_abap_random=>seed( )
|
||||
min = 1
|
||||
max = 100 )->get_next( ) ).
|
||||
|
||||
*struc2 (the value of z may vary because a random integer is created):
|
||||
*ID2 A B C D Z
|
||||
*1 a hallo 6 hi 28
|
||||
|
||||
"--- Assignment using CORRESPONDING (DEFAULT preceded by the source ---
|
||||
"--- component on the right-hand side) --------------------------------
|
||||
"- The example is similar to above. Various expressions are included
|
||||
" in combination with the DEFAULT addition
|
||||
"- Component a: It is not specified; see above.
|
||||
"- Components b/e: The values of the components b and e in the source
|
||||
" are initial. Therefore, the result of the expression is assigned.
|
||||
"- Components c/d: The values of the components c and d in the source
|
||||
" are not initial. Therefore, the values of c and d are assigned.
|
||||
|
||||
"Populating structure
|
||||
struc1 = VALUE #( id1 = 1 a = `a` b = `` c = 2 d = `d` e = 0 ).
|
||||
|
||||
struc2 = CORRESPONDING #(
|
||||
struc1 MAPPING id2 = id1
|
||||
b = b DEFAULT `ha` && `llo`
|
||||
c = c DEFAULT 1 + 5
|
||||
d = d DEFAULT VALUE #( itab1[ 1 ]-d DEFAULT `hi` )
|
||||
z = e DEFAULT cl_abap_random_int=>create(
|
||||
seed = cl_abap_random=>seed( )
|
||||
min = 1
|
||||
max = 100 )->get_next( ) ).
|
||||
|
||||
*struc2 (the value of z may vary because a random integer is created):
|
||||
*ID2 A B C D Z
|
||||
*1 a hallo 2 d 30
|
||||
```
|
||||
|
||||
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## NEW
|
||||
|
||||
@@ -1827,6 +1827,82 @@ CALL METHOD oref2->('TRIPLE') PARAMETER-TABLE ptab.
|
||||
result = ptab[ name = 'R_TRIPLE' ]-('VALUE')->*. "9
|
||||
```
|
||||
|
||||
**Excursion**
|
||||
|
||||
The following simplified example highlights several things in the context of a dynamic invoke example:
|
||||
- Dynamic invoke and assigning actual parameters to formal parameters statically
|
||||
- Creating instances of classes dynamically, using generic types
|
||||
- The concepts of static vs. dynamic type, upcast vs. downcast
|
||||
- Dynamic ABAP does the same as static ABAP, but with dynamic ABAP, errors may not be discovered until runtime.
|
||||
- Type compliance (see the [General Rules for Typing](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentyping_check_general.htm))
|
||||
|
||||
```abap
|
||||
CLASS zcl_demo_test DEFINITION
|
||||
PUBLIC
|
||||
FINAL
|
||||
CREATE PUBLIC .
|
||||
|
||||
PUBLIC SECTION.
|
||||
INTERFACES if_oo_adt_classrun.
|
||||
METHODS some_method IMPORTING obj TYPE REF TO zcl_demo_abap_objects.
|
||||
PROTECTED SECTION.
|
||||
PRIVATE SECTION.
|
||||
ENDCLASS.
|
||||
|
||||
CLASS zcl_demo_test IMPLEMENTATION.
|
||||
METHOD if_oo_adt_classrun~main.
|
||||
|
||||
"Creating an instance of a class dynamically
|
||||
"Here, an object reference variable of the generic type 'object'
|
||||
"is used. This generic type is the static type.
|
||||
"After the CREATE OBJECT statement in the example, the dynamic type
|
||||
"is 'ref to zcl_demo_abap_objects'. It is the type which the variable
|
||||
"points to at runtime.
|
||||
DATA oref TYPE REF TO object.
|
||||
CREATE OBJECT oref TYPE ('ZCL_DEMO_ABAP_OBJECTS').
|
||||
|
||||
"In the example, the some_method method expects an object reference
|
||||
"variable with type 'ref to zcl_demo_abap_objects'.
|
||||
"A static method call such as the following is not possible. The compiler will
|
||||
"raise an error since there is no type compliance. This is because the
|
||||
"static type of the formal parameter is not compliant with the static
|
||||
"type of oref - even if the dynamic type to which the variable points
|
||||
"to at runtime is suitable.
|
||||
"some_method( oref ).
|
||||
|
||||
"As a rule, static ABAP does the same as dynamic ABAP. So, the following
|
||||
"dynamic statement raises an error at runtime. There is no compiler
|
||||
"error shown at compile time.
|
||||
TRY.
|
||||
CALL METHOD ('SOME_METHOD') EXPORTING obj = oref.
|
||||
CATCH cx_sy_dyn_call_illegal_type.
|
||||
ENDTRY.
|
||||
|
||||
"See also the following statement. No error at compile time
|
||||
"with the nonsense formal parameter.
|
||||
"It is checked at runtime and will consequently raise an issue.
|
||||
TRY.
|
||||
CALL METHOD ('SOME_METHOD') EXPORTING abcdef = oref.
|
||||
CATCH cx_sy_dyn_call_param_missing.
|
||||
ENDTRY.
|
||||
|
||||
"If you have such a use case, and deal with generic/dynamic types, note
|
||||
"the general rules for typing in the ABAP Keyword Documentation.
|
||||
"A prior downcast (i.e. from the more generic type 'object' to the less
|
||||
"specific type zcl_demo_abap_objects) can be done. In this context, note
|
||||
"that upcasts are possible (and implicitly done) when assigning the parameters,
|
||||
"but downcasts must always be done explicitly, for example, using the CAST
|
||||
"operator as follows (if you know the type to cast to).
|
||||
CALL METHOD ('SOME_METHOD') EXPORTING obj = CAST zcl_demo_abap_objects( oref ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD some_method.
|
||||
...
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Dynamic Formatting Option Specifications in String Templates
|
||||
|
||||
@@ -1670,6 +1670,13 @@ Character Sets, Ranges, Subgroups and Lookarounds
|
||||
> "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>
|
||||
> ```
|
||||
> - Regarding special characters, check the [Special Characters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenregex_pcre_syntax_specials.htm) topic in the ABAP Keyword Documentation. For example, a non-breaking space whose hex code is *U+00A0*. You can replace all of the non-breaking space occurrences in a string as follows:
|
||||
> ```abap
|
||||
> REPLACE ALL OCCURRENCES OF PCRE `\x{00A0}` IN some_string WITH ``.
|
||||
> "Alternative
|
||||
> REPLACE ALL OCCURRENCES OF PCRE `(*UTF)\N{U+00A0}` IN some_string WITH ``.
|
||||
> ```
|
||||
|
||||
Anchors and Positions
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ The following points cover RAP-related terms such as *RAP business objects* and
|
||||
further down.
|
||||
- Usually, saver classes are not needed in managed RAP BOs (except
|
||||
for special variants of managed RAP BOs which are not covered
|
||||
here). Local handler classes are, as mentioned above, usually
|
||||
here). Local handler classes are usually
|
||||
needed in managed RAP BOs if implementations are required that
|
||||
go beyond standard operations.
|
||||
- Note: In more complex scenarios, with RAP BOs that
|
||||
@@ -200,7 +200,7 @@ focus on).
|
||||
|
||||
## Excursion: RAP Behavior Definition (BDEF)
|
||||
|
||||
- As mentioned in the RAP terms and as the name implies, a RAP behavior definition describes a RAP business object (RAP BO) by defining its behavior for all of its RAP BO entities.
|
||||
- As the name implies, a RAP behavior definition describes a RAP business object (RAP BO) by defining its behavior for all of its RAP BO entities.
|
||||
- BDL source code is used in a BDEF.
|
||||
- Once you have created ...
|
||||
- the CDS root entity of a RAP BO, ADT helps you create the skeleton of a BDEF (e.g., right-click on the CDS root entity and choose *New Behavior Definition* from the pop-up).
|
||||
@@ -443,7 +443,7 @@ authorization dependent by _parent
|
||||
|
||||
## ABAP Behavior Pools (ABP)
|
||||
|
||||
As mentioned above, you can access RAP BO data from inside AS ABAP using
|
||||
You can access RAP BO data from inside AS ABAP using
|
||||
EML. Among other things, EML allows you to read or modify RAP BOs by
|
||||
accessing the RAP BO data (the RAP BO instances) in the transactional
|
||||
buffer and trigger the persistent storage or reset changes. More
|
||||
@@ -738,7 +738,7 @@ TYPES der_typ TYPE TABLE FOR DELETE entity.
|
||||
"Response parameters
|
||||
DATA map TYPE RESPONSE FOR MAPPED entity.
|
||||
DATA fail TYPE RESPONSE FOR FAILED entity.
|
||||
DATA rep TYPE RESPONSE FOR REPORTED entity.
|
||||
DATA resp TYPE RESPONSE FOR REPORTED entity.
|
||||
```
|
||||
> **💡 Note**<br>
|
||||
> Some of the derived types can only be created and accessed in implementation classes.
|
||||
@@ -1009,10 +1009,10 @@ cr_der_type = VALUE #( key_field = 1
|
||||
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 ---------------
|
||||
DELETE zdemo_abap_rapt1 FROM @cr_der_type MAPPING FROM ENTITY.
|
||||
```
|
||||
|
||||
@@ -1190,7 +1190,7 @@ Excursion: Specifying `%control` component values in the short form of `VALUE` c
|
||||
"The following EML statement creates RAP BO instances. The BDEF derived
|
||||
"type is created inline. With the FROM addition, the %control values
|
||||
"must be specified explicitly. You can provide the corresponding values
|
||||
"for all table lines using the short form, i.e. outiside of the inner
|
||||
"for all table lines using the short form, i.e. outside of the inner
|
||||
"parentheses, instead of individually specifying the values for each
|
||||
"instance within the parentheses. In this case, the corresponding %control
|
||||
"component value is assigned for all of the following table lines.
|
||||
@@ -1455,7 +1455,7 @@ READ ENTITIES OPERATIONS op_tab.
|
||||
ENTITIES`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcommit_entities.htm)
|
||||
statement triggers the RAP save sequence. Without such a statement,
|
||||
the modified RAP BO instances that are available in the
|
||||
transactional buffer are not persisted to the database. As mentioned above, in case of a natively supported RAP
|
||||
transactional buffer are not persisted to the database. In case of a natively supported RAP
|
||||
scenario (for example, when using OData), the `COMMIT
|
||||
ENTITIES` request is executed automatically.
|
||||
- `COMMIT ENTITIES` implicitly includes [`COMMIT
|
||||
@@ -1670,7 +1670,7 @@ instances](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?
|
||||
for the current ABAP EML request within the [RAP interaction phase](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_int_phase_glosry.htm "Glossary Entry") in one RAP transaction.
|
||||
- **Note:** Specify `%cid` even if there are no further operations referring to it.
|
||||
- Special case: Late numbering
|
||||
- As mentioned above, in late numbering scenarios newly created
|
||||
- In late numbering scenarios newly created
|
||||
entity instances are given their final key only shortly before
|
||||
saving in the database, i. e. you deal with preliminary keys in
|
||||
the RAP interaction phase and the early phase of the [RAP save sequence](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_save_seq_glosry.htm "Glossary Entry").
|
||||
@@ -1839,7 +1839,7 @@ Saver methods called in the RAP late save phase:
|
||||
[`cleanup`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensaver_method_cleanup.htm) method: After a successful save, the [`cleanup`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensaver_method_cleanup.htm) method clears the transactional buffer. It completes the save sequence.
|
||||
|
||||
**Commit and Rollback in a RAP Transaction**
|
||||
The default ABAP statements for RAP are `COMMIT ENTITIES` (triggers the RAP save sequence and the final database commit; as mentioned above, in natively supported RAP scenarios, the commit is performed implicitly and automatically by the RAP runtime engine) and `ROLLBACK ENTITIES` (rolls back all changes of the current RAP transaction, i.e. the transactional buffer is cleared by calling the `cleanup` method). Both are RAP-specific and end the RAP transaction.
|
||||
The default ABAP statements for RAP are `COMMIT ENTITIES` (triggers the RAP save sequence and the final database commit; in natively supported RAP scenarios, the commit is performed implicitly and automatically by the RAP runtime engine) and `ROLLBACK ENTITIES` (rolls back all changes of the current RAP transaction, i.e. the transactional buffer is cleared by calling the `cleanup` method). Both are RAP-specific and end the RAP transaction.
|
||||
|
||||
*Notes on `COMMIT ...` and `ROLLBACK ...` statements due to the integration of RAP transactions into the SAP LUW:*
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ ENDCLASS.
|
||||
> - `SHORT`: execution time of only a few seconds is expected
|
||||
> - `MEDIUM`: execution time of about one minute is expected
|
||||
> - `LONG`: execution time of more than one minute is expected
|
||||
> - To create a class in ADT, type "test" in the "Test Classes" tab and choose `CTRL + SPACE` to display the templates suggestions. You can then choose "testClass – Test class (ABAP Unit)". The skeleton of a test class is automatically generated.
|
||||
> - To create a class in ADT, type "test" in the "Test Classes" tab and choose `CTRL + SPACE` to display the template suggestions. You can then choose "testClass – Test class (ABAP Unit)". The skeleton of a test class is automatically generated.
|
||||
|
||||
To test protected or private methods, you must declare [friendship](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfriend_glosry.htm) with the class to be tested (class under test).
|
||||
Example:
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
- [Assigning References to Data Reference Variables](#assigning-references-to-data-reference-variables)
|
||||
- [Creating Anonymous Data Objects](#creating-anonymous-data-objects)
|
||||
- [Constants and Immutable Variables](#constants-and-immutable-variables)
|
||||
- [Type Conversion](#type-conversion)
|
||||
- [Type Conversions and Assignments](#type-conversions-and-assignments)
|
||||
- [Terms Related to Data Types and Objects in a Nutshell](#terms-related-to-data-types-and-objects-in-a-nutshell)
|
||||
- [Notes on the Declaration Context](#notes-on-the-declaration-context)
|
||||
- [Excursions](#excursions)
|
||||
@@ -1106,7 +1106,7 @@ SELECT * FROM zdemo_abap_carr INTO TABLE @FINAL(itab_final_inl).
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Type Conversion
|
||||
## Type Conversions and Assignments
|
||||
A value assignment means that the value of a data object is transferred to a target data object. If the data types of the source and target are compatible, the content is copied unchanged. If they are incompatible and a suitable [conversion rule](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconversion_rule_glosry.htm) exists, the content is converted.
|
||||
The following cases must be distinguished with regard to the data type:
|
||||
- The source and target data types are compatible, i.e. all technical type properties match. The content is transferred from the source to the target without being converted.
|
||||
@@ -1120,7 +1120,7 @@ See the conversion rules for the different data types here: [Assignment and Conv
|
||||
> - Typically, assignements are made using the assignment operator `=`. If necessary and applicable, the type is converted implicitly. However, you can also use the conversion operator [`CONV`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_conv.htm) to convert types explicitly.
|
||||
> - For [lossless assignments](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenlossless_assignment_glosry.htm), the lossless operator [`EXACT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_exact.htm) can be used to perform checks before the conversion is performed to ensure that only valid values are assigned and that no values are lost in assignments.
|
||||
> - In general, no checks are performed on assignments between compatible data objects. If a data object already contains an invalid value, for example, an invalid date or time in a date or time field, it is passed a valid value when the assignment is made to a compatible data object.
|
||||
> - The `applies_to_data` method of the [RTTI](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm) class `cl_abap_datadescr` can be used to check type compatibility. See the executable example.
|
||||
> - The `applies_to_data` method of the [RTTI](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm) class `cl_abap_datadescr` can be used to check type compatibility. See the executable example and the [Dynamic Programming cheat sheet](06_Dynamic_Programming.md).
|
||||
|
||||
|
||||
```abap
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
- [Running Code in the Background](#running-code-in-the-background)
|
||||
- [Locking](#locking)
|
||||
- [Calling Services](#calling-services)
|
||||
- [Generating ABAP Repository Objects](#generating-abap-repository-objects)
|
||||
|
||||
|
||||
This ABAP cheat sheet contains a selection of available ABAP classes, serving as a quick introduction, along with code snippets to explore the functionality in action.
|
||||
@@ -2428,3 +2429,47 @@ ENDCLASS.
|
||||
</table>
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Generating ABAP Repository Objects
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td> Class </td> <td> Details/Code Snippet </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> <code>XCO_CP_GENERATION</code> </td>
|
||||
<td>
|
||||
For creating, updating and deleting ABAP repository objects. More information: [Generation APIs](https://help.sap.com/docs/btp/sap-business-technology-platform/generation-apis)<br>The rudimentary snippet is taken from the executable example of the ABAP for Cloud Development cheat sheet.
|
||||
|
||||
<br><br>
|
||||
|
||||
``` abap
|
||||
...
|
||||
DATA(n10_handler) = xco_cp_generation=>environment->dev_system( ... ).
|
||||
DATA(n11_put) = n10_handler->create_put_operation( ).
|
||||
|
||||
"Creating a domain
|
||||
DATA(n12_doma_spec) = n11_put->for-doma->add_object( ... "e.g. 'ZDEMO_ABAP_STATUS'
|
||||
)->set_package( ...
|
||||
)->create_form_specification( ).
|
||||
n12_doma_spec->set_short_description( 'Demo domain' ).
|
||||
n12_doma_spec->set_format( xco_cp_abap_dictionary=>built_in_type->char( 10 ) ).
|
||||
n12_doma_spec->fixed_values->add_fixed_value( 'BOOKED'
|
||||
)->set_description( 'Booked' ).
|
||||
n12_doma_spec->fixed_values->add_fixed_value( 'CANCELED'
|
||||
)->set_description( 'Canceled' ).
|
||||
|
||||
...
|
||||
|
||||
"Executing the generation
|
||||
TRY.
|
||||
n11_put->execute( ).
|
||||
CATCH cx_xco_gen_put_exception.
|
||||
ENDTRY.
|
||||
```
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
@@ -20,12 +20,12 @@
|
||||
- [Time Stamp Calculations with XCO](#time-stamp-calculations-with-xco)
|
||||
- [Calculating Time Stamp Differences Using the Built-In Function `utclong_diff`](#calculating-time-stamp-differences-using-the-built-in-function-utclong_diff)
|
||||
- [`CONVERT UTCLONG`: Time Stamp (`utclong`) -\> Local Date/Time](#convert-utclong-time-stamp-utclong---local-datetime)
|
||||
- [`CONVERT INTO UTCLONG`: Local Date/Time -\> Time Stamp (`utclong`)](#convert-into-utclong-local-datetime---time-stamp-utclong)
|
||||
- [`CONVERT ... INTO UTCLONG`: Local Date/Time -\> Time Stamp (`utclong`)](#convert--into-utclong-local-datetime---time-stamp-utclong)
|
||||
- [`CL_ABAP_UTCLONG`: Utilities for Time Stamps (`utclong`)](#cl_abap_utclong-utilities-for-time-stamps-utclong)
|
||||
- [Time Stamps in Packed Numbers (types `timestamp`, `timestampl`)](#time-stamps-in-packed-numbers-types-timestamp-timestampl)
|
||||
- [`GET TIME STAMP`: Retrieving the Current Time Stamp](#get-time-stamp-retrieving-the-current-time-stamp)
|
||||
- [`CONVERT TIME STAMP`: Time Stamp in Packed Numbers -\> Local Date/Time](#convert-time-stamp-time-stamp-in-packed-numbers---local-datetime)
|
||||
- [`CONVERT INTO TIME STAMP`: Local Date/Time -\> Time Stamp in Packed Numbers](#convert-into-time-stamp-local-datetime---time-stamp-in-packed-numbers)
|
||||
- [`CONVERT ... INTO TIME STAMP`: Local Date/Time -\> Time Stamp in Packed Numbers](#convert--into-time-stamp-local-datetime---time-stamp-in-packed-numbers)
|
||||
- [`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)
|
||||
@@ -788,9 +788,9 @@ ENDTRY.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
#### `CONVERT INTO UTCLONG`: Local Date/Time -> Time Stamp (`utclong`)
|
||||
#### `CONVERT ... INTO UTCLONG`: Local Date/Time -> Time Stamp (`utclong`)
|
||||
|
||||
More information: [`CONVERT INTO UTCLONG`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapconvert_utclong.htm)
|
||||
More information: [`CONVERT ... INTO UTCLONG`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapconvert_utclong.htm)
|
||||
|
||||
```abap
|
||||
DATA date2utcl TYPE d VALUE '20240101'.
|
||||
@@ -1004,9 +1004,9 @@ ASSERT sy-subrc = 12.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
#### `CONVERT INTO TIME STAMP`: Local Date/Time -> Time Stamp in Packed Numbers
|
||||
#### `CONVERT ... INTO TIME STAMP`: Local Date/Time -> Time Stamp in Packed Numbers
|
||||
|
||||
More information: [`CONVERT INTO TIME STAMP`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapconvert_date_time-stamp.htm)
|
||||
More information: [`CONVERT ... INTO TIME STAMP`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapconvert_date_time-stamp.htm)
|
||||
|
||||
```abap
|
||||
DATA date4conv TYPE d VALUE '20240101'.
|
||||
|
||||
@@ -81,7 +81,7 @@ Boolean function that returns a truth value. Similar to <code>boolc</code>, it r
|
||||
<br><br>
|
||||
|
||||
``` abap
|
||||
"X
|
||||
"abap_true
|
||||
DATA(xsdb1) = xsdbool( 3 > 1 ).
|
||||
|
||||
"#X#
|
||||
@@ -216,7 +216,7 @@ DATA(cont15) = xsdbool( contains_any_not_of( val = hi end = abc ) ).
|
||||
<tr>
|
||||
<td> <code>matches</code> </td>
|
||||
<td>
|
||||
Comparing a search range. More optional parameters are available.
|
||||
Comparing a search range of a value with a regular expression. More optional parameters are available (e.g. <code>case</code>, <code>off</code>, <code>len</code>).
|
||||
<br><br>
|
||||
|
||||
``` abap
|
||||
|
||||
Reference in New Issue
Block a user