Correct ABAP md highlights
This commit is contained in:
@@ -162,12 +162,12 @@ or [`LIKE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
TYPES itab_type1 TYPE STANDARD TABLE OF data_type ... "Standard table type
|
TYPES itab_type1 TYPE STANDARD TABLE OF data_type ... "Standard table type
|
||||||
TYPES itab_type2 LIKE SORTED TABLE OF data_object ... "Sorted table type
|
TYPES itab_type2 LIKE SORTED TABLE OF data_object ... "Sorted table type
|
||||||
|
|
||||||
DATA itab1 TYPE TABLE OF data_type ... "Standard table by default
|
DATA itab1 TYPE TABLE OF data_type ... "Standard table by default
|
||||||
DATA itab2 TYPE HASHED TABLE OF data_type ... "Hashed table
|
DATA itab2 TYPE HASHED TABLE OF data_type ... "Hashed table
|
||||||
DATA itab3 TYPE table_type ... "Based on an existing internal table type
|
DATA itab3 TYPE table_type ... "Based on an existing internal table type
|
||||||
DATA itab4 LIKE table ... "Based on an existing internal table
|
DATA itab4 LIKE tab ... "Based on an existing internal table
|
||||||
```
|
```
|
||||||
|
|
||||||
> **💡 Note**<br>
|
> **💡 Note**<br>
|
||||||
@@ -617,23 +617,23 @@ for example, based on a condition. In the case below, the internal table
|
|||||||
is created inline.
|
is created inline.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS comp1, comp2 ...
|
FIELDS comp1, comp2 ...
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO TABLE @DATA(itab_sel).
|
INTO TABLE @DATA(itab_sel).
|
||||||
```
|
```
|
||||||
|
|
||||||
**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.
|
**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
|
``` abap
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS comp1, comp2 ...
|
FIELDS comp1, comp2 ...
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO @DATA(struc_sel).
|
INTO @DATA(struc_sel).
|
||||||
|
|
||||||
IF sy-subrc = 0.
|
IF sy-subrc = 0.
|
||||||
APPEND struc_sel TO itab.
|
APPEND struc_sel TO itab.
|
||||||
...
|
...
|
||||||
ENDIF.
|
ENDIF.
|
||||||
ENDSELECT.
|
ENDSELECT.
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -642,21 +642,21 @@ The `APPENDING CORRESPONDING FIELDS INTO TABLE` addition appends the selected da
|
|||||||
table entries. The `INTO CORRESPONDING FIELDS OF TABLE` addition adds lines and deletes existing table entries.
|
table entries. The `INTO CORRESPONDING FIELDS OF TABLE` addition adds lines and deletes existing table entries.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab2
|
SELECT FROM dbtab2
|
||||||
FIELDS *
|
FIELDS *
|
||||||
WHERE ...
|
WHERE ...
|
||||||
APPENDING CORRESPONDING FIELDS OF TABLE @itab.
|
APPENDING CORRESPONDING FIELDS OF TABLE @itab.
|
||||||
|
|
||||||
SELECT FROM dbtab2
|
SELECT FROM dbtab2
|
||||||
FIELDS *
|
FIELDS *
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO CORRESPONDING FIELDS OF TABLE @itab.
|
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
|
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.
|
internal table.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT comp1, comp2, ...
|
SELECT comp1, comp2, ...
|
||||||
FROM @itab2 AS it_alias
|
FROM @itab2 AS it_alias
|
||||||
INTO TABLE @DATA(itab_sel).
|
INTO TABLE @DATA(itab_sel).
|
||||||
```
|
```
|
||||||
|
|
||||||
**Combining data from multiple tables into one internal table** using an [inner
|
**Combining data from multiple tables into one internal table** using an [inner
|
||||||
@@ -665,9 +665,9 @@ 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 `~`.
|
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
|
``` abap
|
||||||
SELECT it_alias~comp1, it_alias~comp2, dbtab~comp3 ...
|
SELECT it_alias~comp1, it_alias~comp2, dbtab~comp3 ...
|
||||||
FROM @itab AS it_alias
|
FROM @itab AS it_alias
|
||||||
INNER JOIN dbtab ON it_alias~comp1 = dbtab~comp1
|
INNER JOIN dbtab ON it_alias~comp1 = dbtab~comp1
|
||||||
INTO TABLE @DATA(it_join_result).
|
INTO TABLE @DATA(it_join_result).
|
||||||
```
|
```
|
||||||
|
|
||||||
Filling an internal table from a database table using
|
Filling an internal table from a database table using
|
||||||
@@ -682,15 +682,15 @@ a table based on the specified conditions.
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
SELECT comp1, comp2, ...
|
SELECT comp1, comp2, ...
|
||||||
FROM dbtab
|
FROM dbtab
|
||||||
WHERE comp1 NOT IN ( a, b, c ... )
|
WHERE comp1 NOT IN ( a, b, c ... )
|
||||||
INTO TABLE @DATA(it_subquery_result1).
|
INTO TABLE @DATA(it_subquery_result1).
|
||||||
|
|
||||||
SELECT comp1, comp2, ...
|
SELECT comp1, comp2, ...
|
||||||
FROM dbtab
|
FROM dbtab
|
||||||
WHERE EXISTS ( SELECT 'X' FROM @itab AS itab_alias
|
WHERE EXISTS ( SELECT 'X' FROM @itab AS itab_alias
|
||||||
WHERE comp1 = dbtab~comp1 )
|
WHERE comp1 = dbtab~comp1 )
|
||||||
INTO TABLE @DATA(it_subquery_result2).
|
INTO TABLE @DATA(it_subquery_result2).
|
||||||
```
|
```
|
||||||
|
|
||||||
Filling internal table from a table based on the existence of data in
|
Filling internal table from a table based on the existence of data in
|
||||||
@@ -701,11 +701,13 @@ another table using the [`FOR ALL ENTRIES`](https://help.sap.com/doc/abapdocu_cp
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
IF itab IS NOT INITIAL.
|
IF itab IS NOT INITIAL.
|
||||||
SELECT dbtab~comp1, dbtab~comp2, ...
|
|
||||||
FROM dbtab
|
SELECT dbtab~comp1, dbtab~comp2, ...
|
||||||
FOR ALL ENTRIES IN @itab
|
FROM dbtab
|
||||||
WHERE comp1 = @itab-comp1
|
FOR ALL ENTRIES IN @itab
|
||||||
INTO TABLE @DATA(it_select_result).
|
WHERE comp1 = @itab-comp1
|
||||||
|
INTO TABLE @DATA(it_select_result).
|
||||||
|
|
||||||
ENDIF.
|
ENDIF.
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -762,11 +764,11 @@ DATA(f7) = FILTER #( itab3 WHERE num = 3 ).
|
|||||||
"table meets the condition. EXCEPT and USING KEY are also possible.
|
"table meets the condition. EXCEPT and USING KEY are also possible.
|
||||||
|
|
||||||
DATA filter_tab1 TYPE SORTED TABLE OF i
|
DATA filter_tab1 TYPE SORTED TABLE OF i
|
||||||
WITH NON-UNIQUE KEY table_line.
|
WITH NON-UNIQUE KEY table_line.
|
||||||
|
|
||||||
DATA filter_tab2 TYPE STANDARD TABLE OF i
|
DATA filter_tab2 TYPE STANDARD TABLE OF i
|
||||||
WITH EMPTY KEY
|
WITH EMPTY KEY
|
||||||
WITH UNIQUE SORTED KEY line COMPONENTS table_line.
|
WITH UNIQUE SORTED KEY line COMPONENTS table_line.
|
||||||
|
|
||||||
DATA(f8) = FILTER #( itab1 IN filter_tab1 WHERE num = table_line ).
|
DATA(f8) = FILTER #( itab1 IN filter_tab1 WHERE num = table_line ).
|
||||||
|
|
||||||
@@ -1162,7 +1164,7 @@ TYPES ttype like it.
|
|||||||
DATA(tab1) = VALUE ttype( FOR ls IN it ( a = ls-a b = 9 ) ).
|
DATA(tab1) = VALUE ttype( FOR ls IN it ( a = ls-a b = 9 ) ).
|
||||||
|
|
||||||
DATA(tab2) = VALUE ttype( FOR ls IN it WHERE ( a < 7 )
|
DATA(tab2) = VALUE ttype( FOR ls IN it WHERE ( a < 7 )
|
||||||
( a = ls-a b = ls-b + 5 ) ).
|
( a = ls-a b = ls-b + 5 ) ).
|
||||||
```
|
```
|
||||||
|
|
||||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||||
|
|||||||
188
02_Structures.md
188
02_Structures.md
@@ -103,7 +103,7 @@ DATA: BEGIN OF struc,
|
|||||||
"the content is initial.
|
"the content is initial.
|
||||||
comp5 TYPE local_structured_type,
|
comp5 TYPE local_structured_type,
|
||||||
...,
|
...,
|
||||||
END 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 provides better readability.
|
||||||
@@ -127,7 +127,7 @@ Creating structures using existing structured types:
|
|||||||
TYPES: BEGIN OF struc_type,
|
TYPES: BEGIN OF struc_type,
|
||||||
comp1 TYPE i,
|
comp1 TYPE i,
|
||||||
comp2 TYPE c LENGTH 5,
|
comp2 TYPE c LENGTH 5,
|
||||||
END OF struc_type.
|
END OF struc_type.
|
||||||
|
|
||||||
"Creating a structure using a local structured type
|
"Creating a structure using a local structured type
|
||||||
DATA struc_1 TYPE struc_type.
|
DATA struc_1 TYPE struc_type.
|
||||||
@@ -205,50 +205,50 @@ or a [deep structure](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US
|
|||||||
|
|
||||||
- **Flat structures** contain only elementary types that have a fixed length, that is, there are no internal tables, reference types or strings as components. Nesting does not matter in this context. Even a nested structure is considered flat unless a substructure contains a deep component.
|
- **Flat structures** contain only elementary types that have a fixed length, that is, there are no internal tables, reference types or strings as components. Nesting does not matter in this context. Even a nested structure is considered flat unless a substructure contains a deep component.
|
||||||
``` abap
|
``` abap
|
||||||
DATA: BEGIN OF structure,
|
DATA: BEGIN OF struc,
|
||||||
comp1 TYPE i,
|
comp1 TYPE i,
|
||||||
comp2 TYPE c LENGTH 15,
|
comp2 TYPE c LENGTH 15,
|
||||||
comp3 TYPE p LENGTH 8 DECIMALS 2,
|
comp3 TYPE p LENGTH 8 DECIMALS 2,
|
||||||
...,
|
...,
|
||||||
END OF structure.
|
END OF struc.
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Nested structures**: At least one component of a structure is a [substructure](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensubstructure_glosry.htm "Glossary Entry"),
|
- **Nested structures**: At least one component of a structure is a [substructure](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensubstructure_glosry.htm "Glossary Entry"),
|
||||||
that is, it refers to another structure. The following example has multiple substructures.
|
that is, it refers to another structure. The following example has multiple substructures.
|
||||||
``` abap
|
``` abap
|
||||||
DATA: BEGIN OF address_n,
|
DATA: BEGIN OF address_n,
|
||||||
BEGIN OF name,
|
BEGIN OF name,
|
||||||
title TYPE string VALUE `Mr.`,
|
title TYPE string VALUE `Mr.`,
|
||||||
prename TYPE string VALUE `Duncan`,
|
prename TYPE string VALUE `Duncan`,
|
||||||
surname TYPE string VALUE `Pea`,
|
surname TYPE string VALUE `Pea`,
|
||||||
END OF name,
|
END OF name,
|
||||||
BEGIN OF street,
|
BEGIN OF street,
|
||||||
name TYPE string VALUE `Vegetable Lane`,
|
name TYPE string VALUE `Vegetable Lane`,
|
||||||
number TYPE string VALUE `11`,
|
num TYPE string VALUE `11`,
|
||||||
END OF street,
|
END OF street,
|
||||||
BEGIN OF city,
|
BEGIN OF city,
|
||||||
zipcode TYPE string VALUE `349875`,
|
zipcode TYPE string VALUE `349875`,
|
||||||
name TYPE string VALUE `Botanica`,
|
name TYPE string VALUE `Botanica`,
|
||||||
END OF city,
|
END OF city,
|
||||||
END OF address_n.
|
END OF address_n.
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Deep structures**: Contains at least one internal table, reference type, or string as a component.
|
- **Deep structures**: Contains at least one internal table, reference type, or string as a component.
|
||||||
``` abap
|
``` abap
|
||||||
DATA: BEGIN OF address_d,
|
DATA: BEGIN OF address_d,
|
||||||
name TYPE string VALUE `Mr. Duncan Pea`,
|
name TYPE string VALUE `Mr. Duncan Pea`,
|
||||||
street TYPE string VALUE `Vegetable Lane 11`,
|
street TYPE string VALUE `Vegetable Lane 11`,
|
||||||
city TYPE string VALUE `349875 Botanica`,
|
city TYPE string VALUE `349875 Botanica`,
|
||||||
details TYPE TABLE OF some_table WITH EMPTY KEY,
|
details TYPE TABLE OF some_table WITH EMPTY KEY,
|
||||||
END OF address_d.
|
END OF address_d.
|
||||||
```
|
```
|
||||||
Although the following structure looks quite simple, it is not a flat structure, but a deep structure, because it contains strings.
|
Although the following structure looks quite simple, it is not a flat structure, but a deep structure, because it contains strings.
|
||||||
``` abap
|
``` abap
|
||||||
DATA: BEGIN OF address,
|
DATA: BEGIN OF address,
|
||||||
name TYPE string VALUE `Mr. Duncan Pea`,
|
name TYPE string VALUE `Mr. Duncan Pea`,
|
||||||
street TYPE string VALUE `Vegetable Lane 11`,
|
street TYPE string VALUE `Vegetable Lane 11`,
|
||||||
city TYPE string VALUE `349875 Botanica`,
|
city TYPE string VALUE `349875 Botanica`,
|
||||||
END OF address.
|
END OF address.
|
||||||
```
|
```
|
||||||
|
|
||||||
> **💡 Note**<br>
|
> **💡 Note**<br>
|
||||||
@@ -265,28 +265,28 @@ that is, it refers to another structure. The following example has multiple subs
|
|||||||
- ADT and the ABAP Editor provide code completion for structure components after the component selectors.
|
- ADT and the ABAP Editor provide code completion for structure components after the component selectors.
|
||||||
``` abap
|
``` abap
|
||||||
"Addressing components via the structure component selector
|
"Addressing components via the structure component selector
|
||||||
... structure-comp1 ...
|
... struc-comp1 ...
|
||||||
... structure-comp2 ...
|
... struc-comp2 ...
|
||||||
... structure-comp3 ...
|
... struc-comp3 ...
|
||||||
|
|
||||||
"Examples for addressing the whole structure and individual components
|
"Examples for addressing the whole structure and individual components
|
||||||
IF structure IS INITIAL.
|
IF struc IS INITIAL.
|
||||||
...
|
...
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
|
||||||
IF structure-comp1 = 1.
|
IF struc-comp1 = 1.
|
||||||
...
|
...
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
|
||||||
DATA(complete_struc) = structure.
|
DATA(complete_struc) = struc.
|
||||||
DATA(comp_value) = structure-comp2.
|
DATA(comp_value) = struc-comp2.
|
||||||
|
|
||||||
"Type and data declarations
|
"Type and data declarations
|
||||||
TYPES: type_1 TYPE structured_type-comp1,
|
TYPES: type_1 TYPE structured_type-comp1,
|
||||||
type_2 LIKE structure-comp1.
|
type_2 LIKE struc-comp1.
|
||||||
|
|
||||||
DATA: var_1 TYPE structured_type-comp1,
|
DATA: var_1 TYPE structured_type-comp1,
|
||||||
var_2 LIKE structure-comp1.
|
var_2 LIKE struc-comp1.
|
||||||
|
|
||||||
"Variables with reference to a structured data object
|
"Variables with reference to a structured data object
|
||||||
DATA ref_struc_1 TYPE REF TO structured_type.
|
DATA ref_struc_1 TYPE REF TO structured_type.
|
||||||
@@ -302,7 +302,7 @@ DATA(ref_struc_2) = NEW structured_type( ).
|
|||||||
|
|
||||||
Nested components can be addressed using chaining:
|
Nested components can be addressed using chaining:
|
||||||
``` abap
|
``` abap
|
||||||
... structure-substructure-comp1 ...
|
... struc-substructure-comp1 ...
|
||||||
... address_n-name-title ...
|
... address_n-name-title ...
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -351,8 +351,8 @@ address-city = `349875 Botanica`.
|
|||||||
``` abap
|
``` abap
|
||||||
"# used: type of the operand can be implicitly derived
|
"# used: type of the operand can be implicitly derived
|
||||||
address = VALUE #( name = `Mr. Duncan Pea`
|
address = VALUE #( name = `Mr. Duncan Pea`
|
||||||
street = `Vegetable Lane 11`.
|
street = `Vegetable Lane 11`.
|
||||||
city = `349875 Botanica` ).
|
city = `349875 Botanica` ).
|
||||||
|
|
||||||
"Declaring a structure inline
|
"Declaring a structure inline
|
||||||
"Type used explicitly: type of the operand cannot be implicitly derived
|
"Type used explicitly: type of the operand cannot be implicitly derived
|
||||||
@@ -425,13 +425,11 @@ diff_struc = CORRESPONDING #( BASE ( diff_struc ) struc ).
|
|||||||
"assigned to the components of a target structure in mapping
|
"assigned to the components of a target structure in mapping
|
||||||
"relationships.
|
"relationships.
|
||||||
|
|
||||||
diff_struc = CORRESPONDING #( BASE ( diff_struc )
|
diff_struc = CORRESPONDING #( BASE ( diff_struc ) struc MAPPING comp1 = compa ).
|
||||||
struc MAPPING comp1 = compa ).
|
|
||||||
|
|
||||||
"EXCEPT addition: Excluding components from the assignment.
|
"EXCEPT addition: Excluding components from the assignment.
|
||||||
|
|
||||||
diff_struc = CORRESPONDING #( BASE ( diff_struc )
|
diff_struc = CORRESPONDING #( BASE ( diff_struc ) struc EXCEPT comp1 ).
|
||||||
struc EXCEPT comp1 ).
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Value assignments in deep structures
|
Value assignments in deep structures
|
||||||
@@ -449,22 +447,19 @@ MOVE-CORRESPONDING deep_struc TO diff_deep_struc.
|
|||||||
"Existing internal table content is replaced but the value
|
"Existing internal table content is replaced but the value
|
||||||
"assignment happens for identically named components only.
|
"assignment happens for identically named components only.
|
||||||
|
|
||||||
MOVE-CORRESPONDING deep_struc TO diff_deep_struc
|
MOVE-CORRESPONDING deep_struc TO diff_deep_struc EXPANDING NESTED TABLES.
|
||||||
EXPANDING NESTED TABLES.
|
|
||||||
|
|
||||||
"Existing internal table content is kept; table content of the source
|
"Existing internal table content is kept; table content of the source
|
||||||
"structure are added but the value assignment happens like the first
|
"structure are added but the value assignment happens like the first
|
||||||
"MOVE-CORRESPONDING statement without further syntax additions.
|
"MOVE-CORRESPONDING statement without further syntax additions.
|
||||||
|
|
||||||
MOVE-CORRESPONDING deep_struc TO diff_deep_struc
|
MOVE-CORRESPONDING deep_struc TO diff_deep_struc KEEPING TARGET LINES.
|
||||||
KEEPING TARGET LINES.
|
|
||||||
|
|
||||||
"Existing internal table content is kept; table content of the source
|
"Existing internal table content is kept; table content of the source
|
||||||
"structure are added; the value assignment happens like the statement
|
"structure are added; the value assignment happens like the statement
|
||||||
"MOVE-CORRESPONDING ... EXPANDING NESTED TABLES.
|
"MOVE-CORRESPONDING ... EXPANDING NESTED TABLES.
|
||||||
|
|
||||||
MOVE-CORRESPONDING deep_struc TO diff_deep_struc
|
MOVE-CORRESPONDING deep_struc TO diff_deep_struc EXPANDING NESTED TABLES KEEPING TARGET LINES.
|
||||||
EXPANDING NESTED TABLES KEEPING TARGET LINES.
|
|
||||||
|
|
||||||
"Target structure is initialized; the value assignment for an internal
|
"Target structure is initialized; the value assignment for an internal
|
||||||
"table happens irrespective of identically named components.
|
"table happens irrespective of identically named components.
|
||||||
@@ -506,14 +501,13 @@ diff_deep_struc = CORRESPONDING #( DEEP APPENDING BASE ( diff_struc ) deep_struc
|
|||||||
## Clearing Structures
|
## Clearing Structures
|
||||||
You can reset individual components to their initial values and clear the
|
You can reset individual components to their initial values and clear the
|
||||||
entire structure using the [`CLEAR`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapclear.htm) keyword.
|
entire structure using the [`CLEAR`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapclear.htm) keyword.
|
||||||
```
|
``` abap
|
||||||
CLEAR structure-component.
|
CLEAR struc-component.
|
||||||
|
|
||||||
CLEAR structure.
|
CLEAR struc.
|
||||||
|
|
||||||
"Note: Watch out when using the VALUE operator. An assignment as follows also
|
"Note: An assignment using the VALUE operator without entries in the parentheses clears the structure.
|
||||||
"clears the structure.
|
struc = VALUE #( ).
|
||||||
structure = VALUE #( ).
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Processing Structures
|
## Processing Structures
|
||||||
@@ -529,34 +523,34 @@ addition reads only a single row into the structure. It returns the first entry
|
|||||||
DATA ls_fli1 TYPE zdemo_abap_fli.
|
DATA ls_fli1 TYPE zdemo_abap_fli.
|
||||||
|
|
||||||
SELECT SINGLE FROM zdemo_abap_fli
|
SELECT SINGLE FROM zdemo_abap_fli
|
||||||
FIELDS *
|
FIELDS *
|
||||||
WHERE carrid = 'LH'
|
WHERE carrid = 'LH'
|
||||||
INTO @ls_fli1.
|
INTO @ls_fli1.
|
||||||
|
|
||||||
"Target structure declared inline
|
"Target structure declared inline
|
||||||
SELECT SINGLE FROM zdemo_abap_fli
|
SELECT SINGLE FROM zdemo_abap_fli
|
||||||
FIELDS *
|
FIELDS *
|
||||||
WHERE carrid = 'LH'
|
WHERE carrid = 'LH'
|
||||||
INTO @DATA(ls_fli2).
|
INTO @DATA(ls_fli2).
|
||||||
```
|
```
|
||||||
**Reading a row from a database table into a structure that has an incompatible type**.
|
**Reading a row from a database table into a structure that has an incompatible type**.
|
||||||
Components in the structure with identical names are filled.
|
Components in the structure with identical names are filled.
|
||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
SELECT SINGLE FROM zdemo_abap_fli
|
SELECT SINGLE FROM zdemo_abap_fli
|
||||||
FIELDS *
|
FIELDS *
|
||||||
WHERE carrid = 'AA'
|
WHERE carrid = 'AA'
|
||||||
INTO CORRESPONDING FIELDS OF @ls_fli_diff.
|
INTO CORRESPONDING FIELDS OF @ls_fli_diff.
|
||||||
```
|
```
|
||||||
**Reading a line from an internal table into a structure** ...
|
**Reading a line from an internal table into a structure** ...
|
||||||
|
|
||||||
... using a `SELECT` statement. Note the specified alias name and that ABAP variables like internal tables must be escaped with `@`. The addition `INTO CORRESPONDING FIELDS OF` also applies here.
|
... using a `SELECT` statement. Note the specified alias name and that ABAP variables like internal tables must be escaped with `@`. The addition `INTO CORRESPONDING FIELDS OF` also applies here.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT SINGLE FROM @itab AS itab_alias
|
SELECT SINGLE FROM @itab AS itab_alias
|
||||||
FIELDS *
|
FIELDS *
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO @DATA(ls_struc).
|
INTO @DATA(ls_struc).
|
||||||
"INTO CORRESPONDING FIELDS OF @some_existing_struc.
|
"INTO CORRESPONDING FIELDS OF @some_existing_struc.
|
||||||
```
|
```
|
||||||
... using a `READ TABLE` statement. The code snippet below shows the reading of a line into a [work area](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenwork_area_glosry.htm "Glossary Entry"), a [field symbol](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm "Glossary Entry"), and a [data reference variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_reference_variable_glosry.htm "Glossary Entry"), all of which
|
... using a `READ TABLE` statement. The code snippet below shows the reading of a line into a [work area](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenwork_area_glosry.htm "Glossary Entry"), a [field symbol](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm "Glossary Entry"), and a [data reference variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_reference_variable_glosry.htm "Glossary Entry"), all of which
|
||||||
represent structured data objects that are declared inline. In the following example, a line is read based on the line number by
|
represent structured data objects that are declared inline. In the following example, a line is read based on the line number by
|
||||||
@@ -580,20 +574,20 @@ DATA(ls_table_exp) = itab[ 3 ].
|
|||||||
In the following example, the row found and returned in a structure declared inline can be processed further.
|
In the following example, the row found and returned in a structure declared inline can be processed further.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM zdemo_abap_fli
|
SELECT FROM zdemo_abap_fli
|
||||||
FIELDS *
|
FIELDS *
|
||||||
WHERE carrid = 'AZ'
|
WHERE carrid = 'AZ'
|
||||||
INTO @DATA(ls_sel_loop).
|
INTO @DATA(ls_sel_loop).
|
||||||
|
|
||||||
IF sy-subrc = 0.
|
IF sy-subrc = 0.
|
||||||
...
|
...
|
||||||
ENDIF.
|
ENDIF.
|
||||||
ENDSELECT.
|
ENDSELECT.
|
||||||
```
|
```
|
||||||
... a line from an internal table into a structure using a [`LOOP AT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaploop_at_itab_variants.htm) statement. There are many ways to specify the condition on which the loop is based. The following example covers the option of reading all lines sequentially into a field symbol declared inline. When using a field symbol, you can, for example, directly modify components.
|
... a line from an internal table into a structure using a [`LOOP AT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaploop_at_itab_variants.htm) statement. There are many ways to specify the condition on which the loop is based. The following example covers the option of reading all lines sequentially into a field symbol declared inline. When using a field symbol, you can, for example, directly modify components.
|
||||||
``` abap
|
``` abap
|
||||||
LOOP AT itab ASSIGNING FIELD-SYMBOL(<fs>).
|
LOOP AT itab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
<fs>-comp1 = ...
|
<fs>-comp1 = ...
|
||||||
...
|
...
|
||||||
ENDLOOP.
|
ENDLOOP.
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -601,15 +595,15 @@ ENDLOOP.
|
|||||||
[`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.
|
[`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.
|
||||||
``` abap
|
``` abap
|
||||||
INSERT INTO dbtab VALUES @structure.
|
INSERT INTO dbtab VALUES @struc.
|
||||||
|
|
||||||
INSERT dbtab FROM @structure.
|
INSERT dbtab FROM @struc.
|
||||||
|
|
||||||
INSERT dbtab FROM @( VALUE #( comp1 = ... comp2 = ... ) ).
|
INSERT dbtab FROM @( VALUE #( comp1 = ... comp2 = ... ) ).
|
||||||
```
|
```
|
||||||
**Updating a single row in a database table from a structure** using ABAP SQL statements with [`UPDATE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapupdate.htm). Note that this syntax changes the entire row and all of its components.
|
**Updating a single row in a database table from a structure** using ABAP SQL statements with [`UPDATE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapupdate.htm). Note that this syntax changes the entire row and all of its components.
|
||||||
``` abap
|
``` abap
|
||||||
UPDATE dbtab FROM @structure.
|
UPDATE dbtab FROM @struc.
|
||||||
|
|
||||||
UPDATE dbtab FROM @( VALUE #( comp1 = ... comp2 = ... ) ).
|
UPDATE dbtab FROM @( VALUE #( comp1 = ... comp2 = ... ) ).
|
||||||
```
|
```
|
||||||
@@ -625,7 +619,7 @@ UPDATE dbtab FROM @( VALUE #( BASE wa comp2 = ... comp4 = ... ) ).
|
|||||||
**Updating or creating a single row in a database table from a structure** using ABAP SQL statements with
|
**Updating or creating a single row in a database table from a structure** using ABAP SQL statements with
|
||||||
[`MODIFY`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmodify_dbtab.htm). If a row with the same key as specified in the structure already exists in the database table, the row is updated. If no row with the keys specified in the structure exists, a new row is created in the database table.
|
[`MODIFY`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmodify_dbtab.htm). If a row with the same key as specified in the structure already exists in the database table, the row is updated. If no row with the keys specified in the structure exists, a new row is created in the database table.
|
||||||
``` abap
|
``` abap
|
||||||
MODIFY dbtab FROM @structure.
|
MODIFY dbtab FROM @struc.
|
||||||
|
|
||||||
MODIFY dbtab FROM @( VALUE #( comp1 = ... comp2 = ... ) ).
|
MODIFY dbtab FROM @( VALUE #( comp1 = ... comp2 = ... ) ).
|
||||||
```
|
```
|
||||||
@@ -638,11 +632,11 @@ internal table, `INSERT` can be used to add lines at a specific position in the
|
|||||||
- Statements using the `VALUE` operator to directly create and populate the structures are also possible. For more information and code
|
- Statements using the `VALUE` operator to directly create and populate the structures are also possible. For more information and code
|
||||||
snippets, see the [Working with Internal Tables](01_Internal_Tables.md#) cheat sheet.
|
snippets, see the [Working with Internal Tables](01_Internal_Tables.md#) cheat sheet.
|
||||||
``` abap
|
``` abap
|
||||||
INSERT structure INTO TABLE itab.
|
INSERT struc INTO TABLE itab.
|
||||||
|
|
||||||
APPEND structure TO itab.
|
APPEND struc TO itab.
|
||||||
|
|
||||||
MODIFY TABLE itab FROM structure.
|
MODIFY TABLE itab FROM struc.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Excursion: Including Structures
|
## Excursion: Including Structures
|
||||||
@@ -664,25 +658,25 @@ in the context of local structures.
|
|||||||
The following example shows how structured types and data objects are included in another structure. First, three structured types and a structured data object based on one of these types are created. Then, the types and the structure are included in the structured type `address_type`. The executable example demonstrates a structure that includes other structures in this way.
|
The following example shows how structured types and data objects are included in another structure. First, three structured types and a structured data object based on one of these types are created. Then, the types and the structure are included in the structured type `address_type`. The executable example demonstrates a structure that includes other structures in this way.
|
||||||
``` abap
|
``` abap
|
||||||
TYPES: BEGIN OF name_type,
|
TYPES: BEGIN OF name_type,
|
||||||
title TYPE string,
|
title TYPE string,
|
||||||
prename TYPE string,
|
prename TYPE string,
|
||||||
surname TYPE string,
|
surname TYPE string,
|
||||||
END OF name_type,
|
END OF name_type,
|
||||||
BEGIN OF street_type,
|
BEGIN OF street_type,
|
||||||
name TYPE string,
|
name TYPE string,
|
||||||
number TYPE string,
|
num TYPE string,
|
||||||
END OF street_type,
|
END OF street_type,
|
||||||
BEGIN OF city_type,
|
BEGIN OF city_type,
|
||||||
zipcode TYPE string,
|
zipcode TYPE string,
|
||||||
name TYPE string,
|
name TYPE string,
|
||||||
END OF city_type.
|
END OF city_type.
|
||||||
|
|
||||||
DATA city_struc TYPE city_type.
|
DATA city_struc TYPE city_type.
|
||||||
|
|
||||||
TYPES BEGIN OF address_type.
|
TYPES BEGIN OF address_type.
|
||||||
INCLUDE TYPE name_type AS name.
|
INCLUDE TYPE name_type AS name.
|
||||||
INCLUDE TYPE street_type AS street RENAMING WITH SUFFIX _street.
|
INCLUDE TYPE street_type AS street RENAMING WITH SUFFIX _street.
|
||||||
INCLUDE STRUCTURE city_struc AS city RENAMING WITH SUFFIX _city.
|
INCLUDE STRUCTURE city_struc AS city RENAMING WITH SUFFIX _city.
|
||||||
TYPES END OF address_type.
|
TYPES END OF address_type.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
469
03_ABAP_SQL.md
469
03_ABAP_SQL.md
@@ -132,9 +132,9 @@ The `SELECT` statement includes several clauses that serve
|
|||||||
different purposes. The following code snippet shows the basic syntax:
|
different purposes. The following code snippet shows the basic syntax:
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM source "What database table or view to read from
|
SELECT FROM source "What database table or view to read from
|
||||||
FIELDS field_list "What columns should be read
|
FIELDS field_list "What columns should be read
|
||||||
WHERE condition "Specifies conditions on which a row/rows should be read
|
WHERE condition "Specifies conditions on which a row/rows should be read
|
||||||
INTO @target. "Data object to which the result set is assigned (preceded by @)
|
INTO @target. "Data object to which the result set is assigned (preceded by @)
|
||||||
```
|
```
|
||||||
> **💡 Note**<br>
|
> **💡 Note**<br>
|
||||||
>- There are further clauses available of which some are dealt with
|
>- There are further clauses available of which some are dealt with
|
||||||
@@ -151,12 +151,12 @@ SELECT FROM source "What database table or view to read from
|
|||||||
keyword before the `FROM` clause - without `FIELDS`. The
|
keyword before the `FROM` clause - without `FIELDS`. The
|
||||||
following two `SELECT` statements are basically the same but differently arranged:
|
following two `SELECT` statements are basically the same but differently arranged:
|
||||||
> ``` abap
|
> ``` abap
|
||||||
> SELECT FROM dbtab
|
> SELECT FROM dbtab
|
||||||
> FIELDS comp1, comp2, comp3
|
> FIELDS comp1, comp2, comp3
|
||||||
> ...
|
> ...
|
||||||
>
|
>
|
||||||
> SELECT comp1, comp2, comp3
|
> SELECT comp1, comp2, comp3
|
||||||
> FROM dbtab
|
> FROM dbtab
|
||||||
> ...
|
> ...
|
||||||
> ```
|
> ```
|
||||||
>- Regarding the target into which data is read: Instead of using a
|
>- Regarding the target into which data is read: Instead of using a
|
||||||
@@ -185,16 +185,16 @@ SELECT FROM source "What database table or view to read from
|
|||||||
"the result.
|
"the result.
|
||||||
|
|
||||||
SELECT SINGLE FROM dbtab
|
SELECT SINGLE FROM dbtab
|
||||||
FIELDS *
|
FIELDS *
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO @struc. "Existing structure of dbtab's row type
|
INTO @struc. "Existing structure of dbtab's row type
|
||||||
|
|
||||||
"Reading a selected set of fields of a single row
|
"Reading a selected set of fields of a single row
|
||||||
|
|
||||||
SELECT SINGLE FROM dbtab
|
SELECT SINGLE FROM dbtab
|
||||||
FIELDS comp1, comp2, comp3
|
FIELDS comp1, comp2, comp3
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO @DATA(struc2). "Structure declared inline
|
INTO @DATA(struc2). "Structure declared inline
|
||||||
|
|
||||||
"Alternative syntax without the FIELDS addition
|
"Alternative syntax without the FIELDS addition
|
||||||
"Here, the CORRESPONDING FIELDS OF addition is used. Only the content of
|
"Here, the CORRESPONDING FIELDS OF addition is used. Only the content of
|
||||||
@@ -202,9 +202,9 @@ SELECT SINGLE FROM dbtab
|
|||||||
"is assigned.
|
"is assigned.
|
||||||
|
|
||||||
SELECT SINGLE comp1, comp2, comp3 "Selected set of fields
|
SELECT SINGLE comp1, comp2, comp3 "Selected set of fields
|
||||||
FROM dbtab
|
FROM dbtab
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO CORRESPONDING FIELDS OF @struc. "Existing structure
|
INTO CORRESPONDING FIELDS OF @struc. "Existing structure
|
||||||
```
|
```
|
||||||
> **💡 Note**<br>
|
> **💡 Note**<br>
|
||||||
>- Although its use is optional, a `WHERE` clause should be specified to further restrict the read result.
|
>- Although its use is optional, a `WHERE` clause should be specified to further restrict the read result.
|
||||||
@@ -215,24 +215,24 @@ SELECT SINGLE comp1, comp2, comp3 "Selected set of fields
|
|||||||
**Reading multiple rows into an internal table**.
|
**Reading multiple rows into an internal table**.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS * "All fields
|
FIELDS * "All fields
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO TABLE @itab. "itab has an appropriate row type
|
INTO TABLE @itab. "itab has an appropriate row type
|
||||||
|
|
||||||
"Alternative syntax without the FIELDS addition
|
"Alternative syntax without the FIELDS addition
|
||||||
|
|
||||||
SELECT comp1, comp2, comp3 "Selected set of fields
|
SELECT comp1, comp2, comp3 "Selected set of fields
|
||||||
FROM dbtab
|
FROM dbtab
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO TABLE @DATA(lv_itab). "Internal table declared inline
|
INTO TABLE @DATA(lv_itab). "Internal table declared inline
|
||||||
|
|
||||||
"Selected set of fields, existing variable
|
"Selected set of fields, existing variable
|
||||||
"See the note on CORRESPONDING FIELDS OF above
|
"See the note on CORRESPONDING FIELDS OF above
|
||||||
|
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS comp1, comp2, comp3 "Selected set of fields
|
FIELDS comp1, comp2, comp3 "Selected set of fields
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO CORRESPONDING FIELDS OF TABLE @itab.
|
INTO CORRESPONDING FIELDS OF TABLE @itab.
|
||||||
```
|
```
|
||||||
|
|
||||||
**`SELECT` loop: Sequentially reading multiple rows**.
|
**`SELECT` loop: Sequentially reading multiple rows**.
|
||||||
@@ -244,12 +244,15 @@ SELECT FROM dbtab
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS *
|
FIELDS *
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO @struc.
|
INTO @struc.
|
||||||
IF sy-subrc = 0.
|
|
||||||
|
IF sy-subrc = 0.
|
||||||
... "For example, making changes on data and adding the row to an internal table.
|
... "For example, making changes on data and adding the row to an internal table.
|
||||||
ENDIF.
|
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
ENDSELECT.
|
ENDSELECT.
|
||||||
```
|
```
|
||||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||||
@@ -263,9 +266,9 @@ ENDSELECT.
|
|||||||
"Instead of @abap_true, you could also use 'X'.
|
"Instead of @abap_true, you could also use 'X'.
|
||||||
|
|
||||||
SELECT SINGLE @abap_true
|
SELECT SINGLE @abap_true
|
||||||
FROM dbtab
|
FROM dbtab
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO @DATA(exists).
|
INTO @DATA(exists).
|
||||||
|
|
||||||
IF exists = abap_true.
|
IF exists = abap_true.
|
||||||
...
|
...
|
||||||
@@ -277,9 +280,9 @@ ENDIF.
|
|||||||
- See more information here [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapselect_clause.htm).
|
- See more information here [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapselect_clause.htm).
|
||||||
``` abap
|
``` abap
|
||||||
SELECT DISTINCT comp1
|
SELECT DISTINCT comp1
|
||||||
FROM dbtab
|
FROM dbtab
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO TABLE @itab.
|
INTO TABLE @itab.
|
||||||
```
|
```
|
||||||
|
|
||||||
**SELECT list variants** (some of them are already outlined above)
|
**SELECT list variants** (some of them are already outlined above)
|
||||||
@@ -329,9 +332,9 @@ SELECT dbtab~*
|
|||||||
"specify an alias name for the database column to match a component's name in the target data object.
|
"specify an alias name for the database column to match a component's name in the target data object.
|
||||||
|
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS comp1 AS comp_a, comp2 AS comp_b, comp3 AS comp_c
|
FIELDS comp1 AS comp_a, comp2 AS comp_b, comp3 AS comp_c
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO CORRESPONDING FIELDS OF TABLE @itab.
|
INTO CORRESPONDING FIELDS OF TABLE @itab.
|
||||||
|
|
||||||
"Alias name also possible for the data source
|
"Alias name also possible for the data source
|
||||||
SELECT ds~col1, ds~col2, ds~col3
|
SELECT ds~col1, ds~col2, ds~col3
|
||||||
@@ -346,15 +349,15 @@ SELECT ds~col1, ds~col2, ds~col3
|
|||||||
|
|
||||||
"Replaces the current client with the specified client
|
"Replaces the current client with the specified client
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM dbtab USING CLIENT '000'
|
FROM dbtab USING CLIENT '000'
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO TABLE @itab.
|
INTO TABLE @itab.
|
||||||
|
|
||||||
"Selects data of any number of clients
|
"Selects data of any number of clients
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM dbtab USING ALL CLIENTS
|
FROM dbtab USING ALL CLIENTS
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO TABLE @itab.
|
INTO TABLE @itab.
|
||||||
```
|
```
|
||||||
|
|
||||||
**Reading data from an internal table as data source** using `SELECT`. Note that an alias name must be specified for the internal table used as data source.
|
**Reading data from an internal table as data source** using `SELECT`. Note that an alias name must be specified for the internal table used as data source.
|
||||||
@@ -362,9 +365,9 @@ Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOU
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM @itab1 AS tab
|
FROM @itab1 AS tab
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO TABLE @DATA(itab2).
|
INTO TABLE @DATA(itab2).
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -377,9 +380,9 @@ ROWS`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file
|
|||||||
"A maximum of five rows are to be returned
|
"A maximum of five rows are to be returned
|
||||||
"If the INTO clause is the last clause, the UP TO clause must be positioned after it.
|
"If the INTO clause is the last clause, the UP TO clause must be positioned after it.
|
||||||
SELECT * FROM dbtab
|
SELECT * FROM dbtab
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO TABLE @DATA(itab_upto)
|
INTO TABLE @DATA(itab_upto)
|
||||||
UP TO 5 ROWS.
|
UP TO 5 ROWS.
|
||||||
```
|
```
|
||||||
|
|
||||||
**Returning only the table rows after a row with a specified count from the result set** using the optional addition [`OFFSET n`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapselect_up_to_offset.htm#!ABAP_ADDITION_2@2@). You can only use the addition, if an `ORDER BY` clause is specified.
|
**Returning only the table rows after a row with a specified count from the result set** using the optional addition [`OFFSET n`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapselect_up_to_offset.htm#!ABAP_ADDITION_2@2@). You can only use the addition, if an `ORDER BY` clause is specified.
|
||||||
@@ -407,10 +410,10 @@ Note:
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS comp1, comp2, comp3
|
FIELDS comp1, comp2, comp3
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO (@res1,@res2,@res3).
|
INTO (@res1,@res2,@res3).
|
||||||
"INTO (@DATA(res1),@DATA(res2),@DATA(res3)). "Using inline declarations
|
"INTO (@DATA(res1),@DATA(res2),@DATA(res3)). "Using inline declarations
|
||||||
```
|
```
|
||||||
|
|
||||||
**Appending the result set to an existing internal table**.
|
**Appending the result set to an existing internal table**.
|
||||||
@@ -418,20 +421,20 @@ The addition `INTO` initializes the target object. When using the addition `APPE
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
SELECT * FROM dbtab
|
SELECT * FROM dbtab
|
||||||
WHERE ...
|
WHERE ...
|
||||||
APPENDING TABLE @itab.
|
APPENDING TABLE @itab.
|
||||||
|
|
||||||
SELECT * FROM dbtab
|
SELECT * FROM dbtab
|
||||||
WHERE ...
|
WHERE ...
|
||||||
APPENDING CORRESPONDING FIELDS OF TABLE @diff_itab.
|
APPENDING CORRESPONDING FIELDS OF TABLE @diff_itab.
|
||||||
```
|
```
|
||||||
|
|
||||||
**Reading into packages of a specified number of rows** when reading into internal tables. The addition [`PACKAGE SIZE n`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapinto_clause.htm#!ABAP_ONE_ADD@1@) can be specified after `INTO TABLE` and `APPENDING TABLE`. A `SELECT` loop ist opened. After `PACKAGE SIZE`, the number of rows is specified (which can be a host variable, host expression or a literal of type `i`) denoting the number of rows to be inserted in the target object per iteration.
|
**Reading into packages of a specified number of rows** when reading into internal tables. The addition [`PACKAGE SIZE n`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapinto_clause.htm#!ABAP_ONE_ADD@1@) can be specified after `INTO TABLE` and `APPENDING TABLE`. A `SELECT` loop ist opened. After `PACKAGE SIZE`, the number of rows is specified (which can be a host variable, host expression or a literal of type `i`) denoting the number of rows to be inserted in the target object per iteration.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS comp1, comp2, comp3
|
FIELDS comp1, comp2, comp3
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO TABLE @DATA(itab_pack) PACKAGE SIZE n.
|
INTO TABLE @DATA(itab_pack) PACKAGE SIZE n.
|
||||||
...
|
...
|
||||||
ENDSELECT.
|
ENDSELECT.
|
||||||
```
|
```
|
||||||
@@ -441,8 +444,8 @@ ENDSELECT.
|
|||||||
``` abap
|
``` abap
|
||||||
"Here, the target object is an anonymous data object declared inline.
|
"Here, the target object is an anonymous data object declared inline.
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS comp1, comp2, comp3
|
FIELDS comp1, comp2, comp3
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO TABLE NEW @DATA(dref).
|
INTO TABLE NEW @DATA(dref).
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -470,10 +473,10 @@ as shown in the following example.
|
|||||||
In the example below, the database table rows that have the same content in column `comp1` are combined. The lowest and highest values in column `comp2` are determined for each of these groups and placed into the combined row.
|
In the example below, the database table rows that have the same content in column `comp1` are combined. The lowest and highest values in column `comp2` are determined for each of these groups and placed into the combined row.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS comp1, MIN( comp2 ) AS min, MAX( comp2 ) AS max
|
FIELDS comp1, MIN( comp2 ) AS min, MAX( comp2 ) AS max
|
||||||
WHERE ...
|
WHERE ...
|
||||||
GROUP BY comp1
|
GROUP BY comp1
|
||||||
INTO ...
|
INTO ...
|
||||||
```
|
```
|
||||||
|
|
||||||
[`HAVING`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaphaving_clause.htm)
|
[`HAVING`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaphaving_clause.htm)
|
||||||
@@ -483,11 +486,11 @@ logical expression is true are inserted in the target variable. Note
|
|||||||
that `HAVING` can only be used together with `GROUP BY`.
|
that `HAVING` can only be used together with `GROUP BY`.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS comp1, MIN( comp2 ) AS min, MAX( comp3 ) AS max
|
FIELDS comp1, MIN( comp2 ) AS min, MAX( comp3 ) AS max
|
||||||
WHERE ...
|
WHERE ...
|
||||||
GROUP BY comp1
|
GROUP BY comp1
|
||||||
HAVING comp1 LIKE '%XYZ%' AND SUM( comp4 ) > 100
|
HAVING comp1 LIKE '%XYZ%' AND SUM( comp4 ) > 100
|
||||||
INTO ...
|
INTO ...
|
||||||
```
|
```
|
||||||
|
|
||||||
[`ORDER BY`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaporderby_clause.htm)
|
[`ORDER BY`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaporderby_clause.htm)
|
||||||
@@ -501,12 +504,12 @@ order. There are more ordering options, for example, by using SQL
|
|||||||
expressions.
|
expressions.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS comp1, comp2, comp3
|
FIELDS comp1, comp2, comp3
|
||||||
WHERE ...
|
WHERE ...
|
||||||
ORDER BY PRIMARY KEY
|
ORDER BY PRIMARY KEY
|
||||||
"comp2 ASCENDING
|
"comp2 ASCENDING
|
||||||
"comp2 DESCENDING
|
"comp2 DESCENDING
|
||||||
INTO ...
|
INTO ...
|
||||||
```
|
```
|
||||||
|
|
||||||
> **💡 Note**<br>
|
> **💡 Note**<br>
|
||||||
@@ -517,10 +520,10 @@ SELECT FROM dbtab
|
|||||||
[`WHERE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapwhere.htm) clause: Restricts the number of rows that are included in the result set using logical expressions. See further information on them in the following sections.
|
[`WHERE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapwhere.htm) clause: Restricts the number of rows that are included in the result set using logical expressions. See further information on them in the following sections.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab
|
SELECT FROM dbtab
|
||||||
FIELDS comp1, comp2, comp3
|
FIELDS comp1, comp2, comp3
|
||||||
WHERE comp1 = 'abc'
|
WHERE comp1 = 'abc'
|
||||||
AND comp2 < 123
|
AND comp2 < 123
|
||||||
INTO ...
|
INTO ...
|
||||||
```
|
```
|
||||||
|
|
||||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||||
@@ -574,35 +577,35 @@ Example demonstrating possible operands:
|
|||||||
DATA upto TYPE i VALUE 3.
|
DATA upto TYPE i VALUE 3.
|
||||||
|
|
||||||
SELECT FROM zdemo_abap_flsch
|
SELECT FROM zdemo_abap_flsch
|
||||||
FIELDS
|
FIELDS
|
||||||
"Specifies a column of a data source directly using its name
|
"Specifies a column of a data source directly using its name
|
||||||
cityfrom,
|
cityfrom,
|
||||||
|
|
||||||
"Column selector ~ can be used to prefix every specified column.
|
"Column selector ~ can be used to prefix every specified column.
|
||||||
"Here, it is optional. It is non-optional, e. g., if multiple data
|
"Here, it is optional. It is non-optional, e. g., if multiple data
|
||||||
"sources in an ABAP SQL statement are edited and the column name
|
"sources in an ABAP SQL statement are edited and the column name
|
||||||
"is not unique.
|
"is not unique.
|
||||||
zdemo_abap_flsch~cityto,
|
zdemo_abap_flsch~cityto,
|
||||||
|
|
||||||
'Lufthansa' AS name, "Untyped literal
|
'Lufthansa' AS name, "Untyped literal
|
||||||
|
|
||||||
char`X` AS flag, "Typed literal
|
char`X` AS flag, "Typed literal
|
||||||
|
|
||||||
@upto AS num, "Host variable
|
@upto AS num, "Host variable
|
||||||
|
|
||||||
@( cl_abap_context_info=>get_system_date( ) ) as date "Host expression
|
@( cl_abap_context_info=>get_system_date( ) ) as date "Host expression
|
||||||
|
|
||||||
WHERE carrid = 'LH' "Untyped literal
|
WHERE carrid = 'LH' "Untyped literal
|
||||||
AND countryfr = char`DE` "Typed literal
|
AND countryfr = char`DE` "Typed literal
|
||||||
|
|
||||||
"Data object created inline and escaped with @
|
"Data object created inline and escaped with @
|
||||||
INTO TABLE @DATA(it)
|
INTO TABLE @DATA(it)
|
||||||
|
|
||||||
"The following clause shows all options having the same effect
|
"The following clause shows all options having the same effect
|
||||||
UP TO 3 ROWS. "Untyped numeric literal
|
UP TO 3 ROWS. "Untyped numeric literal
|
||||||
"UP TO int4`3` ROWS. "Typed numeric literal
|
"UP TO int4`3` ROWS. "Typed numeric literal
|
||||||
"UP TO @upto ROWS. "Host variable
|
"UP TO @upto ROWS. "Host variable
|
||||||
"UP TO @( 10 - 7 ) ROWS. "Host expression
|
"UP TO @( 10 - 7 ) ROWS. "Host expression
|
||||||
```
|
```
|
||||||
|
|
||||||
**SQL Expressions**
|
**SQL Expressions**
|
||||||
@@ -637,40 +640,40 @@ SELECT FROM zdemo_abap_flsch
|
|||||||
Example: [Numeric functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_arith_func.htm)
|
Example: [Numeric functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_arith_func.htm)
|
||||||
``` abap
|
``` abap
|
||||||
SELECT SINGLE
|
SELECT SINGLE
|
||||||
carrname,
|
carrname,
|
||||||
|
|
||||||
"Division, result rounded to an integer
|
"Division, result rounded to an integer
|
||||||
"Result: 2
|
"Result: 2
|
||||||
div( 4, 2 ) AS div,
|
div( 4, 2 ) AS div,
|
||||||
|
|
||||||
"Division, 3rd argument: result is rounded to the specified
|
"Division, 3rd argument: result is rounded to the specified
|
||||||
"number of decimals
|
"number of decimals
|
||||||
"Result: 0.33
|
"Result: 0.33
|
||||||
division( 1, 3, 2 ) AS division,
|
division( 1, 3, 2 ) AS division,
|
||||||
|
|
||||||
"Result is rounded to first greater integer
|
"Result is rounded to first greater integer
|
||||||
"Result: 2
|
"Result: 2
|
||||||
ceil( decfloat34`1.333` ) AS ceil,
|
ceil( decfloat34`1.333` ) AS ceil,
|
||||||
|
|
||||||
"Result is the remainder of division
|
"Result is the remainder of division
|
||||||
"Result: 1
|
"Result: 1
|
||||||
mod( 3, 2 ) AS mod,
|
mod( 3, 2 ) AS mod,
|
||||||
|
|
||||||
"Result: Largest integer value not greater than the specified value
|
"Result: Largest integer value not greater than the specified value
|
||||||
"Result: 1
|
"Result: 1
|
||||||
floor( decfloat34`1.333` ) AS floor,
|
floor( decfloat34`1.333` ) AS floor,
|
||||||
|
|
||||||
"Returns the absolute number
|
"Returns the absolute number
|
||||||
"Result: 2
|
"Result: 2
|
||||||
abs( int4`-2` ) AS abs,
|
abs( int4`-2` ) AS abs,
|
||||||
|
|
||||||
"Result is rounded to the specified position after the decimal separator
|
"Result is rounded to the specified position after the decimal separator
|
||||||
"Result: 1.34
|
"Result: 1.34
|
||||||
round( decfloat34`1.337`, 2 ) AS round
|
round( decfloat34`1.337`, 2 ) AS round
|
||||||
|
|
||||||
FROM zdemo_abap_carr
|
FROM zdemo_abap_carr
|
||||||
WHERE carrid = 'AA'
|
WHERE carrid = 'AA'
|
||||||
INTO @DATA(numeric_functions).
|
INTO @DATA(numeric_functions).
|
||||||
```
|
```
|
||||||
|
|
||||||
Example: [String functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_string_func.htm)
|
Example: [String functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_string_func.htm)
|
||||||
@@ -726,7 +729,7 @@ SELECT SINGLE
|
|||||||
locate_regexpr( pcre = '\..', "Period followed by any character
|
locate_regexpr( pcre = '\..', "Period followed by any character
|
||||||
value = url,
|
value = url,
|
||||||
occurrence = 2 ) "2nd occurrence in the string
|
occurrence = 2 ) "2nd occurrence in the string
|
||||||
AS locate_regexpr,
|
AS locate_regexpr,
|
||||||
|
|
||||||
"Searches a PCRE pattern, returns offset of match + 1;
|
"Searches a PCRE pattern, returns offset of match + 1;
|
||||||
"many optional parameters: occurrence, case_sensitive, start, group
|
"many optional parameters: occurrence, case_sensitive, start, group
|
||||||
@@ -796,7 +799,7 @@ Example: [Special functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOU
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
SELECT SINGLE
|
SELECT SINGLE
|
||||||
carrid,
|
carrid,
|
||||||
|
|
||||||
"Conversion functions
|
"Conversion functions
|
||||||
"When used: Special conversions that cannot be handled in a general
|
"When used: Special conversions that cannot be handled in a general
|
||||||
@@ -804,27 +807,27 @@ SELECT SINGLE
|
|||||||
|
|
||||||
"Type conversion: string of fixed length (e.g. of type c) to variable
|
"Type conversion: string of fixed length (e.g. of type c) to variable
|
||||||
"length string of type string
|
"length string of type string
|
||||||
to_clob( carrid ) AS clob,
|
to_clob( carrid ) AS clob,
|
||||||
|
|
||||||
"Byte string -> character string
|
"Byte string -> character string
|
||||||
bintohex( raw`3599421128650F4EE00008000978B976` ) AS bintohex,
|
bintohex( raw`3599421128650F4EE00008000978B976` ) AS bintohex,
|
||||||
|
|
||||||
"Character string -> byte string
|
"Character string -> byte string
|
||||||
hextobin( char`3599421128650F4EE00008000978B976` ) AS hextobin,
|
hextobin( char`3599421128650F4EE00008000978B976` ) AS hextobin,
|
||||||
|
|
||||||
"Byte field of type RAW to a byte string (BLOB) of type RAWSTRING
|
"Byte field of type RAW to a byte string (BLOB) of type RAWSTRING
|
||||||
to_blob( raw`3599421128650F4EE00008000978B976` ) AS blob,
|
to_blob( raw`3599421128650F4EE00008000978B976` ) AS blob,
|
||||||
|
|
||||||
"Unit and currency conversion functions
|
"Unit and currency conversion functions
|
||||||
"More parameters are available.
|
"More parameters are available.
|
||||||
|
|
||||||
"Converts miles to kilometers
|
"Converts miles to kilometers
|
||||||
unit_conversion( quantity = d34n`1`,
|
unit_conversion( quantity = d34n`1`,
|
||||||
source_unit = unit`MI`,
|
source_unit = unit`MI`,
|
||||||
target_unit = unit`KM` ) AS miles_to_km,
|
target_unit = unit`KM` ) AS miles_to_km,
|
||||||
|
|
||||||
"Converts Euro to US dollars using today's rate
|
"Converts Euro to US dollars using today's rate
|
||||||
currency_conversion(
|
currency_conversion(
|
||||||
amount = d34n`1`,
|
amount = d34n`1`,
|
||||||
source_currency = char`EUR`,
|
source_currency = char`EUR`,
|
||||||
target_currency = char`USD`,
|
target_currency = char`USD`,
|
||||||
@@ -921,7 +924,7 @@ SELECT SINGLE
|
|||||||
"A cast expression converts the value of the operands to the
|
"A cast expression converts the value of the operands to the
|
||||||
"specified dictionary type. The result is a representation of the
|
"specified dictionary type. The result is a representation of the
|
||||||
"source value in the specified type.
|
"source value in the specified type.
|
||||||
CAST( 1 AS D34N ) / CAST( 2 AS D34N ) AS ratio,
|
CAST( 1 AS D34N ) / CAST( 2 AS D34N ) AS ratio,
|
||||||
|
|
||||||
"String expression using && to concatenate two character strings;
|
"String expression using && to concatenate two character strings;
|
||||||
"the result of the concatenation must not be longer than
|
"the result of the concatenation must not be longer than
|
||||||
@@ -934,22 +937,22 @@ SELECT SINGLE
|
|||||||
"operands. Result: The first operand after THEN for which the
|
"operands. Result: The first operand after THEN for which the
|
||||||
"comparison is true. If no matches are found, the result specified
|
"comparison is true. If no matches are found, the result specified
|
||||||
"after ELSE is selected.
|
"after ELSE is selected.
|
||||||
CASE currcode
|
CASE currcode
|
||||||
WHEN 'EUR' THEN 'A'
|
WHEN 'EUR' THEN 'A'
|
||||||
WHEN 'USD' THEN 'B'
|
WHEN 'USD' THEN 'B'
|
||||||
ELSE 'C'
|
ELSE 'C'
|
||||||
END AS case_simple,
|
END AS case_simple,
|
||||||
|
|
||||||
"Complex case distinction
|
"Complex case distinction
|
||||||
"The expression evaluates logical expressions. Result: The first
|
"The expression evaluates logical expressions. Result: The first
|
||||||
"operand after THEN for which the logical expression is true. If no
|
"operand after THEN for which the logical expression is true. If no
|
||||||
"logical expressions are true, the result specified after ELSE is
|
"logical expressions are true, the result specified after ELSE is
|
||||||
"selected.
|
"selected.
|
||||||
CASE WHEN length( carrname ) <= 5 THEN 'small'
|
CASE WHEN length( carrname ) <= 5 THEN 'small'
|
||||||
WHEN length( carrname ) BETWEEN 6 AND 10 THEN 'mid'
|
WHEN length( carrname ) BETWEEN 6 AND 10 THEN 'mid'
|
||||||
WHEN length( carrname ) BETWEEN 11 AND 15 THEN 'large'
|
WHEN length( carrname ) BETWEEN 11 AND 15 THEN 'large'
|
||||||
ELSE 'huge'
|
ELSE 'huge'
|
||||||
END AS case_complex
|
END AS case_complex
|
||||||
|
|
||||||
FROM zdemo_abap_carr
|
FROM zdemo_abap_carr
|
||||||
WHERE carrid = 'AA'
|
WHERE carrid = 'AA'
|
||||||
@@ -1004,40 +1007,37 @@ Examples:
|
|||||||
"Example 1: A simple window is constructed in the OVER clause;
|
"Example 1: A simple window is constructed in the OVER clause;
|
||||||
"window functions - here aggregate functions - are applied
|
"window functions - here aggregate functions - are applied
|
||||||
SELECT carrid, currency,
|
SELECT carrid, currency,
|
||||||
SUM( paymentsum ) OVER( PARTITION BY carrid ) AS sum,
|
SUM( paymentsum ) OVER( PARTITION BY carrid ) AS sum,
|
||||||
AVG( price AS DEC( 14,2 ) ) OVER( PARTITION BY carrid ) AS avg,
|
AVG( price AS DEC( 14,2 ) ) OVER( PARTITION BY carrid ) AS avg,
|
||||||
MAX( price ) OVER( PARTITION BY carrid ) AS max
|
MAX( price ) OVER( PARTITION BY carrid ) AS max
|
||||||
FROM zdemo_abap_fli
|
FROM zdemo_abap_fli
|
||||||
ORDER BY carrid
|
ORDER BY carrid
|
||||||
INTO TABLE @DATA(win).
|
INTO TABLE @DATA(win).
|
||||||
|
|
||||||
"Example 2:
|
"Example 2:
|
||||||
SELECT carrid, currency, fldate,
|
SELECT carrid, currency, fldate,
|
||||||
"Sorts the rows by some columns and counts the number of rows from
|
"Sorts the rows by some columns and counts the number of rows from
|
||||||
"the first row of the window to the current row.
|
"the first row of the window to the current row.
|
||||||
COUNT( * ) OVER( ORDER BY currency, fldate
|
COUNT( * ) OVER( ORDER BY currency, fldate
|
||||||
ROWS BETWEEN
|
ROWS BETWEEN
|
||||||
"UNBOUNDED PRECEDING: frame starts at the
|
"UNBOUNDED PRECEDING: frame starts at the first row of the window
|
||||||
"first row of the window
|
UNBOUNDED PRECEDING
|
||||||
UNBOUNDED PRECEDING
|
"CURRENT ROW: determines starting or ending at the current row; here, it ends
|
||||||
"CURRENT ROW: determines starting or ending
|
AND CURRENT ROW ) AS count1,
|
||||||
"at the current row; here, it ends
|
|
||||||
AND CURRENT ROW ) AS count1,
|
|
||||||
|
|
||||||
"If no window frame is used, the default window frame is
|
"If no window frame is used, the default window frame is
|
||||||
"BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW,
|
"BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW,
|
||||||
"i. e. the result of count1 equals the result of count2.
|
"i. e. the result of count1 equals the result of count2.
|
||||||
COUNT( * ) OVER( ORDER BY currency, fldate ) AS count2,
|
COUNT( * ) OVER( ORDER BY currency, fldate ) AS count2,
|
||||||
|
|
||||||
"Sorts the rows by some columns and counts the number of rows from
|
"Sorts the rows by some columns and counts the number of rows from
|
||||||
"the current row to the last row of the window.
|
"the current row to the last row of the window.
|
||||||
"The result is reverse numbering.
|
"The result is reverse numbering.
|
||||||
COUNT( * ) OVER( ORDER BY currency, fldate
|
COUNT( * ) OVER( ORDER BY currency, fldate
|
||||||
ROWS BETWEEN CURRENT ROW
|
ROWS BETWEEN CURRENT ROW
|
||||||
"UNBOUND FOLLOWING:
|
UNBOUND FOLLOWING:
|
||||||
"Determines the ending frame boundary,
|
"Determines the ending frame boundary, this addition specifies the last row of the window
|
||||||
"this addition specifies the last row of the window
|
AND UNBOUNDED FOLLOWING ) AS count_reverse,
|
||||||
AND UNBOUNDED FOLLOWING ) AS count_reverse,
|
|
||||||
|
|
||||||
"Sorts the rows by some columns and calculates the rolling averages
|
"Sorts the rows by some columns and calculates the rolling averages
|
||||||
"of a subset of rows from column price. The subset consists of the
|
"of a subset of rows from column price. The subset consists of the
|
||||||
@@ -1045,17 +1045,15 @@ SELECT carrid, currency, fldate,
|
|||||||
"case as below example that uses prices would be that, for example,
|
"case as below example that uses prices would be that, for example,
|
||||||
"you can calculate the 3-day-average temperature for every day from
|
"you can calculate the 3-day-average temperature for every day from
|
||||||
"a list of temperature data.
|
"a list of temperature data.
|
||||||
AVG( price AS DEC( 14,2 ) ) OVER( ORDER BY currency, fldate
|
AVG( price AS DEC( 14,2 ) ) OVER( ORDER BY currency, fldate
|
||||||
ROWS BETWEEN
|
ROWS BETWEEN
|
||||||
"n PRECEDING: for both start and end of frame;
|
"n PRECEDING: for both start and end of frame; frame to start/end n rows above the current row
|
||||||
"frame to start/end n rows above the current row
|
1 PRECEDING
|
||||||
1 PRECEDING
|
"n FOLLOWING: for both start and end of frame; frame to start/end n rows beneath the current row
|
||||||
"n FOLLOWING: for both start and end of frame;
|
AND 1 FOLLOWING ) AS avg
|
||||||
"frame to start/end n rows beneath the current row
|
|
||||||
AND 1 FOLLOWING ) AS avg
|
|
||||||
|
|
||||||
FROM zdemo_abap_fli
|
FROM zdemo_abap_fli
|
||||||
INTO TABLE @DATA(result).
|
INTO TABLE @DATA(result).
|
||||||
```
|
```
|
||||||
|
|
||||||
### Excursion: SQL Conditions
|
### Excursion: SQL Conditions
|
||||||
@@ -1096,40 +1094,40 @@ The clause parts that are commented out in the following code snippet
|
|||||||
just demonstrate how the `WHERE` clause might look like.
|
just demonstrate how the `WHERE` clause might look like.
|
||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab
|
SELECT *
|
||||||
FIELDS comp1, comp2, comp3
|
FROM dbtab
|
||||||
WHERE comp1 = 'abc' "Equals some value
|
WHERE comp1 = 'abc' "Equals some value
|
||||||
|
|
||||||
"More example WHERE conditions:
|
"More example WHERE conditions:
|
||||||
"comp2 > 100 "Greater than some value; alternatively GT is possible
|
comp2 > 100 "Greater than some value; alternatively GT is possible
|
||||||
|
|
||||||
"Not equals plus an additional condition that must be respected
|
"Not equals plus an additional condition that must be respected
|
||||||
"comp2 <> 100 AND comp4 = 'xyz'
|
comp3 <> 100 AND comp4 = 'xyz'
|
||||||
|
|
||||||
"(Not) between a value range
|
"(Not) between a value range
|
||||||
"comp1 BETWEEN 1 AND 10
|
comp5 BETWEEN 1 AND 10
|
||||||
"comp1 NOT BETWEEN 1 AND 10
|
comp6 NOT BETWEEN 1 AND 10
|
||||||
|
|
||||||
"A character literal has a certain pattern, preceded and
|
"A character literal has a certain pattern, preceded and
|
||||||
"followed by any string.
|
"followed by any string.
|
||||||
"comp1 LIKE '%XYZ%'
|
"comp7 LIKE '%XYZ%'
|
||||||
|
|
||||||
"The second character is not Y. _ stands for any character.
|
"The second character is not Y. _ stands for any character.
|
||||||
"comp1 NOT LIKE '_Y%'
|
comp8 NOT LIKE '_Y%'
|
||||||
|
|
||||||
"Contains one of the values specified in the parentheses
|
"Contains one of the values specified in the parentheses
|
||||||
"comp1 IN ( 'ABC', 'DEF', 'GHI' )
|
comp9 IN ( 'ABC', 'DEF', 'GHI' )
|
||||||
|
|
||||||
"Does not contain one of the values specified in the parentheses
|
"Does not contain one of the values specified in the parentheses
|
||||||
"comp1 NOT IN ( 'JKL', 'MNO' )
|
comp10 NOT IN ( 'JKL', 'MNO' )
|
||||||
|
|
||||||
"Checking if an operand has an initial value
|
"Checking if an operand has an initial value
|
||||||
"comp1 IS INITIAL
|
comp11 IS INITIAL
|
||||||
|
|
||||||
"Combination of logical expression using AND, OR and parentheses
|
"Combination of logical expression using AND, OR and parentheses
|
||||||
"( comp1 = a AND comp2 < b ) OR ( comp3 > c AND comp4 <> d )
|
( comp12 = a AND comp13 < b ) OR ( comp14 > c AND comp15 <> d )
|
||||||
|
|
||||||
INTO TABLE @DATA(itab_where).
|
INTO TABLE @DATA(itab_where).
|
||||||
```
|
```
|
||||||
|
|
||||||
### Selecting Data by Evaluating the Content of other Tables
|
### Selecting Data by Evaluating the Content of other Tables
|
||||||
@@ -1146,11 +1144,11 @@ addition:
|
|||||||
"Checking that table is not initial
|
"Checking that table is not initial
|
||||||
IF ( 0 < lines( itab2 ) ).
|
IF ( 0 < lines( itab2 ) ).
|
||||||
|
|
||||||
SELECT comp1, comp2, comp3
|
SELECT comp1, comp2, comp3
|
||||||
FROM dbtab
|
FROM dbtab
|
||||||
FOR ALL ENTRIES IN @itab2 "Host variable before internal table
|
FOR ALL ENTRIES IN @itab2 "Host variable before internal table
|
||||||
WHERE comp1 = @itab2-comp1 ... "Relational expression on the right side of a comparison
|
WHERE comp1 = @itab2-comp1 ... "Relational expression on the right side of a comparison
|
||||||
INTO TABLE @itab1
|
INTO TABLE @itab1
|
||||||
|
|
||||||
ENDIF.
|
ENDIF.
|
||||||
```
|
```
|
||||||
@@ -1163,11 +1161,11 @@ The following code snippet includes a parenthesized subquery following `EXISTS`.
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
SELECT comp1, comp2, comp3
|
SELECT comp1, comp2, comp3
|
||||||
FROM dbtab1 AS tab1
|
FROM dbtab1 AS tab1
|
||||||
WHERE EXISTS
|
WHERE EXISTS
|
||||||
( SELECT comp1 FROM dbtab2
|
( SELECT comp1 FROM dbtab2
|
||||||
WHERE comp1 = tab1~comp1 AND comp2 = tab1~comp2 )
|
WHERE comp1 = tab1~comp1 AND comp2 = tab1~comp2 )
|
||||||
INTO ...
|
INTO ...
|
||||||
```
|
```
|
||||||
|
|
||||||
### Combining Data of Multiple Database Tables
|
### Combining Data of Multiple Database Tables
|
||||||
@@ -1182,13 +1180,11 @@ selector](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?f
|
|||||||
`~`.
|
`~`.
|
||||||
``` abap
|
``` abap
|
||||||
SELECT a~comp1, a~comp2, b~comp3, c~comp4
|
SELECT a~comp1, a~comp2, b~comp3, c~comp4
|
||||||
FROM dbtab1 AS a
|
FROM dbtab1 AS a
|
||||||
INNER JOIN dbtab2 AS b
|
INNER JOIN dbtab2 AS b ON a~comp1 = b~comp1 AND a~comp2 = b~comp2
|
||||||
ON a~comp1 = b~comp1 AND a~comp2 = b~comp2
|
INNER JOIN dbtab3 AS c ON a~comp1 = c~comp1
|
||||||
INNER JOIN dbtab3 AS c
|
WHERE ...
|
||||||
ON a~comp1 = c~comp1
|
INTO ...
|
||||||
WHERE ...
|
|
||||||
INTO ...
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Using an [outer join](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenouter_join_glosry.htm)**:
|
**Using an [outer join](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenouter_join_glosry.htm)**:
|
||||||
@@ -1201,11 +1197,10 @@ a [right outer join](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/
|
|||||||
``` abap
|
``` abap
|
||||||
"Example for a left outer join
|
"Example for a left outer join
|
||||||
SELECT a~comp1, a~comp2, b~comp3,
|
SELECT a~comp1, a~comp2, b~comp3,
|
||||||
FROM dbtab1 AS a
|
FROM dbtab1 AS a
|
||||||
LEFT OUTER JOIN dbtab2 AS b
|
LEFT OUTER JOIN dbtab2 AS b ON a~comp1 = b~comp1
|
||||||
ON a~comp1 = b~comp1
|
WHERE ...
|
||||||
WHERE ...
|
INTO ...
|
||||||
INTO ...
|
|
||||||
```
|
```
|
||||||
> **💡 Note**<br>
|
> **💡 Note**<br>
|
||||||
> There are more join variants available. See the ABAP
|
> There are more join variants available. See the ABAP
|
||||||
@@ -1217,13 +1212,13 @@ for more information.
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
SELECT FROM dbtab1
|
SELECT FROM dbtab1
|
||||||
FIELDS ...
|
FIELDS ...
|
||||||
WHERE ...
|
WHERE ...
|
||||||
UNION
|
UNION
|
||||||
SELECT FROM dbtab2
|
SELECT FROM dbtab2
|
||||||
FIELDS ...
|
FIELDS ...
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO ...
|
INTO ...
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Excursion: Using Common Table Expressions (CTE)
|
#### Excursion: Using Common Table Expressions (CTE)
|
||||||
@@ -1283,29 +1278,27 @@ internal table.
|
|||||||
``` abap
|
``` abap
|
||||||
WITH
|
WITH
|
||||||
+connections AS (
|
+connections AS (
|
||||||
SELECT zdemo_abap_flsch~carrid, carrname, connid, cityfrom, cityto
|
SELECT zdemo_abap_flsch~carrid, carrname, connid, cityfrom, cityto
|
||||||
FROM zdemo_abap_flsch
|
FROM zdemo_abap_flsch
|
||||||
INNER JOIN zdemo_abap_carr
|
INNER JOIN zdemo_abap_carr
|
||||||
ON zdemo_abap_carr~carrid = zdemo_abap_flsch~carrid
|
ON zdemo_abap_carr~carrid = zdemo_abap_flsch~carrid
|
||||||
WHERE zdemo_abap_flsch~carrid BETWEEN 'AA' AND 'JL' ),
|
WHERE zdemo_abap_flsch~carrid BETWEEN 'AA' AND 'JL' ),
|
||||||
+sum_seats AS (
|
+sum_seats AS (
|
||||||
SELECT carrid, connid, SUM( seatsocc ) AS sum_seats
|
SELECT carrid, connid, SUM( seatsocc ) AS sum_seats
|
||||||
FROM zdemo_abap_fli
|
FROM zdemo_abap_fli
|
||||||
WHERE carrid BETWEEN 'AA' AND 'JL'
|
WHERE carrid BETWEEN 'AA' AND 'JL'
|
||||||
GROUP BY carrid, connid ),
|
GROUP BY carrid, connid ),
|
||||||
+result( name, connection, departure, arrival, occupied ) AS (
|
+result( name, connection, departure, arrival, occupied ) AS (
|
||||||
SELECT carrname, c~connid, cityfrom, cityto, sum_seats
|
SELECT carrname, c~connid, cityfrom, cityto, sum_seats
|
||||||
FROM +connections AS c
|
FROM +connections AS c
|
||||||
INNER JOIN +sum_seats AS s
|
INNER JOIN +sum_seats AS s
|
||||||
ON c~carrid = s~carrid AND
|
ON c~carrid = s~carrid AND c~connid = s~connid )
|
||||||
c~connid = s~connid )
|
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM +result
|
FROM +result
|
||||||
ORDER BY name, connection
|
ORDER BY name, connection
|
||||||
INTO TABLE @DATA(result).
|
INTO TABLE @DATA(result).
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||||
|
|
||||||
## Changing Data in Database Tables
|
## Changing Data in Database Tables
|
||||||
@@ -1393,13 +1386,11 @@ ind_tab = VALUE #(
|
|||||||
( comp1 = ... comp2 = ... comp_ind-comp2 = abap_true )
|
( comp1 = ... comp2 = ... comp_ind-comp2 = abap_true )
|
||||||
( comp1 = ... comp2 = ... comp_ind-comp2 = abap_true ) ).
|
( comp1 = ... comp2 = ... comp_ind-comp2 = abap_true ) ).
|
||||||
|
|
||||||
UPDATE dbtab FROM TABLE @ind_tab
|
UPDATE dbtab FROM TABLE @ind_tab INDICATORS SET STRUCTURE comp_ind.
|
||||||
INDICATORS SET STRUCTURE comp_ind.
|
|
||||||
|
|
||||||
"Reverses the logic
|
"Reverses the logic
|
||||||
|
|
||||||
UPDATE dbtab FROM TABLE @ind_tab
|
UPDATE dbtab FROM TABLE @ind_tab INDICATORS NOT SET STRUCTURE comp_ind.
|
||||||
INDICATORS NOT SET STRUCTURE comp_ind.
|
|
||||||
|
|
||||||
"SET addition: Changing values of specific fields in all table rows
|
"SET addition: Changing values of specific fields in all table rows
|
||||||
"There are mutliple options for the value assignment. E. g. you can use
|
"There are mutliple options for the value assignment. E. g. you can use
|
||||||
@@ -1480,9 +1471,9 @@ DELETE dbtab FROM TABLE @( VALUE #( ( comp1 = ... )
|
|||||||
|
|
||||||
"Selecting from a dynamically specified database table.
|
"Selecting from a dynamically specified database table.
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM (dbtab)
|
FROM (dbtab)
|
||||||
WHERE ...
|
WHERE ...
|
||||||
INTO ...
|
INTO ...
|
||||||
```
|
```
|
||||||
- [This topic](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql.htm) serves as the entry point for topics about ABAP SQL in the ABAP Keyword Documentation. For the full details, check the subtopics there, especially topics not covered in this cheat sheet.
|
- [This topic](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql.htm) serves as the entry point for topics about ABAP SQL in the ABAP Keyword Documentation. For the full details, check the subtopics there, especially topics not covered in this cheat sheet.
|
||||||
|
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ possible for the declaration part.
|
|||||||
``` abap
|
``` abap
|
||||||
"Declaration part
|
"Declaration part
|
||||||
CLASS global_class DEFINITION
|
CLASS global_class DEFINITION
|
||||||
PUBLIC "Makes the class a global class in the class library.
|
PUBLIC "Makes the class a global class in the class library.
|
||||||
FINAL "Means that no subclasses can be derived from this class.
|
FINAL "Means that no subclasses can be derived from this class.
|
||||||
CREATE PUBLIC. "This class can be instantiated anywhere it is visible.
|
CREATE PUBLIC. "This class can be instantiated anywhere it is visible.
|
||||||
|
|
||||||
... "Here go the declarations for all components and visibility sections.
|
... "Here go the declarations for all components and visibility sections.
|
||||||
|
|
||||||
@@ -1148,18 +1148,18 @@ The following code snippet shows an implementation of the singleton design patte
|
|||||||
"Using the addition CREATE PRIVATE, objects can only be created by the class itself.
|
"Using the addition CREATE PRIVATE, objects can only be created by the class itself.
|
||||||
CLASS singleton_class DEFINITION CREATE PRIVATE.
|
CLASS singleton_class DEFINITION CREATE PRIVATE.
|
||||||
PUBLIC SECTION.
|
PUBLIC SECTION.
|
||||||
CLASS-METHODS get_instance RETURNING VALUE(inst) TYPE REF TO singleton_class.
|
CLASS-METHODS get_instance RETURNING VALUE(ret) TYPE REF TO singleton_class.
|
||||||
|
|
||||||
PRIVATE SECTION.
|
PRIVATE SECTION.
|
||||||
CLASS-DATA instance TYPE REF TO singleton_class.
|
CLASS-DATA inst TYPE REF TO singleton_class.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|
||||||
CLASS singleton_class IMPLEMENTATION.
|
CLASS singleton_class IMPLEMENTATION.
|
||||||
METHOD get_instance.
|
METHOD get_instance.
|
||||||
IF instance IS NOT BOUND.
|
IF inst IS NOT BOUND.
|
||||||
instance = NEW #( ).
|
inst = NEW #( ).
|
||||||
ENDIF.
|
ENDIF.
|
||||||
inst = instance.
|
ret = inst.
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -107,9 +107,9 @@ Example: Structure
|
|||||||
``` abap
|
``` abap
|
||||||
"Creating a structured type
|
"Creating a structured type
|
||||||
TYPES: BEGIN OF struc_type,
|
TYPES: BEGIN OF struc_type,
|
||||||
a TYPE i,
|
a TYPE i,
|
||||||
b TYPE c LENGTH 3,
|
b TYPE c LENGTH 3,
|
||||||
END OF struc_type.
|
END OF struc_type.
|
||||||
|
|
||||||
DATA struc TYPE struc_type. "Structured data object
|
DATA struc TYPE struc_type. "Structured data object
|
||||||
|
|
||||||
@@ -186,12 +186,12 @@ demonstrates a nested structure.
|
|||||||
``` abap
|
``` abap
|
||||||
"Creating a nested structure
|
"Creating a nested structure
|
||||||
DATA: BEGIN OF nested_struc,
|
DATA: BEGIN OF nested_struc,
|
||||||
a TYPE i,
|
a TYPE i,
|
||||||
BEGIN OF struct,
|
BEGIN OF struct,
|
||||||
b TYPE i,
|
b TYPE i,
|
||||||
c TYPE c LENGTH 3,
|
c TYPE c LENGTH 3,
|
||||||
END OF struct,
|
END OF struct,
|
||||||
END OF nested_struc.
|
END OF nested_struc.
|
||||||
|
|
||||||
"Filling the deep structure
|
"Filling the deep structure
|
||||||
nested_struc = VALUE #( a = 1 struct = VALUE #( b = 2 c = 'abc' ) ).
|
nested_struc = VALUE #( a = 1 struct = VALUE #( b = 2 c = 'abc' ) ).
|
||||||
@@ -366,10 +366,8 @@ two statements are not the same:
|
|||||||
you get a [reference
|
you get a [reference
|
||||||
variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreference_variable_glosry.htm "Glossary Entry")
|
variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreference_variable_glosry.htm "Glossary Entry")
|
||||||
that points to the created object. In doing so, the operator
|
that points to the created object. In doing so, the operator
|
||||||
basically replaces [CREATE
|
basically replaces [`CREATE DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcreate_data.htm)
|
||||||
DATA](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcreate_data.htm)
|
and [`CREATE OBJECT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcreate_object.htm).
|
||||||
and [CREATE
|
|
||||||
OBJECT](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcreate_object.htm).
|
|
||||||
- For the type specification preceding the parentheses, you can use
|
- For the type specification preceding the parentheses, you can use
|
||||||
- non-generic data types which creates a [data reference
|
- non-generic data types which creates a [data reference
|
||||||
variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_reference_variable_glosry.htm "Glossary Entry")
|
variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_reference_variable_glosry.htm "Glossary Entry")
|
||||||
@@ -556,14 +554,14 @@ Examples:
|
|||||||
``` abap
|
``` abap
|
||||||
"Leads to a data loss when converting to a data object accepting only a single character
|
"Leads to a data loss when converting to a data object accepting only a single character
|
||||||
TRY.
|
TRY.
|
||||||
DATA(exact1) = EXACT abap_bool( 'XY' ).
|
DATA(exact1) = EXACT abap_bool( 'XY' ).
|
||||||
CATCH CX_SY_CONVERSION_DATA_LOSS INTO DATA(error1).
|
CATCH CX_SY_CONVERSION_DATA_LOSS INTO DATA(error1).
|
||||||
ENDTRY.
|
ENDTRY.
|
||||||
|
|
||||||
"The calculation cannot be executed exactly; a rounding is necessary
|
"The calculation cannot be executed exactly; a rounding is necessary
|
||||||
TRY.
|
TRY.
|
||||||
DATA(exact2) = EXACT decfloat34( 1 / 3 ).
|
DATA(exact2) = EXACT decfloat34( 1 / 3 ).
|
||||||
CATCH CX_SY_CONVERSION_ROUNDING INTO DATA(error2).
|
CATCH CX_SY_CONVERSION_ROUNDING INTO DATA(error2).
|
||||||
ENDTRY.
|
ENDTRY.
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -591,7 +589,7 @@ Examples:
|
|||||||
"Data references
|
"Data references
|
||||||
"Declaring data object and assign value
|
"Declaring data object and assign value
|
||||||
|
|
||||||
DATA number TYPE i VALUE 5.
|
DATA num TYPE i VALUE 5.
|
||||||
|
|
||||||
"Declaring data reference variable
|
"Declaring data reference variable
|
||||||
|
|
||||||
@@ -599,7 +597,7 @@ DATA dref_a TYPE REF TO i.
|
|||||||
|
|
||||||
"Getting references
|
"Getting references
|
||||||
|
|
||||||
dref_a = REF #( number ).
|
dref_a = REF #( num ).
|
||||||
|
|
||||||
"Inline declaration and explicit type specification
|
"Inline declaration and explicit type specification
|
||||||
DATA(dref_b) = REF string( `hallo` ).
|
DATA(dref_b) = REF string( `hallo` ).
|
||||||
@@ -640,14 +638,12 @@ DATA(oref_b) = REF #( oref_a ).
|
|||||||
examples:
|
examples:
|
||||||
``` abap
|
``` abap
|
||||||
"Getting component information
|
"Getting component information
|
||||||
DATA(components) =
|
DATA(components) = CAST cl_abap_structdescr(
|
||||||
CAST cl_abap_structdescr(
|
cl_abap_typedescr=>describe_by_data( some_object ) )->components.
|
||||||
cl_abap_typedescr=>describe_by_data( some_object ) )->components.
|
|
||||||
|
|
||||||
"Getting method information
|
"Getting method information
|
||||||
DATA(methods) =
|
DATA(methods) = CAST cl_abap_objectdescr(
|
||||||
CAST cl_abap_objectdescr(
|
cl_abap_objectdescr=>describe_by_name( 'LOCAL_CLASS' ) )->methods.
|
||||||
cl_abap_objectdescr=>describe_by_name( 'LOCAL_CLASS' ) )->methods.
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||||
@@ -674,9 +670,9 @@ DATA(methods) =
|
|||||||
Example:
|
Example:
|
||||||
``` abap
|
``` abap
|
||||||
DATA(b) = COND #( WHEN a BETWEEN 1 AND 3 THEN w
|
DATA(b) = COND #( WHEN a BETWEEN 1 AND 3 THEN w
|
||||||
WHEN a > 4 THEN x
|
WHEN a > 4 THEN x
|
||||||
WHEN a IS INITIAL THEN y
|
WHEN a IS INITIAL THEN y
|
||||||
ELSE z ).
|
ELSE z ).
|
||||||
```
|
```
|
||||||
|
|
||||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||||
@@ -693,10 +689,10 @@ checked in the case distinction.
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
DATA(b) = SWITCH #( a
|
DATA(b) = SWITCH #( a
|
||||||
WHEN 1 THEN w
|
WHEN 1 THEN w
|
||||||
WHEN 2 THEN x
|
WHEN 2 THEN x
|
||||||
WHEN 3 THEN y
|
WHEN 3 THEN y
|
||||||
ELSE z ).
|
ELSE z ).
|
||||||
```
|
```
|
||||||
|
|
||||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||||
@@ -750,11 +746,11 @@ DATA(f7) = FILTER #( itab3 WHERE num = 3 ).
|
|||||||
"are used for which at least one line in the filter table meets the condition. EXCEPT and USING KEY are also possible.
|
"are used for which at least one line in the filter table meets the condition. EXCEPT and USING KEY are also possible.
|
||||||
|
|
||||||
DATA filter_tab1 TYPE SORTED TABLE OF i
|
DATA filter_tab1 TYPE SORTED TABLE OF i
|
||||||
WITH NON-UNIQUE KEY table_line.
|
WITH NON-UNIQUE KEY table_line.
|
||||||
|
|
||||||
DATA filter_tab2 TYPE STANDARD TABLE OF i
|
DATA filter_tab2 TYPE STANDARD TABLE OF i
|
||||||
WITH EMPTY KEY
|
WITH EMPTY KEY
|
||||||
WITH UNIQUE SORTED KEY line COMPONENTS table_line.
|
WITH UNIQUE SORTED KEY line COMPONENTS table_line.
|
||||||
|
|
||||||
DATA(f8) = FILTER #( itab1 IN filter_tab1 WHERE num = table_line ).
|
DATA(f8) = FILTER #( itab1 IN filter_tab1 WHERE num = table_line ).
|
||||||
|
|
||||||
@@ -784,9 +780,10 @@ DATA(f11) = FILTER #( itab2 USING KEY sec_key EXCEPT IN filter_tab2 WHERE num =
|
|||||||
The following example calculates the total of the numbers from 1 to 10
|
The following example calculates the total of the numbers from 1 to 10
|
||||||
using the `REDUCE` operator:
|
using the `REDUCE` operator:
|
||||||
``` abap
|
``` abap
|
||||||
|
"sum: 55
|
||||||
DATA(sum) = REDUCE i( INIT s = 0
|
DATA(sum) = REDUCE i( INIT s = 0
|
||||||
FOR i = 1 UNTIL i > 10
|
FOR i = 1 UNTIL i > 10
|
||||||
NEXT s += i ) ). "sum: 55
|
NEXT s += i ) ).
|
||||||
```
|
```
|
||||||
|
|
||||||
> **💡 Note**<br>
|
> **💡 Note**<br>
|
||||||
@@ -830,8 +827,8 @@ has the same effect as the example using `UNTIL` shown above.
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
DATA(sum) = REDUCE i( INIT y = 0
|
DATA(sum) = REDUCE i( INIT y = 0
|
||||||
FOR n = 1 THEN n + 1 WHILE n < 11
|
FOR n = 1 THEN n + 1 WHILE n < 11
|
||||||
NEXT y += n ).
|
NEXT y += n ).
|
||||||
```
|
```
|
||||||
|
|
||||||
`FOR ... UNTIL`: See the example in the `REDUCE`
|
`FOR ... UNTIL`: See the example in the `REDUCE`
|
||||||
@@ -865,17 +862,17 @@ tables:
|
|||||||
TYPES t_type LIKE itab.
|
TYPES t_type LIKE itab.
|
||||||
|
|
||||||
... = VALUE t_type( FOR wa IN itab
|
... = VALUE t_type( FOR wa IN itab
|
||||||
"WHERE ( comp1 > 2 )
|
"WHERE ( comp1 > 2 )
|
||||||
( wa ) ).
|
( wa ) ).
|
||||||
|
|
||||||
"Storing specific components having different names by specifying the assignment
|
"Storing specific components having different names by specifying the assignment
|
||||||
"individually; assumption: the target type is not compatible to the type of itab;
|
"individually; assumption: the target type is not compatible to the type of itab;
|
||||||
"a field mapping is provided; pay attention to potential type conversion
|
"a field mapping is provided; pay attention to potential type conversion
|
||||||
|
|
||||||
... = VALUE t_type( FOR wa IN itab
|
... = VALUE t_type( FOR wa IN itab
|
||||||
"WHERE ( comp1 > 2 )
|
"WHERE ( comp1 > 2 )
|
||||||
( compX = wa-comp1
|
( compX = wa-comp1
|
||||||
compY = wa-comp2 ) ).
|
compY = wa-comp2 ) ).
|
||||||
|
|
||||||
"Storing specific components having the same names;
|
"Storing specific components having the same names;
|
||||||
"assumption: Target type is not compatible to the type of itab;
|
"assumption: Target type is not compatible to the type of itab;
|
||||||
@@ -883,17 +880,17 @@ TYPES t_type LIKE itab.
|
|||||||
"also use CORRESPONDING
|
"also use CORRESPONDING
|
||||||
|
|
||||||
... = VALUE t_type( FOR wa IN itab
|
... = VALUE t_type( FOR wa IN itab
|
||||||
"WHERE ( comp1 > 2 )
|
"WHERE ( comp1 > 2 )
|
||||||
( CORRESPONDING #( wa ) ) ).
|
( CORRESPONDING #( wa ) ) ).
|
||||||
|
|
||||||
"Multiple iteration expressions
|
"Multiple iteration expressions
|
||||||
|
|
||||||
... = VALUE t_type( FOR wa1 IN itab1 WHERE ( comp1 = 4 )
|
... = VALUE t_type( FOR wa1 IN itab1 WHERE ( comp1 = 4 )
|
||||||
FOR wa2 IN itab2 WHERE ( comp2 > 5 )
|
FOR wa2 IN itab2 WHERE ( comp2 > 5 )
|
||||||
FOR wa3 IN itab3 WHERE ( comp3 < 3 )
|
FOR wa3 IN itab3 WHERE ( comp3 < 3 )
|
||||||
( compX = wa1-comp1
|
( compX = wa1-comp1
|
||||||
compY = wa2-comp2
|
compY = wa2-comp2
|
||||||
compZ = wa3-comp3 ) ).
|
compZ = wa3-comp3 ) ).
|
||||||
```
|
```
|
||||||
|
|
||||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||||
@@ -922,10 +919,10 @@ DATA(str_tab) = VALUE string_table( LET it = `be` IN
|
|||||||
"Conditional expressions
|
"Conditional expressions
|
||||||
|
|
||||||
DATA(a) = COND #( LET b = c IN
|
DATA(a) = COND #( LET b = c IN
|
||||||
WHEN b > x THEN ...
|
WHEN b > x THEN ...
|
||||||
WHEN b < y THEN ...
|
WHEN b < y THEN ...
|
||||||
...
|
...
|
||||||
ELSE ... ).
|
ELSE ... ).
|
||||||
```
|
```
|
||||||
|
|
||||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||||
|
|||||||
@@ -29,9 +29,11 @@
|
|||||||
- See the following `SELECT` statement. As also shown further down, the `FROM` clause does not include a statically defined table to be selected from. Instead, there is a pair of parentheses including a data object. Assume the data object holds the name of the database table. At runtime, the data retrieval happens from the database table that was inserted in the input field.
|
- See the following `SELECT` statement. As also shown further down, the `FROM` clause does not include a statically defined table to be selected from. Instead, there is a pair of parentheses including a data object. Assume the data object holds the name of the database table. At runtime, the data retrieval happens from the database table that was inserted in the input field.
|
||||||
|
|
||||||
```abap
|
```abap
|
||||||
|
DATA(dbtab) = `ZDEMO_ABAP_FLI`.
|
||||||
|
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM (dbtab)
|
FROM (dbtab)
|
||||||
INTO TABLE @DATA(some_itab).
|
INTO TABLE @DATA(some_itab).
|
||||||
```
|
```
|
||||||
|
|
||||||
- Further aspects for dynamic programming in ABAP enter the picture if you want to determine information about data types and data objects at runtime ([RTTI](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm)) or even create them ([RTTC](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_creation_glosry.htm)).
|
- Further aspects for dynamic programming in ABAP enter the picture if you want to determine information about data types and data objects at runtime ([RTTI](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm)) or even create them ([RTTC](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_creation_glosry.htm)).
|
||||||
@@ -105,9 +107,9 @@ Once the memory area is assigned, you can work with the content.
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
"Some data object declarations to be used
|
"Some data object declarations to be used
|
||||||
DATA: number TYPE i,
|
DATA: num TYPE i,
|
||||||
struc TYPE zdemo_abap_fli, "Demo database table
|
struc TYPE zdemo_abap_fli, "Demo database table
|
||||||
tab TYPE string_table.
|
tab TYPE string_table.
|
||||||
|
|
||||||
"Declaring field symbols with complete types
|
"Declaring field symbols with complete types
|
||||||
FIELD-SYMBOLS: <fs_i> TYPE i,
|
FIELD-SYMBOLS: <fs_i> TYPE i,
|
||||||
@@ -119,14 +121,14 @@ FIELD-SYMBOLS <fs_gen> TYPE data.
|
|||||||
|
|
||||||
"Assigning data objects to field symbols
|
"Assigning data objects to field symbols
|
||||||
"Note: In this case, the field symbols have an appropriate type.
|
"Note: In this case, the field symbols have an appropriate type.
|
||||||
ASSIGN number TO <fs_i>.
|
ASSIGN num TO <fs_i>.
|
||||||
ASSIGN struc TO <fs_struc>.
|
ASSIGN struc TO <fs_struc>.
|
||||||
ASSIGN tab TO <fs_tab>.
|
ASSIGN tab TO <fs_tab>.
|
||||||
ASSIGN number TO <fs_gen>. "Could be any of the data objects
|
ASSIGN num TO <fs_gen>. "Could be any of the data objects
|
||||||
|
|
||||||
"Inline declaration is possible, too. The type
|
"Inline declaration is possible, too. The type
|
||||||
"is automatically derived.
|
"is automatically derived.
|
||||||
ASSIGN number TO FIELD-SYMBOL(<fs_inl>).
|
ASSIGN num TO FIELD-SYMBOL(<fs_inl>).
|
||||||
|
|
||||||
"You can also assign a particular component of a structure.
|
"You can also assign a particular component of a structure.
|
||||||
"Second component of the structure
|
"Second component of the structure
|
||||||
@@ -168,17 +170,18 @@ ASSIGN chars TO <fs2> CASTING TYPE c_len_3.
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
"For example, in assignments
|
"For example, in assignments
|
||||||
DATA number TYPE i VALUE 1.
|
DATA num TYPE i VALUE 1.
|
||||||
FIELD-SYMBOLS <fs_i> TYPE i.
|
FIELD-SYMBOLS <fs_i> TYPE i.
|
||||||
ASSIGN number TO <fs_i>.
|
ASSIGN num TO <fs_i>.
|
||||||
|
|
||||||
<fs_i> = 2.
|
<fs_i> = 2.
|
||||||
"The data object 'number' has now the value 2.
|
"The data object 'num' has now the value 2.
|
||||||
|
|
||||||
"Loops
|
"Loops
|
||||||
"Here, field symbols are handy since you can avoid an
|
"Here, field symbols are handy since you can avoid an
|
||||||
"actual copying of the table line to boost performance.
|
"actual copying of the table line to boost performance.
|
||||||
SELECT * FROM zdemo_abap_fli
|
SELECT *
|
||||||
|
FROM zdemo_abap_fli
|
||||||
INTO TABLE @DATA(itab).
|
INTO TABLE @DATA(itab).
|
||||||
|
|
||||||
FIELD-SYMBOLS <fs1> LIKE LINE OF itab.
|
FIELD-SYMBOLS <fs1> LIKE LINE OF itab.
|
||||||
@@ -261,8 +264,7 @@ DATA(ref2) = REF #( num ).
|
|||||||
|
|
||||||
DATA(ref3) = REF string( `hallo` ).
|
DATA(ref3) = REF string( `hallo` ).
|
||||||
|
|
||||||
"The older syntax GET REFERENCE having the same effect
|
"The older syntax GET REFERENCE having the same effect should not be used anymore.
|
||||||
"should not be used anymore.
|
|
||||||
"GET REFERENCE OF num INTO ref1.
|
"GET REFERENCE OF num INTO ref1.
|
||||||
"GET REFERENCE OF num INTO DATA(ref4).
|
"GET REFERENCE OF num INTO DATA(ref4).
|
||||||
```
|
```
|
||||||
@@ -272,8 +274,7 @@ data object](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.ht
|
|||||||
at runtime by assigning the reference to the data object of a data reference variable. You can use the [instance
|
at runtime by assigning the reference to the data object of a data reference variable. You can use the [instance
|
||||||
operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninstance_operator_glosry.htm "Glossary Entry")
|
operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninstance_operator_glosry.htm "Glossary Entry")
|
||||||
[`NEW`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_new.htm).
|
[`NEW`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_new.htm).
|
||||||
The older syntax [`CREATE DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcreate_data.htm)
|
It replaces the older syntax [`CREATE DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcreate_data.htm). However, as shown further, `CREATE DATA` is required for specifying a dynamically determined type.
|
||||||
has the same effect as using the newer instance operator.
|
|
||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
"Declaring data reference variables
|
"Declaring data reference variables
|
||||||
@@ -300,17 +301,15 @@ TYPES i_table TYPE STANDARD TABLE OF i WITH EMPTY KEY.
|
|||||||
DATA(ref3) = NEW i_table( ( 1 ) ( 2 ) ( 3 ) ( 4 ) ( 5 ) ).
|
DATA(ref3) = NEW i_table( ( 1 ) ( 2 ) ( 3 ) ( 4 ) ( 5 ) ).
|
||||||
|
|
||||||
"CREATE DATA statements (older syntax)
|
"CREATE DATA statements (older syntax)
|
||||||
"Unlike above, the older syntax is not commented out. CREATE DATA is used for dynamic
|
"DATA ref4 TYPE REF TO string.
|
||||||
"type specification as shown further down.
|
"DATA ref5 TYPE REF TO data.
|
||||||
DATA ref4 TYPE REF TO string.
|
|
||||||
DATA ref5 TYPE REF TO data.
|
|
||||||
|
|
||||||
CREATE DATA ref4.
|
"CREATE DATA ref4.
|
||||||
|
|
||||||
"Note: TYPE ... needed because of generic type data
|
"Note: TYPE ... needed because of generic type data
|
||||||
CREATE DATA ref5 TYPE p LENGTH 6 DECIMALS 2.
|
"CREATE DATA ref5 TYPE p LENGTH 6 DECIMALS 2.
|
||||||
|
|
||||||
CREATE DATA ref5 LIKE ref4.
|
"CREATE DATA ref5 LIKE ref4.
|
||||||
```
|
```
|
||||||
|
|
||||||
**Assigning existing data references** to other data references. As mentioned above regarding the assignment, note that static types of both data
|
**Assigning existing data references** to other data references. As mentioned above regarding the assignment, note that static types of both data
|
||||||
@@ -327,8 +326,8 @@ Excursion: Static vs. dynamic type, upcasts and downcasts
|
|||||||
- Upcast: If the static type of the target variables is **less specific or the same** as the static type of the source variable, an assignment is possible. This includes, for example, assignments with the [assignment operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenassignment_operator_glosry.htm) `=`.
|
- Upcast: If the static type of the target variables is **less specific or the same** as the static type of the source variable, an assignment is possible. This includes, for example, assignments with the [assignment operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenassignment_operator_glosry.htm) `=`.
|
||||||
- Downcast: If the static type of the target variable is **more specific** than the static type of the source variable, a check must be made at runtime before the assignment is done. If you indeed want to trigger such a downcast, you must do it explicitly in your code. You can do this, for example, using the
|
- Downcast: If the static type of the target variable is **more specific** than the static type of the source variable, a check must be made at runtime before the assignment is done. If you indeed want to trigger such a downcast, you must do it explicitly in your code. You can do this, for example, using the
|
||||||
[constructor operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_operator_glosry.htm "Glossary Entry")
|
[constructor operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_operator_glosry.htm "Glossary Entry")
|
||||||
[`CAST`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_cast.htm). In older code, you might see
|
[`CAST`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_cast.htm). In older code, you may see the use of
|
||||||
the operator [`?=`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmove_cast.htm).
|
[`?=`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmove_cast.htm) operator.
|
||||||
- In contrast to a downcast, an upcast does not have to be done explicitly. However, you can - but need not - use the mentioned operators for upcasts, too.
|
- In contrast to a downcast, an upcast does not have to be done explicitly. However, you can - but need not - use the mentioned operators for upcasts, too.
|
||||||
|
|
||||||
|
|
||||||
@@ -364,7 +363,7 @@ DATA ref6 TYPE REF TO data.
|
|||||||
ref6 = NEW i( 654 ).
|
ref6 = NEW i( 654 ).
|
||||||
ref5 = CAST #( ref6 ).
|
ref5 = CAST #( ref6 ).
|
||||||
|
|
||||||
"Casting operator: Older syntax
|
"Casting operator in older syntax
|
||||||
"ref5 ?= ref6.
|
"ref5 ?= ref6.
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -430,11 +429,11 @@ Some example contexts of using data references are as follows:
|
|||||||
|
|
||||||
**Overwriting data reference variables**:
|
**Overwriting data reference variables**:
|
||||||
``` abap
|
``` abap
|
||||||
ref = NEW i( 1 ).
|
dref = NEW i( 1 ).
|
||||||
|
|
||||||
"ref is overwritten here because a new object is created
|
"ref is overwritten here because a new object is created
|
||||||
"with a data reference variable already pointing to a data object
|
"with a data reference variable already pointing to a data object
|
||||||
ref = NEW i( 2 ).
|
dref = NEW i( 2 ).
|
||||||
```
|
```
|
||||||
|
|
||||||
**Retaining data references**:
|
**Retaining data references**:
|
||||||
@@ -444,20 +443,20 @@ ref = NEW i( 2 ).
|
|||||||
"with the same reference variable. Storing them in an internal table
|
"with the same reference variable. Storing them in an internal table
|
||||||
"using the TYPE TABLE OF REF TO prevents the overwriting.
|
"using the TYPE TABLE OF REF TO prevents the overwriting.
|
||||||
|
|
||||||
DATA: ref TYPE REF TO data,
|
DATA: dref TYPE REF TO data,
|
||||||
itab TYPE TABLE OF REF TO data,
|
itab TYPE TABLE OF REF TO data,
|
||||||
number TYPE i VALUE 0.
|
num TYPE i VALUE 0.
|
||||||
|
|
||||||
DO 3 TIMES.
|
DO 3 TIMES.
|
||||||
"Adding up 1 to demonstrate a changed data object.
|
"Adding up 1 to demonstrate a changed data object.
|
||||||
number += 1.
|
num += 1.
|
||||||
|
|
||||||
"Creating data reference and assigning value.
|
"Creating data reference and assigning value.
|
||||||
"In the course of the loop, the variable gets overwritten.
|
"In the course of the loop, the variable gets overwritten.
|
||||||
ref = NEW i( number ).
|
dref = NEW i( num ).
|
||||||
|
|
||||||
"Adding the reference to itab
|
"Adding the reference to itab
|
||||||
itab = VALUE #( BASE itab ( ref ) ).
|
itab = VALUE #( BASE itab ( dref ) ).
|
||||||
ENDDO.
|
ENDDO.
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -469,7 +468,8 @@ ENDDO.
|
|||||||
"instead of actually copying the content to boost performance.
|
"instead of actually copying the content to boost performance.
|
||||||
|
|
||||||
"Filling an internal table.
|
"Filling an internal table.
|
||||||
SELECT * FROM zdemo_abap_fli
|
SELECT *
|
||||||
|
FROM zdemo_abap_fli
|
||||||
INTO TABLE @DATA(fli_tab).
|
INTO TABLE @DATA(fli_tab).
|
||||||
|
|
||||||
LOOP AT fli_tab REFERENCE INTO DATA(ref).
|
LOOP AT fli_tab REFERENCE INTO DATA(ref).
|
||||||
@@ -563,8 +563,8 @@ Note that dynamically specifying syntax elements has downsides, too. Consider so
|
|||||||
"Anonymous data objects are created using a type determined at runtime.
|
"Anonymous data objects are created using a type determined at runtime.
|
||||||
"Note that the NEW operator cannot be used here.
|
"Note that the NEW operator cannot be used here.
|
||||||
|
|
||||||
CREATE DATA ref TYPE (some_type).
|
CREATE DATA dref TYPE (some_type).
|
||||||
CREATE DATA ref TYPE TABLE OF (some_type).
|
CREATE DATA dref TYPE TABLE OF (some_type).
|
||||||
|
|
||||||
"Assigning a data object to a field symbol casting a dynamically specified type
|
"Assigning a data object to a field symbol casting a dynamically specified type
|
||||||
|
|
||||||
|
|||||||
@@ -172,9 +172,9 @@ DATA isbn_number TYPE n LENGTH 13 VALUE '1234567890123'.
|
|||||||
CONSTANTS pi TYPE p LENGTH 8 DECIMALS 14 VALUE '3.14159265358979'.
|
CONSTANTS pi TYPE p LENGTH 8 DECIMALS 14 VALUE '3.14159265358979'.
|
||||||
|
|
||||||
"More data object declarations
|
"More data object declarations
|
||||||
DATA: char1 TYPE c LENGTH 5,
|
DATA: char1 TYPE c LENGTH 5,
|
||||||
html TYPE string,
|
html TYPE string,
|
||||||
str2 LIKE html.
|
str2 LIKE html.
|
||||||
|
|
||||||
"Value assignments
|
"Value assignments
|
||||||
char1 = 'ab123'.
|
char1 = 'ab123'.
|
||||||
@@ -485,7 +485,7 @@ SHIFT s3 RIGHT DELETING TRAILING ` `. "' hallo' (length is kept)
|
|||||||
"you can use the following sequence of statements
|
"you can use the following sequence of statements
|
||||||
DATA(s4) = `hallo `.
|
DATA(s4) = `hallo `.
|
||||||
SHIFT s4 RIGHT DELETING TRAILING ` `. "' hallo'
|
SHIFT s4 RIGHT DELETING TRAILING ` `. "' hallo'
|
||||||
SHIFT s4 LEFT DELETING LEADING ` `. "'hallo'
|
SHIFT s4 LEFT DELETING LEADING ` `. "'hallo'
|
||||||
|
|
||||||
"String functions with parameters
|
"String functions with parameters
|
||||||
s1 = `hallo`.
|
s1 = `hallo`.
|
||||||
@@ -872,12 +872,12 @@ Syntax Overview (see the syntax diagram in the [ABAP Keyword Documentation](http
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
FIND
|
FIND
|
||||||
FIRST OCCURRENCE OF | ALL OCCURRENCES OF
|
FIRST OCCURRENCE OF "(or) ALL OCCURRENCES OF
|
||||||
"1. Only the first occurrence is searched
|
"1. Only the first occurrence is searched
|
||||||
"2. All occurrences are searched
|
"2. All occurrences are searched
|
||||||
"Note: If none of these two additions is specified, only the first occurrence is searched for.
|
"Note: If none of these two additions is specified, only the first occurrence is searched for.
|
||||||
|
|
||||||
SUBSTRING some_substring | PCRE some_regex
|
SUBSTRING some_substring "(or) PCRE some_regex
|
||||||
"1. Searching for exactly one string, specifying SUBSTRING is optional (e.g. for emphasis);
|
"1. Searching for exactly one string, specifying SUBSTRING is optional (e.g. for emphasis);
|
||||||
" some_substring is a character-like operand; note: Trailing blanks are not ignored if it is of type string
|
" some_substring is a character-like operand; note: Trailing blanks are not ignored if it is of type string
|
||||||
"2. Searching for a substring matching a regular expression; only the PCRE addition should be used;
|
"2. Searching for a substring matching a regular expression; only the PCRE addition should be used;
|
||||||
@@ -886,7 +886,8 @@ FIND
|
|||||||
|
|
||||||
IN
|
IN
|
||||||
SECTION
|
SECTION
|
||||||
OFFSET off | LENGTH len
|
OFFSET off
|
||||||
|
LENGTH len
|
||||||
OF
|
OF
|
||||||
"- Restricting the search to a specific section from an offset specified in off with the length len
|
"- Restricting the search to a specific section from an offset specified in off with the length len
|
||||||
"- When using SECTION, at least one of the two options must be specified
|
"- When using SECTION, at least one of the two options must be specified
|
||||||
@@ -901,7 +902,7 @@ dobj
|
|||||||
|
|
||||||
"Further additional options for advanced evaluation options:
|
"Further additional options for advanced evaluation options:
|
||||||
"Specifying whether the search is case-sensitive; not specified means RESEPECTING CASE by default
|
"Specifying whether the search is case-sensitive; not specified means RESEPECTING CASE by default
|
||||||
RESPECTING CASE | IGNORING CASE
|
RESPECTING CASE "(or) IGNORING CASE
|
||||||
|
|
||||||
"Determining the number of sequences found, number stored in cnt that is of type i (e.g. a variable declared inline)
|
"Determining the number of sequences found, number stored in cnt that is of type i (e.g. a variable declared inline)
|
||||||
"When searching for the first occurrence, the value is always 1 (not found -> 0)
|
"When searching for the first occurrence, the value is always 1 (not found -> 0)
|
||||||
@@ -922,7 +923,7 @@ dobj
|
|||||||
"Note on submatches: table of type SUBMATCH_RESULT_TAB; holds offset and length information of substrings of occurrences
|
"Note on submatches: table of type SUBMATCH_RESULT_TAB; holds offset and length information of substrings of occurrences
|
||||||
"that are stored in subgroup registers of regular expressions; in FIND IN TABLE statements, the additional component LINE
|
"that are stored in subgroup registers of regular expressions; in FIND IN TABLE statements, the additional component LINE
|
||||||
"is available
|
"is available
|
||||||
RESULTS tab | RESULTS struc
|
RESULTS tab "(or) RESULTS struc
|
||||||
|
|
||||||
"Storing content of subgroup register of a regular expression in character-like data objects;
|
"Storing content of subgroup register of a regular expression in character-like data objects;
|
||||||
"only to be used if a regular expression pattern is specified.
|
"only to be used if a regular expression pattern is specified.
|
||||||
@@ -1131,7 +1132,7 @@ res = find( val = str sub = `xy` ). "-1
|
|||||||
TRY.
|
TRY.
|
||||||
res = find( val = str sub = `` ).
|
res = find( val = str sub = `` ).
|
||||||
CATCH cx_sy_strg_par_val.
|
CATCH cx_sy_strg_par_val.
|
||||||
"Nope!
|
...
|
||||||
ENDTRY.
|
ENDTRY.
|
||||||
|
|
||||||
"The search is case-sensitive by default
|
"The search is case-sensitive by default
|
||||||
@@ -1154,7 +1155,7 @@ res = find( val = str sub = `e` len = 2 ). "-1
|
|||||||
TRY.
|
TRY.
|
||||||
res = find( val = str sub = `e` off = 5 len = 15 ).
|
res = find( val = str sub = `e` off = 5 len = 15 ).
|
||||||
CATCH cx_sy_range_out_of_bounds.
|
CATCH cx_sy_range_out_of_bounds.
|
||||||
"Nope!
|
...
|
||||||
ENDTRY.
|
ENDTRY.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -774,9 +774,8 @@ EML statement including the execution of an action:
|
|||||||
MODIFY ENTITIES OF root_ent
|
MODIFY ENTITIES OF root_ent
|
||||||
ENTITY root
|
ENTITY root
|
||||||
EXECUTE some_action
|
EXECUTE some_action
|
||||||
FROM action_tab
|
FROM action_tab
|
||||||
RESULT DATA(action_result) "Assumption: The action is defined with a
|
RESULT DATA(action_result) "Assumption: The action is defined with a result parameter.
|
||||||
"result parameter.
|
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -837,8 +836,7 @@ is available for reading all field values.
|
|||||||
READ ENTITIES OF root_ent
|
READ ENTITIES OF root_ent
|
||||||
ENTITY root_ent
|
ENTITY root_ent
|
||||||
ALL FIELDS WITH
|
ALL FIELDS WITH
|
||||||
VALUE #( ( key_field = 1 ) "Derived type TYPE TABLE FOR READ IMPORT
|
VALUE #( ( key_field = 1 ) "Derived type TYPE TABLE FOR READ IMPORT only includes the keys
|
||||||
"only includes the keys
|
|
||||||
( key_field = 2 ) )
|
( key_field = 2 ) )
|
||||||
RESULT DATA(result)
|
RESULT DATA(result)
|
||||||
FAILED DATA(f)
|
FAILED DATA(f)
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ cannot be anything else but a CDS view that exposes a [hierarchy
|
|||||||
association](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhierarchy_association_glosry.htm "Glossary Entry").
|
association](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhierarchy_association_glosry.htm "Glossary Entry").
|
||||||
Here is a very simple example for that:
|
Here is a very simple example for that:
|
||||||
|
|
||||||
``` abap
|
```
|
||||||
@AccessControl.authorizationCheck: #NOT_REQUIRED
|
@AccessControl.authorizationCheck: #NOT_REQUIRED
|
||||||
define view entity DEMO_CDS_SIMPLE_TREE_VIEW
|
define view entity DEMO_CDS_SIMPLE_TREE_VIEW
|
||||||
as select from demo_simple_tree
|
as select from demo_simple_tree
|
||||||
@@ -145,7 +145,7 @@ more complex than shown in the simple example here.
|
|||||||
Now we can use the above CDS view as the hierarchy source of a CDS
|
Now we can use the above CDS view as the hierarchy source of a CDS
|
||||||
hierarchy that can be defined as follows:
|
hierarchy that can be defined as follows:
|
||||||
|
|
||||||
``` abap
|
```
|
||||||
define hierarchy DEMO_CDS_SIMPLE_TREE
|
define hierarchy DEMO_CDS_SIMPLE_TREE
|
||||||
with parameters
|
with parameters
|
||||||
p_id : abap.int4
|
p_id : abap.int4
|
||||||
@@ -218,18 +218,18 @@ DATA root_id type demo_cds_simple_tree_view-id.
|
|||||||
...
|
...
|
||||||
|
|
||||||
SELECT FROM demo_cds_simple_tree( p_id = @root_id )
|
SELECT FROM demo_cds_simple_tree( p_id = @root_id )
|
||||||
FIELDS id,
|
FIELDS id,
|
||||||
parent,
|
parent,
|
||||||
name,
|
name,
|
||||||
hierarchy_rank,
|
hierarchy_rank,
|
||||||
hierarchy_tree_size,
|
hierarchy_tree_size,
|
||||||
hierarchy_parent_rank,
|
hierarchy_parent_rank,
|
||||||
hierarchy_level,
|
hierarchy_level,
|
||||||
hierarchy_is_cycle,
|
hierarchy_is_cycle,
|
||||||
hierarchy_is_orphan,
|
hierarchy_is_orphan,
|
||||||
node_id,
|
node_id,
|
||||||
parent_id
|
parent_id
|
||||||
INTO TABLE @FINAL(cds_result).
|
INTO TABLE @FINAL(cds_result).
|
||||||
```
|
```
|
||||||
|
|
||||||
And although we did not define any hierarchy attributes in the element
|
And although we did not define any hierarchy attributes in the element
|
||||||
@@ -270,7 +270,6 @@ SELECT FROM HIERARCHY( SOURCE demo_cds_simple_tree_view
|
|||||||
START WHERE id = @root_id
|
START WHERE id = @root_id
|
||||||
SIBLINGS ORDER BY id
|
SIBLINGS ORDER BY id
|
||||||
MULTIPLE PARENTS NOT ALLOWED ) "hierarchy
|
MULTIPLE PARENTS NOT ALLOWED ) "hierarchy
|
||||||
]
|
|
||||||
FIELDS id,
|
FIELDS id,
|
||||||
parent,
|
parent,
|
||||||
name,
|
name,
|
||||||
@@ -321,12 +320,11 @@ WITH
|
|||||||
WITH ASSOCIATIONS (
|
WITH ASSOCIATIONS (
|
||||||
JOIN TO MANY +cte_simple_tree_source AS _tree
|
JOIN TO MANY +cte_simple_tree_source AS _tree
|
||||||
ON +cte_simple_tree_source~parent = _tree~id )
|
ON +cte_simple_tree_source~parent = _tree~id )
|
||||||
SELECT FROM HIERARCHY( SOURCE +cte_simple_tree_source
|
SELECT FROM HIERARCHY( SOURCE +cte_simple_tree_source
|
||||||
CHILD TO PARENT ASSOCIATION _tree
|
CHILD TO PARENT ASSOCIATION _tree
|
||||||
START WHERE id = @root_id
|
START WHERE id = @root_id
|
||||||
SIBLINGS ORDER BY id
|
SIBLINGS ORDER BY id
|
||||||
MULTIPLE PARENTS NOT ALLOWED ) "hierarchy
|
MULTIPLE PARENTS NOT ALLOWED ) "hierarchy
|
||||||
]
|
|
||||||
FIELDS id,
|
FIELDS id,
|
||||||
parent,
|
parent,
|
||||||
name,
|
name,
|
||||||
@@ -338,7 +336,7 @@ WITH
|
|||||||
hierarchy_is_orphan,
|
hierarchy_is_orphan,
|
||||||
node_id,
|
node_id,
|
||||||
parent_id
|
parent_id
|
||||||
INTO TABLE @FINAL(asql_cte_result). ]
|
INTO TABLE @FINAL(asql_cte_result).
|
||||||
|
|
||||||
ASSERT asql_cte_result = cds_result.
|
ASSERT asql_cte_result = cds_result.
|
||||||
```
|
```
|
||||||
@@ -390,7 +388,7 @@ WITH
|
|||||||
( SELECT FROM demo_cds_simple_tree( p_id = @root_id )
|
( SELECT FROM demo_cds_simple_tree( p_id = @root_id )
|
||||||
FIELDS * )
|
FIELDS * )
|
||||||
WITH HIERARCHY demo_cds_simple_tree
|
WITH HIERARCHY demo_cds_simple_tree
|
||||||
SELECT FROM +tree "hierarchy ]
|
SELECT FROM +tree "hierarchy ]
|
||||||
FIELDS id,
|
FIELDS id,
|
||||||
parent,
|
parent,
|
||||||
name,
|
name,
|
||||||
@@ -418,7 +416,7 @@ WITH
|
|||||||
parent,
|
parent,
|
||||||
name )
|
name )
|
||||||
WITH HIERARCHY asql_hierarchy
|
WITH HIERARCHY asql_hierarchy
|
||||||
SELECT FROM +tree "hierarchy ]
|
SELECT FROM +tree "hierarchy ]
|
||||||
FIELDS id,
|
FIELDS id,
|
||||||
parent,
|
parent,
|
||||||
name,
|
name,
|
||||||
@@ -454,7 +452,7 @@ WITH
|
|||||||
parent,
|
parent,
|
||||||
name )
|
name )
|
||||||
WITH HIERARCHY cte_hierarchy
|
WITH HIERARCHY cte_hierarchy
|
||||||
SELECT FROM +tree "hierarchy ]
|
SELECT FROM +tree "hierarchy ]
|
||||||
FIELDS id,
|
FIELDS id,
|
||||||
parent,
|
parent,
|
||||||
name,
|
name,
|
||||||
@@ -522,11 +520,11 @@ DATA sub_id TYPE demo_cds_simple_tree_view-id.
|
|||||||
SELECT FROM HIERARCHY_DESCENDANTS(
|
SELECT FROM HIERARCHY_DESCENDANTS(
|
||||||
SOURCE demo_cds_simple_tree( p_id = @root_id )
|
SOURCE demo_cds_simple_tree( p_id = @root_id )
|
||||||
START WHERE id = @sub_id )
|
START WHERE id = @sub_id )
|
||||||
FIELDS id,
|
FIELDS id,
|
||||||
parent_id,
|
parent_id,
|
||||||
name,
|
name,
|
||||||
hierarchy_distance
|
hierarchy_distance
|
||||||
INTO TABLE @FINAL(descendants).
|
INTO TABLE @FINAL(descendants).
|
||||||
```
|
```
|
||||||
|
|
||||||
Our CDS hierarchy `DEMO_CDS_SIMPLE_TREE_VIEW` is used to
|
Our CDS hierarchy `DEMO_CDS_SIMPLE_TREE_VIEW` is used to
|
||||||
@@ -554,11 +552,11 @@ DATA max_id TYPE demo_cds_simple_tree_view-id.
|
|||||||
SELECT FROM HIERARCHY_ANCESTORS(
|
SELECT FROM HIERARCHY_ANCESTORS(
|
||||||
SOURCE demo_cds_simple_tree( p_id = @root_id )
|
SOURCE demo_cds_simple_tree( p_id = @root_id )
|
||||||
START WHERE id = @max_id )
|
START WHERE id = @max_id )
|
||||||
FIELDS id,
|
FIELDS id,
|
||||||
parent_id,
|
parent_id,
|
||||||
name,
|
name,
|
||||||
hierarchy_distance
|
hierarchy_distance
|
||||||
INTO TABLE @FINAL(ancestors).
|
INTO TABLE @FINAL(ancestors).
|
||||||
```
|
```
|
||||||
|
|
||||||
Looking at the result when running
|
Looking at the result when running
|
||||||
@@ -587,11 +585,11 @@ DATA sibl_id TYPE demo_cds_simple_tree_view-id.
|
|||||||
SELECT FROM HIERARCHY_SIBLINGS(
|
SELECT FROM HIERARCHY_SIBLINGS(
|
||||||
SOURCE demo_cds_simple_tree( p_id = @root_id )
|
SOURCE demo_cds_simple_tree( p_id = @root_id )
|
||||||
START WHERE id = @sibl_id )
|
START WHERE id = @sibl_id )
|
||||||
FIELDS id,
|
FIELDS id,
|
||||||
parent_id,
|
parent_id,
|
||||||
name,
|
name,
|
||||||
hierarchy_sibling_distance
|
hierarchy_sibling_distance
|
||||||
INTO TABLE @FINAL(siblings).
|
INTO TABLE @FINAL(siblings).
|
||||||
```
|
```
|
||||||
|
|
||||||
You see that this function adds another hierarchy column
|
You see that this function adds another hierarchy column
|
||||||
@@ -646,11 +644,11 @@ SELECT FROM HIERARCHY_DESCENDANTS_AGGREGATE(
|
|||||||
WHERE hierarchy_rank > 1
|
WHERE hierarchy_rank > 1
|
||||||
WITH SUBTOTAL
|
WITH SUBTOTAL
|
||||||
WITH BALANCE )
|
WITH BALANCE )
|
||||||
FIELDS id,
|
FIELDS id,
|
||||||
amount_sum,
|
amount_sum,
|
||||||
hierarchy_rank,
|
hierarchy_rank,
|
||||||
hierarchy_aggregate_type
|
hierarchy_aggregate_type
|
||||||
INTO TABLE @FINAL(descendants_aggregate).
|
INTO TABLE @FINAL(descendants_aggregate).
|
||||||
```
|
```
|
||||||
|
|
||||||
In our example, we join an internal table `value_tab` of the
|
In our example, we join an internal table `value_tab` of the
|
||||||
|
|||||||
@@ -50,12 +50,12 @@ representative binding.
|
|||||||
To access the members of a group, a member loop can be inserted into the
|
To access the members of a group, a member loop can be inserted into the
|
||||||
group loop:
|
group loop:
|
||||||
``` abap
|
``` abap
|
||||||
LOOP AT spfli_tab INTO wa
|
LOOP AT spfli_tab INTO wa
|
||||||
GROUP BY wa-carrid.
|
GROUP BY wa-carrid.
|
||||||
...
|
...
|
||||||
LOOP AT GROUP wa INTO DATA(member).
|
LOOP AT GROUP wa INTO DATA(member).
|
||||||
... member-... ...
|
... member-... ...
|
||||||
ENDLOOP.
|
ENDLOOP.
|
||||||
...
|
...
|
||||||
ENDLOOP.
|
ENDLOOP.
|
||||||
```
|
```
|
||||||
@@ -71,8 +71,8 @@ defined as follows. In the simplest case, the grouping criteria are
|
|||||||
columns of the internal table:
|
columns of the internal table:
|
||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
LOOP AT spfli_tab INTO wa
|
LOOP AT spfli_tab INTO wa
|
||||||
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ).
|
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ).
|
||||||
... wa-carrid ... wa-airpfrom ...
|
... wa-carrid ... wa-airpfrom ...
|
||||||
ENDLOOP.
|
ENDLOOP.
|
||||||
```
|
```
|
||||||
@@ -92,9 +92,9 @@ of the representative binding in which the output area of the group loop
|
|||||||
is reused:
|
is reused:
|
||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
LOOP AT spfli_tab INTO wa
|
LOOP AT spfli_tab INTO wa
|
||||||
GROUP BY wa-carrid
|
GROUP BY wa-carrid
|
||||||
INTO DATA(key).
|
INTO DATA(key).
|
||||||
... key ...
|
... key ...
|
||||||
ENDLOOP.
|
ENDLOOP.
|
||||||
```
|
```
|
||||||
@@ -118,13 +118,13 @@ binding, with the difference that a group is now addressed by
|
|||||||
`key` instead of `wa`.
|
`key` instead of `wa`.
|
||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
LOOP AT spfli_tab INTO wa
|
LOOP AT spfli_tab INTO wa
|
||||||
GROUP BY wa-carrid
|
GROUP BY wa-carrid
|
||||||
INTO key.
|
INTO key.
|
||||||
...
|
...
|
||||||
LOOP AT GROUP key INTO member.
|
LOOP AT GROUP key INTO member.
|
||||||
... members ...
|
... members ...
|
||||||
ENDLOOP.
|
ENDLOOP.
|
||||||
...
|
...
|
||||||
ENDLOOP.
|
ENDLOOP.
|
||||||
```
|
```
|
||||||
@@ -134,8 +134,8 @@ Finally, the group key binding for structured group keys:
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
LOOP AT spfli_tab INTO wa
|
LOOP AT spfli_tab INTO wa
|
||||||
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom )
|
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom )
|
||||||
INTO DATA(key).
|
INTO DATA(key).
|
||||||
... key-key1 ... key-key2 ...
|
... key-key1 ... key-key2 ...
|
||||||
ENDLOOP.
|
ENDLOOP.
|
||||||
```
|
```
|
||||||
@@ -150,10 +150,10 @@ can be used to save time and memory.
|
|||||||
|
|
||||||
``` abap
|
``` abap
|
||||||
LOOP AT spfli_tab INTO wa
|
LOOP AT spfli_tab INTO wa
|
||||||
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom
|
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom
|
||||||
index = GROUP INDEX size = GROUP SIZE )
|
index = GROUP INDEX size = GROUP SIZE )
|
||||||
WITHOUT MEMBERS
|
WITHOUT MEMBERS
|
||||||
INTO DATA(key).
|
INTO DATA(key).
|
||||||
... key-key1 ... key-key2 ... key-index ... key-size ...
|
... key-key1 ... key-key2 ... key-index ... key-size ...
|
||||||
ENDLOOP.
|
ENDLOOP.
|
||||||
```
|
```
|
||||||
|
|||||||
57
12_AMDP.md
57
12_AMDP.md
@@ -95,7 +95,7 @@ CLASS cl_some_amdp_class DEFINITION
|
|||||||
|
|
||||||
PUBLIC SECTION.
|
PUBLIC SECTION.
|
||||||
"Specifying the interface is mandatory
|
"Specifying the interface is mandatory
|
||||||
INTERFACES if_amdp_marker_hdb.
|
INTERFACES if_amdp_marker_hdb.
|
||||||
...
|
...
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
```
|
```
|
||||||
@@ -122,12 +122,12 @@ methods:
|
|||||||
...
|
...
|
||||||
PUBLIC SECTION.
|
PUBLIC SECTION.
|
||||||
|
|
||||||
METHODS some_amdp_meth
|
METHODS some_amdp_meth
|
||||||
... "Here go the parameters
|
... "Here go the parameters
|
||||||
|
|
||||||
PRIVATE SECTION.
|
PRIVATE SECTION.
|
||||||
|
|
||||||
CLASS-METHODS another_amdp_meth
|
CLASS-METHODS another_amdp_meth
|
||||||
... "Here go the parameters
|
... "Here go the parameters
|
||||||
|
|
||||||
...
|
...
|
||||||
@@ -167,11 +167,11 @@ Example for an AMDP procedure's declaration part:
|
|||||||
PUBLIC SECTION.
|
PUBLIC SECTION.
|
||||||
|
|
||||||
"Table type with a structured row type
|
"Table type with a structured row type
|
||||||
TYPES tab_type TYPE STANDARD TABLE OF dbtab WITH EMPTY KEY.
|
TYPES tab_type TYPE STANDARD TABLE OF dbtab WITH EMPTY KEY.
|
||||||
|
|
||||||
METHODS amdp_meth
|
METHODS amdp_meth
|
||||||
IMPORTING VALUE(num) TYPE i,
|
IMPORTING VALUE(num) TYPE i,
|
||||||
EXPORTING VALUE(tab) TYPE tab_type.
|
EXPORTING VALUE(tab) TYPE tab_type.
|
||||||
|
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
@@ -185,10 +185,10 @@ following <code>METHOD</code> and the method name:
|
|||||||
...
|
...
|
||||||
METHOD amdp_meth
|
METHOD amdp_meth
|
||||||
BY DATABASE PROCEDURE
|
BY DATABASE PROCEDURE
|
||||||
FOR HDB
|
FOR HDB
|
||||||
LANGUAGE SQLSCRIPT
|
LANGUAGE SQLSCRIPT
|
||||||
OPTIONS READ-ONLY
|
OPTIONS READ-ONLY
|
||||||
USING db_object. "see comments further down
|
USING db_object. "see comments further down
|
||||||
|
|
||||||
"Beginning of the SQLScript code (note that it is not ABAP code although it looks similar)
|
"Beginning of the SQLScript code (note that it is not ABAP code although it looks similar)
|
||||||
|
|
||||||
@@ -222,8 +222,6 @@ Note:
|
|||||||
and implementation parts. Check the ABAP Keyword Documentation for
|
and implementation parts. Check the ABAP Keyword Documentation for
|
||||||
more details as touched on further down.
|
more details as touched on further down.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## AMDP Functions
|
## AMDP Functions
|
||||||
|
|
||||||
[Scalar](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_scalar_function_glosry.htm "Glossary Entry")
|
[Scalar](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp_scalar_function_glosry.htm "Glossary Entry")
|
||||||
@@ -264,12 +262,12 @@ Example for an AMDP function's declaration part:
|
|||||||
PUBLIC SECTION.
|
PUBLIC SECTION.
|
||||||
|
|
||||||
"Table type with a structured row type
|
"Table type with a structured row type
|
||||||
TYPES tab_type TYPE STANDARD TABLE OF dbtab WITH EMPTY KEY.
|
TYPES tab_type TYPE STANDARD TABLE OF dbtab WITH EMPTY KEY.
|
||||||
|
|
||||||
METHODS amdp_func
|
METHODS amdp_func
|
||||||
IMPORTING VALUE(num) TYPE i,
|
IMPORTING VALUE(num) TYPE i,
|
||||||
VALUE(some_elem) TYPE c LENGTH 3,
|
VALUE(some_elem) TYPE c LENGTH 3,
|
||||||
RETURNING VALUE(tab) TYPE tab_type.
|
RETURNING VALUE(tab) TYPE tab_type.
|
||||||
|
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
@@ -280,11 +278,11 @@ AMDP procedure as shown above. The difference is the use of `BY DATABASE FUNCTIO
|
|||||||
```abap
|
```abap
|
||||||
...
|
...
|
||||||
METHOD amdp_func
|
METHOD amdp_func
|
||||||
BY DATABASE FUNCTION
|
BY DATABASE FUNCTION
|
||||||
FOR HDB
|
FOR HDB
|
||||||
LANGUAGE SQLSCRIPT
|
LANGUAGE SQLSCRIPT
|
||||||
OPTIONS READ-ONLY
|
OPTIONS READ-ONLY
|
||||||
USING db_object.
|
USING db_object.
|
||||||
|
|
||||||
"Beginning of the SQLScript code (note that it is not ABAP code although it looks similar)
|
"Beginning of the SQLScript code (note that it is not ABAP code although it looks similar)
|
||||||
|
|
||||||
@@ -331,8 +329,8 @@ function:
|
|||||||
...
|
...
|
||||||
PUBLIC SECTION.
|
PUBLIC SECTION.
|
||||||
|
|
||||||
CLASS-METHODS:
|
CLASS-METHODS:
|
||||||
table_func FOR TABLE FUNCTION some_ddl_source.
|
table_func FOR TABLE FUNCTION some_ddl_source.
|
||||||
|
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
@@ -357,7 +355,7 @@ source of a CDS table function:
|
|||||||
|
|
||||||
The CDS DDL source might look like this:
|
The CDS DDL source might look like this:
|
||||||
|
|
||||||
```abap
|
```
|
||||||
//Here go annotations.
|
//Here go annotations.
|
||||||
define table function some_ddl_source
|
define table function some_ddl_source
|
||||||
returns
|
returns
|
||||||
@@ -411,11 +409,11 @@ snippet:
|
|||||||
|
|
||||||
```abap
|
```abap
|
||||||
IF NOT cl_abap_dbfeatures=>use_features(
|
IF NOT cl_abap_dbfeatures=>use_features(
|
||||||
EXPORTING requested_features =
|
EXPORTING requested_features =
|
||||||
VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ).
|
VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ).
|
||||||
|
|
||||||
"Result: Current database system does not support AMDP procedures
|
"Result: Current database system does not support AMDP procedures
|
||||||
RETURN.
|
RETURN.
|
||||||
ENDIF.
|
ENDIF.
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -430,7 +428,6 @@ input parameter for the client ID. See more information
|
|||||||
The client handling is not dealt with in this cheat sheet and not
|
The client handling is not dealt with in this cheat sheet and not
|
||||||
relevant in the executable example.
|
relevant in the executable example.
|
||||||
|
|
||||||
|
|
||||||
## Executable Example
|
## Executable Example
|
||||||
[zcl_demo_abap_amdp](./src/zcl_demo_abap_amdp.clas.abap)
|
[zcl_demo_abap_amdp](./src/zcl_demo_abap_amdp.clas.abap)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user