From fe10b5d3cf2e1c2ffc68b76fb96b8aaf28baebfb Mon Sep 17 00:00:00 2001
From: danrega <16720986+danrega@users.noreply.github.com>
Date: Wed, 3 May 2023 14:24:14 +0200
Subject: [PATCH] Correct ABAP md highlights
---
01_Internal_Tables.md | 86 ++---
02_Structures.md | 188 +++++-----
03_ABAP_SQL.md | 469 ++++++++++++------------
04_ABAP_Object_Orientation.md | 16 +-
05_Constructor_Expressions.md | 107 +++---
06_Dynamic_Programming.md | 78 ++--
07_String_Processing.md | 23 +-
08_EML_ABAP_for_RAP.md | 8 +-
10_ABAP_SQL_Hierarchies.md | 56 ++-
11_ABAP_SQL_Grouping_Internal_Tables.md | 40 +-
12_AMDP.md | 57 ++-
11 files changed, 553 insertions(+), 575 deletions(-)
diff --git a/01_Internal_Tables.md b/01_Internal_Tables.md
index 7753111..8533ec2 100644
--- a/01_Internal_Tables.md
+++ b/01_Internal_Tables.md
@@ -162,12 +162,12 @@ or [`LIKE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm
``` abap
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 itab2 TYPE HASHED TABLE OF data_type ... "Hashed table
-DATA itab3 TYPE table_type ... "Based on an existing internal table type
-DATA itab4 LIKE table ... "Based on an existing internal table
+DATA itab1 TYPE TABLE OF data_type ... "Standard table by default
+DATA itab2 TYPE HASHED TABLE OF data_type ... "Hashed table
+DATA itab3 TYPE table_type ... "Based on an existing internal table type
+DATA itab4 LIKE tab ... "Based on an existing internal table
```
> **💡 Note**
@@ -617,23 +617,23 @@ for example, based on a condition. In the case below, the internal table
is created inline.
``` abap
SELECT FROM dbtab
- FIELDS comp1, comp2 ...
- WHERE ...
- INTO TABLE @DATA(itab_sel).
+ FIELDS comp1, comp2 ...
+ WHERE ...
+ 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.
``` abap
-SELECT FROM dbtab
- FIELDS comp1, comp2 ...
- WHERE ...
- INTO @DATA(struc_sel).
+SELECT FROM dbtab
+ FIELDS comp1, comp2 ...
+ WHERE ...
+ INTO @DATA(struc_sel).
- IF sy-subrc = 0.
- APPEND struc_sel TO itab.
+ IF sy-subrc = 0.
+ APPEND struc_sel TO itab.
...
- ENDIF.
+ ENDIF.
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.
``` abap
SELECT FROM dbtab2
- FIELDS *
- WHERE ...
- APPENDING CORRESPONDING FIELDS OF TABLE @itab.
+ FIELDS *
+ WHERE ...
+ APPENDING CORRESPONDING FIELDS OF TABLE @itab.
SELECT FROM dbtab2
- FIELDS *
- WHERE ...
- INTO CORRESPONDING FIELDS OF TABLE @itab.
+ FIELDS *
+ WHERE ...
+ INTO CORRESPONDING FIELDS OF TABLE @itab.
```
Adding multiple lines from an internal table to another internal table using `SELECT`. Note the alias name that must be defined for the
internal table.
``` abap
SELECT comp1, comp2, ...
- FROM @itab2 AS it_alias
- INTO TABLE @DATA(itab_sel).
+ FROM @itab2 AS it_alias
+ INTO TABLE @DATA(itab_sel).
```
**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 `~`.
``` abap
SELECT it_alias~comp1, it_alias~comp2, dbtab~comp3 ...
- FROM @itab AS it_alias
- INNER JOIN dbtab ON it_alias~comp1 = dbtab~comp1
- INTO TABLE @DATA(it_join_result).
+ FROM @itab AS it_alias
+ INNER JOIN dbtab ON it_alias~comp1 = dbtab~comp1
+ INTO TABLE @DATA(it_join_result).
```
Filling an internal table from a database table using
@@ -682,15 +682,15 @@ a table based on the specified conditions.
``` abap
SELECT comp1, comp2, ...
- FROM dbtab
- WHERE comp1 NOT IN ( a, b, c ... )
- INTO TABLE @DATA(it_subquery_result1).
+ FROM dbtab
+ WHERE comp1 NOT IN ( a, b, c ... )
+ INTO TABLE @DATA(it_subquery_result1).
SELECT comp1, comp2, ...
- FROM dbtab
- WHERE EXISTS ( SELECT 'X' FROM @itab AS itab_alias
- WHERE comp1 = dbtab~comp1 )
- INTO TABLE @DATA(it_subquery_result2).
+ FROM dbtab
+ WHERE EXISTS ( SELECT 'X' FROM @itab AS itab_alias
+ WHERE comp1 = dbtab~comp1 )
+ INTO TABLE @DATA(it_subquery_result2).
```
Filling internal table from a table based on the existence of data in
@@ -701,11 +701,13 @@ another table using the [`FOR ALL ENTRIES`](https://help.sap.com/doc/abapdocu_cp
``` abap
IF itab IS NOT INITIAL.
-SELECT dbtab~comp1, dbtab~comp2, ...
- FROM dbtab
- FOR ALL ENTRIES IN @itab
- WHERE comp1 = @itab-comp1
- INTO TABLE @DATA(it_select_result).
+
+ SELECT dbtab~comp1, dbtab~comp2, ...
+ FROM dbtab
+ FOR ALL ENTRIES IN @itab
+ WHERE comp1 = @itab-comp1
+ INTO TABLE @DATA(it_select_result).
+
ENDIF.
```
@@ -762,11 +764,11 @@ DATA(f7) = FILTER #( itab3 WHERE num = 3 ).
"table meets the condition. EXCEPT and USING KEY are also possible.
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
- WITH EMPTY KEY
- WITH UNIQUE SORTED KEY line COMPONENTS table_line.
+ WITH EMPTY KEY
+ WITH UNIQUE SORTED KEY line COMPONENTS 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(tab2) = VALUE ttype( FOR ls IN it WHERE ( a < 7 )
- ( a = ls-a b = ls-b + 5 ) ).
+ ( a = ls-a b = ls-b + 5 ) ).
```
(back to top)
diff --git a/02_Structures.md b/02_Structures.md
index 4e2580c..625015e 100644
--- a/02_Structures.md
+++ b/02_Structures.md
@@ -103,7 +103,7 @@ DATA: BEGIN OF struc,
"the content is initial.
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.
@@ -127,7 +127,7 @@ Creating structures using existing structured types:
TYPES: BEGIN OF struc_type,
comp1 TYPE i,
comp2 TYPE c LENGTH 5,
- END OF struc_type.
+ END OF struc_type.
"Creating a structure using a local structured 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.
``` abap
- DATA: BEGIN OF structure,
+ DATA: BEGIN OF struc,
comp1 TYPE i,
comp2 TYPE c LENGTH 15,
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"),
that is, it refers to another structure. The following example has multiple substructures.
``` abap
DATA: BEGIN OF address_n,
- BEGIN OF name,
- title TYPE string VALUE `Mr.`,
- prename TYPE string VALUE `Duncan`,
- surname TYPE string VALUE `Pea`,
- END OF name,
- BEGIN OF street,
- name TYPE string VALUE `Vegetable Lane`,
- number TYPE string VALUE `11`,
- END OF street,
- BEGIN OF city,
- zipcode TYPE string VALUE `349875`,
- name TYPE string VALUE `Botanica`,
- END OF city,
- END OF address_n.
+ BEGIN OF name,
+ title TYPE string VALUE `Mr.`,
+ prename TYPE string VALUE `Duncan`,
+ surname TYPE string VALUE `Pea`,
+ END OF name,
+ BEGIN OF street,
+ name TYPE string VALUE `Vegetable Lane`,
+ num TYPE string VALUE `11`,
+ END OF street,
+ BEGIN OF city,
+ zipcode TYPE string VALUE `349875`,
+ name TYPE string VALUE `Botanica`,
+ END OF city,
+ END OF address_n.
```
- **Deep structures**: Contains at least one internal table, reference type, or string as a component.
``` abap
DATA: BEGIN OF address_d,
- name TYPE string VALUE `Mr. Duncan Pea`,
- street TYPE string VALUE `Vegetable Lane 11`,
- city TYPE string VALUE `349875 Botanica`,
- details TYPE TABLE OF some_table WITH EMPTY KEY,
- END OF address_d.
+ name TYPE string VALUE `Mr. Duncan Pea`,
+ street TYPE string VALUE `Vegetable Lane 11`,
+ city TYPE string VALUE `349875 Botanica`,
+ details TYPE TABLE OF some_table WITH EMPTY KEY,
+ 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.
``` abap
DATA: BEGIN OF address,
- name TYPE string VALUE `Mr. Duncan Pea`,
- street TYPE string VALUE `Vegetable Lane 11`,
- city TYPE string VALUE `349875 Botanica`,
- END OF address.
+ name TYPE string VALUE `Mr. Duncan Pea`,
+ street TYPE string VALUE `Vegetable Lane 11`,
+ city TYPE string VALUE `349875 Botanica`,
+ END OF address.
```
> **💡 Note**
@@ -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.
``` abap
"Addressing components via the structure component selector
-... structure-comp1 ...
-... structure-comp2 ...
-... structure-comp3 ...
+... struc-comp1 ...
+... struc-comp2 ...
+... struc-comp3 ...
"Examples for addressing the whole structure and individual components
-IF structure IS INITIAL.
+IF struc IS INITIAL.
...
ENDIF.
-IF structure-comp1 = 1.
+IF struc-comp1 = 1.
...
ENDIF.
-DATA(complete_struc) = structure.
-DATA(comp_value) = structure-comp2.
+DATA(complete_struc) = struc.
+DATA(comp_value) = struc-comp2.
"Type and data declarations
TYPES: type_1 TYPE structured_type-comp1,
- type_2 LIKE structure-comp1.
+ type_2 LIKE struc-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
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:
``` abap
-... structure-substructure-comp1 ...
+... struc-substructure-comp1 ...
... address_n-name-title ...
```
@@ -351,8 +351,8 @@ address-city = `349875 Botanica`.
``` abap
"# used: type of the operand can be implicitly derived
address = VALUE #( name = `Mr. Duncan Pea`
- street = `Vegetable Lane 11`.
- city = `349875 Botanica` ).
+ street = `Vegetable Lane 11`.
+ city = `349875 Botanica` ).
"Declaring a structure inline
"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
"relationships.
-diff_struc = CORRESPONDING #( BASE ( diff_struc )
- struc MAPPING comp1 = compa ).
+diff_struc = CORRESPONDING #( BASE ( diff_struc ) struc MAPPING comp1 = compa ).
"EXCEPT addition: Excluding components from the assignment.
-diff_struc = CORRESPONDING #( BASE ( diff_struc )
- struc EXCEPT comp1 ).
+diff_struc = CORRESPONDING #( BASE ( diff_struc ) struc EXCEPT comp1 ).
```
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
"assignment happens for identically named components only.
-MOVE-CORRESPONDING deep_struc TO diff_deep_struc
- EXPANDING NESTED TABLES.
+MOVE-CORRESPONDING deep_struc TO diff_deep_struc EXPANDING NESTED TABLES.
"Existing internal table content is kept; table content of the source
"structure are added but the value assignment happens like the first
"MOVE-CORRESPONDING statement without further syntax additions.
-MOVE-CORRESPONDING deep_struc TO diff_deep_struc
- KEEPING TARGET LINES.
+MOVE-CORRESPONDING deep_struc TO diff_deep_struc KEEPING TARGET LINES.
"Existing internal table content is kept; table content of the source
"structure are added; the value assignment happens like the statement
"MOVE-CORRESPONDING ... EXPANDING NESTED TABLES.
-MOVE-CORRESPONDING deep_struc TO diff_deep_struc
- EXPANDING NESTED TABLES KEEPING TARGET LINES.
+MOVE-CORRESPONDING deep_struc TO diff_deep_struc EXPANDING NESTED TABLES KEEPING TARGET LINES.
"Target structure is initialized; the value assignment for an internal
"table happens irrespective of identically named components.
@@ -506,14 +501,13 @@ diff_deep_struc = CORRESPONDING #( DEEP APPENDING BASE ( diff_struc ) deep_struc
## Clearing Structures
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.
-```
-CLEAR structure-component.
+``` abap
+CLEAR struc-component.
-CLEAR structure.
+CLEAR struc.
-"Note: Watch out when using the VALUE operator. An assignment as follows also
-"clears the structure.
-structure = VALUE #( ).
+"Note: An assignment using the VALUE operator without entries in the parentheses clears the structure.
+struc = VALUE #( ).
```
## 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.
SELECT SINGLE FROM zdemo_abap_fli
- FIELDS *
- WHERE carrid = 'LH'
- INTO @ls_fli1.
+ FIELDS *
+ WHERE carrid = 'LH'
+ INTO @ls_fli1.
"Target structure declared inline
SELECT SINGLE FROM zdemo_abap_fli
- FIELDS *
- WHERE carrid = 'LH'
- INTO @DATA(ls_fli2).
+ FIELDS *
+ WHERE carrid = 'LH'
+ INTO @DATA(ls_fli2).
```
**Reading a row from a database table into a structure that has an incompatible type**.
Components in the structure with identical names are filled.
``` abap
SELECT SINGLE FROM zdemo_abap_fli
- FIELDS *
- WHERE carrid = 'AA'
- INTO CORRESPONDING FIELDS OF @ls_fli_diff.
+ FIELDS *
+ WHERE carrid = 'AA'
+ INTO CORRESPONDING FIELDS OF @ls_fli_diff.
```
**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.
``` abap
SELECT SINGLE FROM @itab AS itab_alias
- FIELDS *
- WHERE ...
- INTO @DATA(ls_struc).
- "INTO CORRESPONDING FIELDS OF @some_existing_struc.
+ FIELDS *
+ WHERE ...
+ INTO @DATA(ls_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
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.
``` abap
SELECT FROM zdemo_abap_fli
- FIELDS *
- WHERE carrid = 'AZ'
- INTO @DATA(ls_sel_loop).
+ FIELDS *
+ WHERE carrid = 'AZ'
+ INTO @DATA(ls_sel_loop).
IF sy-subrc = 0.
- ...
- ENDIF.
+ ...
+ ENDIF.
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.
``` abap
LOOP AT itab ASSIGNING FIELD-SYMBOL().
- -comp1 = ...
- ...
+ -comp1 = ...
+ ...
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.
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
-INSERT INTO dbtab VALUES @structure.
+INSERT INTO dbtab VALUES @struc.
-INSERT dbtab FROM @structure.
+INSERT dbtab FROM @struc.
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.
``` abap
-UPDATE dbtab FROM @structure.
+UPDATE dbtab FROM @struc.
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
[`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
-MODIFY dbtab FROM @structure.
+MODIFY dbtab FROM @struc.
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
snippets, see the [Working with Internal Tables](01_Internal_Tables.md#) cheat sheet.
``` 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
@@ -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.
``` abap
TYPES: BEGIN OF name_type,
- title TYPE string,
- prename TYPE string,
- surname TYPE string,
- END OF name_type,
- BEGIN OF street_type,
- name TYPE string,
- number TYPE string,
- END OF street_type,
- BEGIN OF city_type,
- zipcode TYPE string,
- name TYPE string,
- END OF city_type.
+ title TYPE string,
+ prename TYPE string,
+ surname TYPE string,
+ END OF name_type,
+ BEGIN OF street_type,
+ name TYPE string,
+ num TYPE string,
+ END OF street_type,
+ BEGIN OF city_type,
+ zipcode TYPE string,
+ name TYPE string,
+ END OF city_type.
DATA city_struc TYPE city_type.
TYPES BEGIN OF address_type.
- INCLUDE TYPE name_type AS name.
- INCLUDE TYPE street_type AS street RENAMING WITH SUFFIX _street.
- INCLUDE STRUCTURE city_struc AS city RENAMING WITH SUFFIX _city.
+ INCLUDE TYPE name_type AS name.
+ INCLUDE TYPE street_type AS street RENAMING WITH SUFFIX _street.
+ INCLUDE STRUCTURE city_struc AS city RENAMING WITH SUFFIX _city.
TYPES END OF address_type.
```
diff --git a/03_ABAP_SQL.md b/03_ABAP_SQL.md
index 256d447..282347f 100644
--- a/03_ABAP_SQL.md
+++ b/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:
``` abap
SELECT FROM source "What database table or view to read from
- FIELDS field_list "What columns 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 @)
+ FIELDS field_list "What columns 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 @)
```
> **💡 Note**
>- 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
following two `SELECT` statements are basically the same but differently arranged:
> ``` abap
-> SELECT FROM dbtab
-> FIELDS comp1, comp2, comp3
+> SELECT FROM dbtab
+> FIELDS comp1, comp2, comp3
> ...
>
> SELECT comp1, comp2, comp3
-> FROM dbtab
+> FROM dbtab
> ...
> ```
>- 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.
SELECT SINGLE FROM dbtab
- FIELDS *
- WHERE ...
- INTO @struc. "Existing structure of dbtab's row type
+ FIELDS *
+ WHERE ...
+ INTO @struc. "Existing structure of dbtab's row type
"Reading a selected set of fields of a single row
SELECT SINGLE FROM dbtab
- FIELDS comp1, comp2, comp3
- WHERE ...
- INTO @DATA(struc2). "Structure declared inline
+ FIELDS comp1, comp2, comp3
+ WHERE ...
+ INTO @DATA(struc2). "Structure declared inline
"Alternative syntax without the FIELDS addition
"Here, the CORRESPONDING FIELDS OF addition is used. Only the content of
@@ -202,9 +202,9 @@ SELECT SINGLE FROM dbtab
"is assigned.
SELECT SINGLE comp1, comp2, comp3 "Selected set of fields
- FROM dbtab
- WHERE ...
- INTO CORRESPONDING FIELDS OF @struc. "Existing structure
+ FROM dbtab
+ WHERE ...
+ INTO CORRESPONDING FIELDS OF @struc. "Existing structure
```
> **💡 Note**
>- 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**.
``` abap
SELECT FROM dbtab
- FIELDS * "All fields
- WHERE ...
- INTO TABLE @itab. "itab has an appropriate row type
+ FIELDS * "All fields
+ WHERE ...
+ INTO TABLE @itab. "itab has an appropriate row type
"Alternative syntax without the FIELDS addition
SELECT comp1, comp2, comp3 "Selected set of fields
- FROM dbtab
- WHERE ...
- INTO TABLE @DATA(lv_itab). "Internal table declared inline
+ FROM dbtab
+ WHERE ...
+ INTO TABLE @DATA(lv_itab). "Internal table declared inline
"Selected set of fields, existing variable
"See the note on CORRESPONDING FIELDS OF above
SELECT FROM dbtab
- FIELDS comp1, comp2, comp3 "Selected set of fields
- WHERE ...
- INTO CORRESPONDING FIELDS OF TABLE @itab.
+ FIELDS comp1, comp2, comp3 "Selected set of fields
+ WHERE ...
+ INTO CORRESPONDING FIELDS OF TABLE @itab.
```
**`SELECT` loop: Sequentially reading multiple rows**.
@@ -244,12 +244,15 @@ SELECT FROM dbtab
``` abap
SELECT FROM dbtab
- FIELDS *
- WHERE ...
- INTO @struc.
- IF sy-subrc = 0.
+ FIELDS *
+ WHERE ...
+ INTO @struc.
+
+ IF sy-subrc = 0.
... "For example, making changes on data and adding the row to an internal table.
- ENDIF.
+
+ ENDIF.
+
ENDSELECT.
```
(back to top)
@@ -263,9 +266,9 @@ ENDSELECT.
"Instead of @abap_true, you could also use 'X'.
SELECT SINGLE @abap_true
- FROM dbtab
- WHERE ...
- INTO @DATA(exists).
+ FROM dbtab
+ WHERE ...
+ INTO @DATA(exists).
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).
``` abap
SELECT DISTINCT comp1
- FROM dbtab
- WHERE ...
- INTO TABLE @itab.
+ FROM dbtab
+ WHERE ...
+ INTO TABLE @itab.
```
**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.
SELECT FROM dbtab
- FIELDS comp1 AS comp_a, comp2 AS comp_b, comp3 AS comp_c
- WHERE ...
- INTO CORRESPONDING FIELDS OF TABLE @itab.
+ FIELDS comp1 AS comp_a, comp2 AS comp_b, comp3 AS comp_c
+ WHERE ...
+ INTO CORRESPONDING FIELDS OF TABLE @itab.
"Alias name also possible for the data source
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
SELECT *
- FROM dbtab USING CLIENT '000'
- WHERE ...
- INTO TABLE @itab.
+ FROM dbtab USING CLIENT '000'
+ WHERE ...
+ INTO TABLE @itab.
"Selects data of any number of clients
SELECT *
- FROM dbtab USING ALL CLIENTS
- WHERE ...
- INTO TABLE @itab.
+ FROM dbtab USING ALL CLIENTS
+ WHERE ...
+ 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.
@@ -362,9 +365,9 @@ Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOU
``` abap
SELECT *
- FROM @itab1 AS tab
- WHERE ...
- INTO TABLE @DATA(itab2).
+ FROM @itab1 AS tab
+ WHERE ...
+ 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
"If the INTO clause is the last clause, the UP TO clause must be positioned after it.
SELECT * FROM dbtab
- WHERE ...
- INTO TABLE @DATA(itab_upto)
- UP TO 5 ROWS.
+ WHERE ...
+ INTO TABLE @DATA(itab_upto)
+ 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.
@@ -407,10 +410,10 @@ Note:
``` abap
SELECT FROM dbtab
- FIELDS comp1, comp2, comp3
- WHERE ...
- INTO (@res1,@res2,@res3).
- "INTO (@DATA(res1),@DATA(res2),@DATA(res3)). "Using inline declarations
+ FIELDS comp1, comp2, comp3
+ WHERE ...
+ INTO (@res1,@res2,@res3).
+ "INTO (@DATA(res1),@DATA(res2),@DATA(res3)). "Using inline declarations
```
**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
SELECT * FROM dbtab
- WHERE ...
- APPENDING TABLE @itab.
+ WHERE ...
+ APPENDING TABLE @itab.
SELECT * FROM dbtab
- WHERE ...
- APPENDING CORRESPONDING FIELDS OF TABLE @diff_itab.
+ WHERE ...
+ 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.
``` abap
SELECT FROM dbtab
- FIELDS comp1, comp2, comp3
- WHERE ...
- INTO TABLE @DATA(itab_pack) PACKAGE SIZE n.
+ FIELDS comp1, comp2, comp3
+ WHERE ...
+ INTO TABLE @DATA(itab_pack) PACKAGE SIZE n.
...
ENDSELECT.
```
@@ -441,8 +444,8 @@ ENDSELECT.
``` abap
"Here, the target object is an anonymous data object declared inline.
SELECT FROM dbtab
- FIELDS comp1, comp2, comp3
- WHERE ...
+ FIELDS comp1, comp2, comp3
+ WHERE ...
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.
``` abap
SELECT FROM dbtab
- FIELDS comp1, MIN( comp2 ) AS min, MAX( comp2 ) AS max
- WHERE ...
- GROUP BY comp1
- INTO ...
+ FIELDS comp1, MIN( comp2 ) AS min, MAX( comp2 ) AS max
+ WHERE ...
+ GROUP BY comp1
+ INTO ...
```
[`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`.
``` abap
SELECT FROM dbtab
- FIELDS comp1, MIN( comp2 ) AS min, MAX( comp3 ) AS max
- WHERE ...
- GROUP BY comp1
- HAVING comp1 LIKE '%XYZ%' AND SUM( comp4 ) > 100
- INTO ...
+ FIELDS comp1, MIN( comp2 ) AS min, MAX( comp3 ) AS max
+ WHERE ...
+ GROUP BY comp1
+ HAVING comp1 LIKE '%XYZ%' AND SUM( comp4 ) > 100
+ INTO ...
```
[`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.
``` abap
SELECT FROM dbtab
- FIELDS comp1, comp2, comp3
- WHERE ...
- ORDER BY PRIMARY KEY
- "comp2 ASCENDING
- "comp2 DESCENDING
- INTO ...
+ FIELDS comp1, comp2, comp3
+ WHERE ...
+ ORDER BY PRIMARY KEY
+ "comp2 ASCENDING
+ "comp2 DESCENDING
+ INTO ...
```
> **💡 Note**
@@ -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.
``` abap
SELECT FROM dbtab
- FIELDS comp1, comp2, comp3
- WHERE comp1 = 'abc'
+ FIELDS comp1, comp2, comp3
+ WHERE comp1 = 'abc'
AND comp2 < 123
- INTO ...
+ INTO ...
```
(back to top)
@@ -574,35 +577,35 @@ Example demonstrating possible operands:
DATA upto TYPE i VALUE 3.
SELECT FROM zdemo_abap_flsch
- FIELDS
+ FIELDS
"Specifies a column of a data source directly using its name
- cityfrom,
+ cityfrom,
"Column selector ~ can be used to prefix every specified column.
"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
"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
- AND countryfr = char`DE` "Typed literal
+ WHERE carrid = 'LH' "Untyped literal
+ AND countryfr = char`DE` "Typed literal
"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
- UP TO 3 ROWS. "Untyped numeric literal
- "UP TO int4`3` ROWS. "Typed numeric literal
- "UP TO @upto ROWS. "Host variable
- "UP TO @( 10 - 7 ) ROWS. "Host expression
+ UP TO 3 ROWS. "Untyped numeric literal
+ "UP TO int4`3` ROWS. "Typed numeric literal
+ "UP TO @upto ROWS. "Host variable
+ "UP TO @( 10 - 7 ) ROWS. "Host expression
```
**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)
``` abap
SELECT SINGLE
- carrname,
+ carrname,
- "Division, result rounded to an integer
- "Result: 2
- div( 4, 2 ) AS div,
+ "Division, result rounded to an integer
+ "Result: 2
+ div( 4, 2 ) AS div,
- "Division, 3rd argument: result is rounded to the specified
- "number of decimals
- "Result: 0.33
- division( 1, 3, 2 ) AS division,
+ "Division, 3rd argument: result is rounded to the specified
+ "number of decimals
+ "Result: 0.33
+ division( 1, 3, 2 ) AS division,
- "Result is rounded to first greater integer
- "Result: 2
- ceil( decfloat34`1.333` ) AS ceil,
+ "Result is rounded to first greater integer
+ "Result: 2
+ ceil( decfloat34`1.333` ) AS ceil,
- "Result is the remainder of division
- "Result: 1
- mod( 3, 2 ) AS mod,
+ "Result is the remainder of division
+ "Result: 1
+ mod( 3, 2 ) AS mod,
- "Result: Largest integer value not greater than the specified value
- "Result: 1
- floor( decfloat34`1.333` ) AS floor,
+ "Result: Largest integer value not greater than the specified value
+ "Result: 1
+ floor( decfloat34`1.333` ) AS floor,
- "Returns the absolute number
- "Result: 2
- abs( int4`-2` ) AS abs,
+ "Returns the absolute number
+ "Result: 2
+ abs( int4`-2` ) AS abs,
- "Result is rounded to the specified position after the decimal separator
- "Result: 1.34
- round( decfloat34`1.337`, 2 ) AS round
+ "Result is rounded to the specified position after the decimal separator
+ "Result: 1.34
+ round( decfloat34`1.337`, 2 ) AS round
- FROM zdemo_abap_carr
- WHERE carrid = 'AA'
- INTO @DATA(numeric_functions).
+ FROM zdemo_abap_carr
+ WHERE carrid = 'AA'
+ 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)
@@ -726,7 +729,7 @@ SELECT SINGLE
locate_regexpr( pcre = '\..', "Period followed by any character
value = url,
occurrence = 2 ) "2nd occurrence in the string
- AS locate_regexpr,
+ AS locate_regexpr,
"Searches a PCRE pattern, returns offset of match + 1;
"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
SELECT SINGLE
- carrid,
+ carrid,
"Conversion functions
"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
"length string of type string
- to_clob( carrid ) AS clob,
+ to_clob( carrid ) AS clob,
"Byte string -> character string
- bintohex( raw`3599421128650F4EE00008000978B976` ) AS bintohex,
+ bintohex( raw`3599421128650F4EE00008000978B976` ) AS bintohex,
"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
- to_blob( raw`3599421128650F4EE00008000978B976` ) AS blob,
+ to_blob( raw`3599421128650F4EE00008000978B976` ) AS blob,
"Unit and currency conversion functions
"More parameters are available.
"Converts miles to kilometers
- unit_conversion( quantity = d34n`1`,
+ unit_conversion( quantity = d34n`1`,
source_unit = unit`MI`,
target_unit = unit`KM` ) AS miles_to_km,
"Converts Euro to US dollars using today's rate
- currency_conversion(
+ currency_conversion(
amount = d34n`1`,
source_currency = char`EUR`,
target_currency = char`USD`,
@@ -921,7 +924,7 @@ SELECT SINGLE
"A cast expression converts the value of the operands to the
"specified dictionary type. The result is a representation of the
"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;
"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
"comparison is true. If no matches are found, the result specified
"after ELSE is selected.
- CASE currcode
- WHEN 'EUR' THEN 'A'
- WHEN 'USD' THEN 'B'
- ELSE 'C'
- END AS case_simple,
+ CASE currcode
+ WHEN 'EUR' THEN 'A'
+ WHEN 'USD' THEN 'B'
+ ELSE 'C'
+ END AS case_simple,
"Complex case distinction
"The expression evaluates logical expressions. Result: The first
"operand after THEN for which the logical expression is true. If no
"logical expressions are true, the result specified after ELSE is
"selected.
- CASE WHEN length( carrname ) <= 5 THEN 'small'
- WHEN length( carrname ) BETWEEN 6 AND 10 THEN 'mid'
- WHEN length( carrname ) BETWEEN 11 AND 15 THEN 'large'
- ELSE 'huge'
- END AS case_complex
+ CASE WHEN length( carrname ) <= 5 THEN 'small'
+ WHEN length( carrname ) BETWEEN 6 AND 10 THEN 'mid'
+ WHEN length( carrname ) BETWEEN 11 AND 15 THEN 'large'
+ ELSE 'huge'
+ END AS case_complex
FROM zdemo_abap_carr
WHERE carrid = 'AA'
@@ -1004,40 +1007,37 @@ Examples:
"Example 1: A simple window is constructed in the OVER clause;
"window functions - here aggregate functions - are applied
SELECT carrid, currency,
- SUM( paymentsum ) OVER( PARTITION BY carrid ) AS sum,
- AVG( price AS DEC( 14,2 ) ) OVER( PARTITION BY carrid ) AS avg,
- MAX( price ) OVER( PARTITION BY carrid ) AS max
- FROM zdemo_abap_fli
- ORDER BY carrid
- INTO TABLE @DATA(win).
+ SUM( paymentsum ) OVER( PARTITION BY carrid ) AS sum,
+ AVG( price AS DEC( 14,2 ) ) OVER( PARTITION BY carrid ) AS avg,
+ MAX( price ) OVER( PARTITION BY carrid ) AS max
+ FROM zdemo_abap_fli
+ ORDER BY carrid
+ INTO TABLE @DATA(win).
"Example 2:
SELECT carrid, currency, fldate,
"Sorts the rows by some columns and counts the number of rows from
"the first row of the window to the current row.
- COUNT( * ) OVER( ORDER BY currency, fldate
- ROWS BETWEEN
- "UNBOUNDED PRECEDING: frame starts at the
- "first row of the window
- UNBOUNDED PRECEDING
- "CURRENT ROW: determines starting or ending
- "at the current row; here, it ends
- AND CURRENT ROW ) AS count1,
+ COUNT( * ) OVER( ORDER BY currency, fldate
+ ROWS BETWEEN
+ "UNBOUNDED PRECEDING: frame starts at the first row of the window
+ UNBOUNDED PRECEDING
+ "CURRENT ROW: determines starting or ending at the current row; here, it ends
+ AND CURRENT ROW ) AS count1,
"If no window frame is used, the default window frame is
"BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW,
"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
"the current row to the last row of the window.
"The result is reverse numbering.
- COUNT( * ) OVER( ORDER BY currency, fldate
- ROWS BETWEEN CURRENT ROW
- "UNBOUND FOLLOWING:
- "Determines the ending frame boundary,
- "this addition specifies the last row of the window
- AND UNBOUNDED FOLLOWING ) AS count_reverse,
+ COUNT( * ) OVER( ORDER BY currency, fldate
+ ROWS BETWEEN CURRENT ROW
+ UNBOUND FOLLOWING:
+ "Determines the ending frame boundary, this addition specifies the last row of the window
+ AND UNBOUNDED FOLLOWING ) AS count_reverse,
"Sorts the rows by some columns and calculates the rolling averages
"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,
"you can calculate the 3-day-average temperature for every day from
"a list of temperature data.
- AVG( price AS DEC( 14,2 ) ) OVER( ORDER BY currency, fldate
- ROWS BETWEEN
- "n PRECEDING: for both start and end of frame;
- "frame to start/end n rows above the current row
- 1 PRECEDING
- "n FOLLOWING: for both start and end of frame;
- "frame to start/end n rows beneath the current row
- AND 1 FOLLOWING ) AS avg
+ AVG( price AS DEC( 14,2 ) ) OVER( ORDER BY currency, fldate
+ ROWS BETWEEN
+ "n PRECEDING: for both start and end of frame; frame to start/end n rows above the current row
+ 1 PRECEDING
+ "n FOLLOWING: for both start and end of frame; frame to start/end n rows beneath the current row
+ AND 1 FOLLOWING ) AS avg
- FROM zdemo_abap_fli
- INTO TABLE @DATA(result).
+ FROM zdemo_abap_fli
+ INTO TABLE @DATA(result).
```
### 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.
``` abap
-SELECT FROM dbtab
- FIELDS comp1, comp2, comp3
- WHERE comp1 = 'abc' "Equals some value
+SELECT *
+ FROM dbtab
+ WHERE comp1 = 'abc' "Equals some value
"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
- "comp2 <> 100 AND comp4 = 'xyz'
+ comp3 <> 100 AND comp4 = 'xyz'
"(Not) between a value range
- "comp1 BETWEEN 1 AND 10
- "comp1 NOT BETWEEN 1 AND 10
+ comp5 BETWEEN 1 AND 10
+ comp6 NOT BETWEEN 1 AND 10
"A character literal has a certain pattern, preceded and
"followed by any string.
- "comp1 LIKE '%XYZ%'
+ "comp7 LIKE '%XYZ%'
"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
- "comp1 IN ( 'ABC', 'DEF', 'GHI' )
+ comp9 IN ( 'ABC', 'DEF', 'GHI' )
"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
- "comp1 IS INITIAL
+ "Checking if an operand has an initial value
+ comp11 IS INITIAL
"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
@@ -1146,11 +1144,11 @@ addition:
"Checking that table is not initial
IF ( 0 < lines( itab2 ) ).
- SELECT comp1, comp2, comp3
- FROM dbtab
- FOR ALL ENTRIES IN @itab2 "Host variable before internal table
- WHERE comp1 = @itab2-comp1 ... "Relational expression on the right side of a comparison
- INTO TABLE @itab1
+ SELECT comp1, comp2, comp3
+ FROM dbtab
+ FOR ALL ENTRIES IN @itab2 "Host variable before internal table
+ WHERE comp1 = @itab2-comp1 ... "Relational expression on the right side of a comparison
+ INTO TABLE @itab1
ENDIF.
```
@@ -1163,11 +1161,11 @@ The following code snippet includes a parenthesized subquery following `EXISTS`.
``` abap
SELECT comp1, comp2, comp3
- FROM dbtab1 AS tab1
- WHERE EXISTS
- ( SELECT comp1 FROM dbtab2
- WHERE comp1 = tab1~comp1 AND comp2 = tab1~comp2 )
- INTO ...
+ FROM dbtab1 AS tab1
+ WHERE EXISTS
+ ( SELECT comp1 FROM dbtab2
+ WHERE comp1 = tab1~comp1 AND comp2 = tab1~comp2 )
+ INTO ...
```
### 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
SELECT a~comp1, a~comp2, b~comp3, c~comp4
- FROM dbtab1 AS a
- INNER JOIN dbtab2 AS b
- ON a~comp1 = b~comp1 AND a~comp2 = b~comp2
- INNER JOIN dbtab3 AS c
- ON a~comp1 = c~comp1
- WHERE ...
- INTO ...
+ FROM dbtab1 AS a
+ INNER JOIN dbtab2 AS b ON a~comp1 = b~comp1 AND a~comp2 = b~comp2
+ INNER JOIN dbtab3 AS c ON a~comp1 = c~comp1
+ 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)**:
@@ -1201,11 +1197,10 @@ a [right outer join](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/
``` abap
"Example for a left outer join
SELECT a~comp1, a~comp2, b~comp3,
- FROM dbtab1 AS a
- LEFT OUTER JOIN dbtab2 AS b
- ON a~comp1 = b~comp1
- WHERE ...
- INTO ...
+ FROM dbtab1 AS a
+ LEFT OUTER JOIN dbtab2 AS b ON a~comp1 = b~comp1
+ WHERE ...
+ INTO ...
```
> **💡 Note**
> There are more join variants available. See the ABAP
@@ -1217,13 +1212,13 @@ for more information.
``` abap
SELECT FROM dbtab1
- FIELDS ...
- WHERE ...
+ FIELDS ...
+ WHERE ...
UNION
- SELECT FROM dbtab2
- FIELDS ...
- WHERE ...
- INTO ...
+ SELECT FROM dbtab2
+ FIELDS ...
+ WHERE ...
+ INTO ...
```
#### Excursion: Using Common Table Expressions (CTE)
@@ -1283,29 +1278,27 @@ internal table.
``` abap
WITH
+connections AS (
- SELECT zdemo_abap_flsch~carrid, carrname, connid, cityfrom, cityto
- FROM zdemo_abap_flsch
- INNER JOIN zdemo_abap_carr
- ON zdemo_abap_carr~carrid = zdemo_abap_flsch~carrid
- WHERE zdemo_abap_flsch~carrid BETWEEN 'AA' AND 'JL' ),
+ SELECT zdemo_abap_flsch~carrid, carrname, connid, cityfrom, cityto
+ FROM zdemo_abap_flsch
+ INNER JOIN zdemo_abap_carr
+ ON zdemo_abap_carr~carrid = zdemo_abap_flsch~carrid
+ WHERE zdemo_abap_flsch~carrid BETWEEN 'AA' AND 'JL' ),
+sum_seats AS (
- SELECT carrid, connid, SUM( seatsocc ) AS sum_seats
- FROM zdemo_abap_fli
- WHERE carrid BETWEEN 'AA' AND 'JL'
- GROUP BY carrid, connid ),
+ SELECT carrid, connid, SUM( seatsocc ) AS sum_seats
+ FROM zdemo_abap_fli
+ WHERE carrid BETWEEN 'AA' AND 'JL'
+ GROUP BY carrid, connid ),
+result( name, connection, departure, arrival, occupied ) AS (
- SELECT carrname, c~connid, cityfrom, cityto, sum_seats
- FROM +connections AS c
- INNER JOIN +sum_seats AS s
- ON c~carrid = s~carrid AND
- c~connid = s~connid )
+ SELECT carrname, c~connid, cityfrom, cityto, sum_seats
+ FROM +connections AS c
+ INNER JOIN +sum_seats AS s
+ ON c~carrid = s~carrid AND c~connid = s~connid )
SELECT *
- FROM +result
- ORDER BY name, connection
- INTO TABLE @DATA(result).
+ FROM +result
+ ORDER BY name, connection
+ INTO TABLE @DATA(result).
```
-
(back to top)
## 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 ) ).
-UPDATE dbtab FROM TABLE @ind_tab
- INDICATORS SET STRUCTURE comp_ind.
+UPDATE dbtab FROM TABLE @ind_tab INDICATORS SET STRUCTURE comp_ind.
"Reverses the logic
-UPDATE dbtab FROM TABLE @ind_tab
- INDICATORS NOT SET STRUCTURE comp_ind.
+UPDATE dbtab FROM TABLE @ind_tab INDICATORS NOT SET STRUCTURE comp_ind.
"SET addition: Changing values of specific fields in all table rows
"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.
SELECT *
- FROM (dbtab)
- WHERE ...
- INTO ...
+ FROM (dbtab)
+ WHERE ...
+ 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.
diff --git a/04_ABAP_Object_Orientation.md b/04_ABAP_Object_Orientation.md
index 26f82e4..59f98bb 100644
--- a/04_ABAP_Object_Orientation.md
+++ b/04_ABAP_Object_Orientation.md
@@ -119,9 +119,9 @@ possible for the declaration part.
``` abap
"Declaration part
CLASS global_class DEFINITION
- PUBLIC "Makes the class a global class in the class library.
- FINAL "Means that no subclasses can be derived from this class.
- CREATE PUBLIC. "This class can be instantiated anywhere it is visible.
+ PUBLIC "Makes the class a global class in the class library.
+ FINAL "Means that no subclasses can be derived from this class.
+ CREATE PUBLIC. "This class can be instantiated anywhere it is visible.
... "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.
CLASS singleton_class DEFINITION CREATE PRIVATE.
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.
- CLASS-DATA instance TYPE REF TO singleton_class.
+ CLASS-DATA inst TYPE REF TO singleton_class.
ENDCLASS.
CLASS singleton_class IMPLEMENTATION.
METHOD get_instance.
- IF instance IS NOT BOUND.
- instance = NEW #( ).
+ IF inst IS NOT BOUND.
+ inst = NEW #( ).
ENDIF.
- inst = instance.
+ ret = inst.
ENDMETHOD.
ENDCLASS.
```
diff --git a/05_Constructor_Expressions.md b/05_Constructor_Expressions.md
index 209bd8b..e4a7fa3 100644
--- a/05_Constructor_Expressions.md
+++ b/05_Constructor_Expressions.md
@@ -107,9 +107,9 @@ Example: Structure
``` abap
"Creating a structured type
TYPES: BEGIN OF struc_type,
- a TYPE i,
- b TYPE c LENGTH 3,
- END OF struc_type.
+ a TYPE i,
+ b TYPE c LENGTH 3,
+ END OF struc_type.
DATA struc TYPE struc_type. "Structured data object
@@ -186,12 +186,12 @@ demonstrates a nested structure.
``` abap
"Creating a nested structure
DATA: BEGIN OF nested_struc,
- a TYPE i,
- BEGIN OF struct,
- b TYPE i,
- c TYPE c LENGTH 3,
- END OF struct,
- END OF nested_struc.
+ a TYPE i,
+ BEGIN OF struct,
+ b TYPE i,
+ c TYPE c LENGTH 3,
+ END OF struct,
+ END OF nested_struc.
"Filling the deep structure
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
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
- basically replaces [CREATE
- 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).
+ basically replaces [`CREATE 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).
- For the type specification preceding the parentheses, you can use
- 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")
@@ -556,14 +554,14 @@ Examples:
``` abap
"Leads to a data loss when converting to a data object accepting only a single character
TRY.
- DATA(exact1) = EXACT abap_bool( 'XY' ).
- CATCH CX_SY_CONVERSION_DATA_LOSS INTO DATA(error1).
+ DATA(exact1) = EXACT abap_bool( 'XY' ).
+ CATCH CX_SY_CONVERSION_DATA_LOSS INTO DATA(error1).
ENDTRY.
"The calculation cannot be executed exactly; a rounding is necessary
TRY.
- DATA(exact2) = EXACT decfloat34( 1 / 3 ).
- CATCH CX_SY_CONVERSION_ROUNDING INTO DATA(error2).
+ DATA(exact2) = EXACT decfloat34( 1 / 3 ).
+ CATCH CX_SY_CONVERSION_ROUNDING INTO DATA(error2).
ENDTRY.
```
@@ -591,7 +589,7 @@ Examples:
"Data references
"Declaring data object and assign value
-DATA number TYPE i VALUE 5.
+DATA num TYPE i VALUE 5.
"Declaring data reference variable
@@ -599,7 +597,7 @@ DATA dref_a TYPE REF TO i.
"Getting references
-dref_a = REF #( number ).
+dref_a = REF #( num ).
"Inline declaration and explicit type specification
DATA(dref_b) = REF string( `hallo` ).
@@ -640,14 +638,12 @@ DATA(oref_b) = REF #( oref_a ).
examples:
``` abap
"Getting component information
-DATA(components) =
- CAST cl_abap_structdescr(
- cl_abap_typedescr=>describe_by_data( some_object ) )->components.
+DATA(components) = CAST cl_abap_structdescr(
+ cl_abap_typedescr=>describe_by_data( some_object ) )->components.
"Getting method information
-DATA(methods) =
- CAST cl_abap_objectdescr(
- cl_abap_objectdescr=>describe_by_name( 'LOCAL_CLASS' ) )->methods.
+DATA(methods) = CAST cl_abap_objectdescr(
+ cl_abap_objectdescr=>describe_by_name( 'LOCAL_CLASS' ) )->methods.
```
(back to top)
@@ -674,9 +670,9 @@ DATA(methods) =
Example:
``` abap
DATA(b) = COND #( WHEN a BETWEEN 1 AND 3 THEN w
- WHEN a > 4 THEN x
- WHEN a IS INITIAL THEN y
- ELSE z ).
+ WHEN a > 4 THEN x
+ WHEN a IS INITIAL THEN y
+ ELSE z ).
```
(back to top)
@@ -693,10 +689,10 @@ checked in the case distinction.
``` abap
DATA(b) = SWITCH #( a
- WHEN 1 THEN w
- WHEN 2 THEN x
- WHEN 3 THEN y
- ELSE z ).
+ WHEN 1 THEN w
+ WHEN 2 THEN x
+ WHEN 3 THEN y
+ ELSE z ).
```
(back to top)
@@ -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.
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
- WITH EMPTY KEY
- WITH UNIQUE SORTED KEY line COMPONENTS table_line.
+ WITH EMPTY KEY
+ WITH UNIQUE SORTED KEY line COMPONENTS 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
using the `REDUCE` operator:
``` abap
+"sum: 55
DATA(sum) = REDUCE i( INIT s = 0
- FOR i = 1 UNTIL i > 10
- NEXT s += i ) ). "sum: 55
+ FOR i = 1 UNTIL i > 10
+ NEXT s += i ) ).
```
> **💡 Note**
@@ -830,8 +827,8 @@ has the same effect as the example using `UNTIL` shown above.
``` abap
DATA(sum) = REDUCE i( INIT y = 0
- FOR n = 1 THEN n + 1 WHILE n < 11
- NEXT y += n ).
+ FOR n = 1 THEN n + 1 WHILE n < 11
+ NEXT y += n ).
```
`FOR ... UNTIL`: See the example in the `REDUCE`
@@ -865,17 +862,17 @@ tables:
TYPES t_type LIKE itab.
... = VALUE t_type( FOR wa IN itab
- "WHERE ( comp1 > 2 )
- ( wa ) ).
+ "WHERE ( comp1 > 2 )
+ ( wa ) ).
"Storing specific components having different names by specifying the assignment
"individually; assumption: the target type is not compatible to the type of itab;
"a field mapping is provided; pay attention to potential type conversion
... = VALUE t_type( FOR wa IN itab
- "WHERE ( comp1 > 2 )
- ( compX = wa-comp1
- compY = wa-comp2 ) ).
+ "WHERE ( comp1 > 2 )
+ ( compX = wa-comp1
+ compY = wa-comp2 ) ).
"Storing specific components having the same names;
"assumption: Target type is not compatible to the type of itab;
@@ -883,17 +880,17 @@ TYPES t_type LIKE itab.
"also use CORRESPONDING
... = VALUE t_type( FOR wa IN itab
- "WHERE ( comp1 > 2 )
- ( CORRESPONDING #( wa ) ) ).
+ "WHERE ( comp1 > 2 )
+ ( CORRESPONDING #( wa ) ) ).
"Multiple iteration expressions
... = VALUE t_type( FOR wa1 IN itab1 WHERE ( comp1 = 4 )
- FOR wa2 IN itab2 WHERE ( comp2 > 5 )
- FOR wa3 IN itab3 WHERE ( comp3 < 3 )
- ( compX = wa1-comp1
- compY = wa2-comp2
- compZ = wa3-comp3 ) ).
+ FOR wa2 IN itab2 WHERE ( comp2 > 5 )
+ FOR wa3 IN itab3 WHERE ( comp3 < 3 )
+ ( compX = wa1-comp1
+ compY = wa2-comp2
+ compZ = wa3-comp3 ) ).
```
(back to top)
@@ -922,10 +919,10 @@ DATA(str_tab) = VALUE string_table( LET it = `be` IN
"Conditional expressions
DATA(a) = COND #( LET b = c IN
- WHEN b > x THEN ...
- WHEN b < y THEN ...
- ...
- ELSE ... ).
+ WHEN b > x THEN ...
+ WHEN b < y THEN ...
+ ...
+ ELSE ... ).
```
(back to top)
diff --git a/06_Dynamic_Programming.md b/06_Dynamic_Programming.md
index 693fd17..4b4e17f 100644
--- a/06_Dynamic_Programming.md
+++ b/06_Dynamic_Programming.md
@@ -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.
```abap
+ DATA(dbtab) = `ZDEMO_ABAP_FLI`.
+
SELECT *
- FROM (dbtab)
- INTO TABLE @DATA(some_itab).
+ FROM (dbtab)
+ 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)).
@@ -105,9 +107,9 @@ Once the memory area is assigned, you can work with the content.
``` abap
"Some data object declarations to be used
-DATA: number TYPE i,
- struc TYPE zdemo_abap_fli, "Demo database table
- tab TYPE string_table.
+DATA: num TYPE i,
+ struc TYPE zdemo_abap_fli, "Demo database table
+ tab TYPE string_table.
"Declaring field symbols with complete types
FIELD-SYMBOLS: TYPE i,
@@ -119,14 +121,14 @@ FIELD-SYMBOLS TYPE data.
"Assigning data objects to field symbols
"Note: In this case, the field symbols have an appropriate type.
-ASSIGN number TO .
-ASSIGN struc TO .
-ASSIGN tab TO .
-ASSIGN number TO . "Could be any of the data objects
+ASSIGN num TO .
+ASSIGN struc TO .
+ASSIGN tab TO .
+ASSIGN num TO . "Could be any of the data objects
"Inline declaration is possible, too. The type
"is automatically derived.
-ASSIGN number TO FIELD-SYMBOL().
+ASSIGN num TO FIELD-SYMBOL().
"You can also assign a particular component of a structure.
"Second component of the structure
@@ -168,17 +170,18 @@ ASSIGN chars TO CASTING TYPE c_len_3.
``` abap
"For example, in assignments
-DATA number TYPE i VALUE 1.
+DATA num TYPE i VALUE 1.
FIELD-SYMBOLS TYPE i.
-ASSIGN number TO .
+ASSIGN num TO .
= 2.
-"The data object 'number' has now the value 2.
+"The data object 'num' has now the value 2.
"Loops
"Here, field symbols are handy since you can avoid an
"actual copying of the table line to boost performance.
-SELECT * FROM zdemo_abap_fli
+SELECT *
+ FROM zdemo_abap_fli
INTO TABLE @DATA(itab).
FIELD-SYMBOLS LIKE LINE OF itab.
@@ -261,8 +264,7 @@ DATA(ref2) = REF #( num ).
DATA(ref3) = REF string( `hallo` ).
-"The older syntax GET REFERENCE having the same effect
-"should not be used anymore.
+"The older syntax GET REFERENCE having the same effect should not be used anymore.
"GET REFERENCE OF num INTO ref1.
"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
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).
-The older syntax [`CREATE DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcreate_data.htm)
-has the same effect as using the newer instance operator.
+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.
``` abap
"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 ) ).
"CREATE DATA statements (older syntax)
-"Unlike above, the older syntax is not commented out. CREATE DATA is used for dynamic
-"type specification as shown further down.
-DATA ref4 TYPE REF TO string.
-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
-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
@@ -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) `=`.
- 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")
-[`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
-the operator [`?=`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmove_cast.htm).
+[`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
+ [`?=`](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.
@@ -364,7 +363,7 @@ DATA ref6 TYPE REF TO data.
ref6 = NEW i( 654 ).
ref5 = CAST #( ref6 ).
-"Casting operator: Older syntax
+"Casting operator in older syntax
"ref5 ?= ref6.
```
@@ -430,11 +429,11 @@ Some example contexts of using data references are as follows:
**Overwriting data reference variables**:
``` abap
-ref = NEW i( 1 ).
+dref = NEW i( 1 ).
"ref is overwritten here because a new object is created
"with a data reference variable already pointing to a data object
-ref = NEW i( 2 ).
+dref = NEW i( 2 ).
```
**Retaining data references**:
@@ -444,20 +443,20 @@ ref = NEW i( 2 ).
"with the same reference variable. Storing them in an internal table
"using the TYPE TABLE OF REF TO prevents the overwriting.
-DATA: ref TYPE REF TO data,
- itab TYPE TABLE OF REF TO data,
- number TYPE i VALUE 0.
+DATA: dref TYPE REF TO data,
+ itab TYPE TABLE OF REF TO data,
+ num TYPE i VALUE 0.
DO 3 TIMES.
"Adding up 1 to demonstrate a changed data object.
- number += 1.
+ num += 1.
"Creating data reference and assigning value.
"In the course of the loop, the variable gets overwritten.
- ref = NEW i( number ).
+ dref = NEW i( num ).
"Adding the reference to itab
- itab = VALUE #( BASE itab ( ref ) ).
+ itab = VALUE #( BASE itab ( dref ) ).
ENDDO.
```
@@ -469,7 +468,8 @@ ENDDO.
"instead of actually copying the content to boost performance.
"Filling an internal table.
-SELECT * FROM zdemo_abap_fli
+SELECT *
+ FROM zdemo_abap_fli
INTO TABLE @DATA(fli_tab).
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.
"Note that the NEW operator cannot be used here.
- CREATE DATA ref TYPE (some_type).
- CREATE DATA ref TYPE TABLE OF (some_type).
+ CREATE DATA dref TYPE (some_type).
+ CREATE DATA dref TYPE TABLE OF (some_type).
"Assigning a data object to a field symbol casting a dynamically specified type
diff --git a/07_String_Processing.md b/07_String_Processing.md
index 72d7dd8..06285f3 100644
--- a/07_String_Processing.md
+++ b/07_String_Processing.md
@@ -172,9 +172,9 @@ DATA isbn_number TYPE n LENGTH 13 VALUE '1234567890123'.
CONSTANTS pi TYPE p LENGTH 8 DECIMALS 14 VALUE '3.14159265358979'.
"More data object declarations
-DATA: char1 TYPE c LENGTH 5,
- html TYPE string,
- str2 LIKE html.
+DATA: char1 TYPE c LENGTH 5,
+ html TYPE string,
+ str2 LIKE html.
"Value assignments
char1 = 'ab123'.
@@ -485,7 +485,7 @@ SHIFT s3 RIGHT DELETING TRAILING ` `. "' hallo' (length is kept)
"you can use the following sequence of statements
DATA(s4) = `hallo `.
SHIFT s4 RIGHT DELETING TRAILING ` `. "' hallo'
-SHIFT s4 LEFT DELETING LEADING ` `. "'hallo'
+SHIFT s4 LEFT DELETING LEADING ` `. "'hallo'
"String functions with parameters
s1 = `hallo`.
@@ -872,12 +872,12 @@ Syntax Overview (see the syntax diagram in the [ABAP Keyword Documentation](http
``` abap
FIND
- FIRST OCCURRENCE OF | ALL OCCURRENCES OF
+ FIRST OCCURRENCE OF "(or) ALL OCCURRENCES OF
"1. Only the first occurrence is searched
"2. All occurrences are searched
"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);
" 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;
@@ -886,7 +886,8 @@ FIND
IN
SECTION
- OFFSET off | LENGTH len
+ OFFSET off
+ LENGTH len
OF
"- 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
@@ -901,7 +902,7 @@ dobj
"Further additional options for advanced evaluation options:
"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)
"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
"that are stored in subgroup registers of regular expressions; in FIND IN TABLE statements, the additional component LINE
"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;
"only to be used if a regular expression pattern is specified.
@@ -1131,7 +1132,7 @@ res = find( val = str sub = `xy` ). "-1
TRY.
res = find( val = str sub = `` ).
CATCH cx_sy_strg_par_val.
- "Nope!
+ ...
ENDTRY.
"The search is case-sensitive by default
@@ -1154,7 +1155,7 @@ res = find( val = str sub = `e` len = 2 ). "-1
TRY.
res = find( val = str sub = `e` off = 5 len = 15 ).
CATCH cx_sy_range_out_of_bounds.
- "Nope!
+ ...
ENDTRY.
```
diff --git a/08_EML_ABAP_for_RAP.md b/08_EML_ABAP_for_RAP.md
index 0cc5d26..b47fa5a 100644
--- a/08_EML_ABAP_for_RAP.md
+++ b/08_EML_ABAP_for_RAP.md
@@ -774,9 +774,8 @@ EML statement including the execution of an action:
MODIFY ENTITIES OF root_ent
ENTITY root
EXECUTE some_action
- FROM action_tab
- RESULT DATA(action_result) "Assumption: The action is defined with a
- "result parameter.
+ FROM action_tab
+ RESULT DATA(action_result) "Assumption: The action is defined with a result parameter.
...
```
@@ -837,8 +836,7 @@ is available for reading all field values.
READ ENTITIES OF root_ent
ENTITY root_ent
ALL FIELDS WITH
- VALUE #( ( key_field = 1 ) "Derived type TYPE TABLE FOR READ IMPORT
- "only includes the keys
+ VALUE #( ( key_field = 1 ) "Derived type TYPE TABLE FOR READ IMPORT only includes the keys
( key_field = 2 ) )
RESULT DATA(result)
FAILED DATA(f)
diff --git a/10_ABAP_SQL_Hierarchies.md b/10_ABAP_SQL_Hierarchies.md
index 3ce8fc0..0931f3e 100644
--- a/10_ABAP_SQL_Hierarchies.md
+++ b/10_ABAP_SQL_Hierarchies.md
@@ -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").
Here is a very simple example for that:
-``` abap
+```
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view entity DEMO_CDS_SIMPLE_TREE_VIEW
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
hierarchy that can be defined as follows:
-``` abap
+```
define hierarchy DEMO_CDS_SIMPLE_TREE
with parameters
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 )
- FIELDS id,
- parent,
- name,
- hierarchy_rank,
- hierarchy_tree_size,
- hierarchy_parent_rank,
- hierarchy_level,
- hierarchy_is_cycle,
- hierarchy_is_orphan,
- node_id,
- parent_id
- INTO TABLE @FINAL(cds_result).
+ FIELDS id,
+ parent,
+ name,
+ hierarchy_rank,
+ hierarchy_tree_size,
+ hierarchy_parent_rank,
+ hierarchy_level,
+ hierarchy_is_cycle,
+ hierarchy_is_orphan,
+ node_id,
+ parent_id
+ INTO TABLE @FINAL(cds_result).
```
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
SIBLINGS ORDER BY id
MULTIPLE PARENTS NOT ALLOWED ) "hierarchy
-]
FIELDS id,
parent,
name,
@@ -321,12 +320,11 @@ WITH
WITH ASSOCIATIONS (
JOIN TO MANY +cte_simple_tree_source AS _tree
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
START WHERE id = @root_id
SIBLINGS ORDER BY id
MULTIPLE PARENTS NOT ALLOWED ) "hierarchy
-]
FIELDS id,
parent,
name,
@@ -338,7 +336,7 @@ WITH
hierarchy_is_orphan,
node_id,
parent_id
- INTO TABLE @FINAL(asql_cte_result). ]
+ INTO TABLE @FINAL(asql_cte_result).
ASSERT asql_cte_result = cds_result.
```
@@ -390,7 +388,7 @@ WITH
( SELECT FROM demo_cds_simple_tree( p_id = @root_id )
FIELDS * )
WITH HIERARCHY demo_cds_simple_tree
- SELECT FROM +tree "hierarchy ]
+ SELECT FROM +tree "hierarchy ]
FIELDS id,
parent,
name,
@@ -418,7 +416,7 @@ WITH
parent,
name )
WITH HIERARCHY asql_hierarchy
- SELECT FROM +tree "hierarchy ]
+ SELECT FROM +tree "hierarchy ]
FIELDS id,
parent,
name,
@@ -454,7 +452,7 @@ WITH
parent,
name )
WITH HIERARCHY cte_hierarchy
- SELECT FROM +tree "hierarchy ]
+ SELECT FROM +tree "hierarchy ]
FIELDS id,
parent,
name,
@@ -522,11 +520,11 @@ DATA sub_id TYPE demo_cds_simple_tree_view-id.
SELECT FROM HIERARCHY_DESCENDANTS(
SOURCE demo_cds_simple_tree( p_id = @root_id )
START WHERE id = @sub_id )
- FIELDS id,
+ FIELDS id,
parent_id,
name,
hierarchy_distance
- INTO TABLE @FINAL(descendants).
+ INTO TABLE @FINAL(descendants).
```
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(
SOURCE demo_cds_simple_tree( p_id = @root_id )
START WHERE id = @max_id )
- FIELDS id,
+ FIELDS id,
parent_id,
name,
hierarchy_distance
- INTO TABLE @FINAL(ancestors).
+ INTO TABLE @FINAL(ancestors).
```
Looking at the result when running
@@ -587,11 +585,11 @@ DATA sibl_id TYPE demo_cds_simple_tree_view-id.
SELECT FROM HIERARCHY_SIBLINGS(
SOURCE demo_cds_simple_tree( p_id = @root_id )
START WHERE id = @sibl_id )
- FIELDS id,
+ FIELDS id,
parent_id,
name,
hierarchy_sibling_distance
- INTO TABLE @FINAL(siblings).
+ INTO TABLE @FINAL(siblings).
```
You see that this function adds another hierarchy column
@@ -646,11 +644,11 @@ SELECT FROM HIERARCHY_DESCENDANTS_AGGREGATE(
WHERE hierarchy_rank > 1
WITH SUBTOTAL
WITH BALANCE )
- FIELDS id,
+ FIELDS id,
amount_sum,
hierarchy_rank,
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
diff --git a/11_ABAP_SQL_Grouping_Internal_Tables.md b/11_ABAP_SQL_Grouping_Internal_Tables.md
index 8fffcc8..b15c017 100644
--- a/11_ABAP_SQL_Grouping_Internal_Tables.md
+++ b/11_ABAP_SQL_Grouping_Internal_Tables.md
@@ -50,12 +50,12 @@ representative binding.
To access the members of a group, a member loop can be inserted into the
group loop:
``` abap
-LOOP AT spfli_tab INTO wa
- GROUP BY wa-carrid.
+LOOP AT spfli_tab INTO wa
+ GROUP BY wa-carrid.
...
- LOOP AT GROUP wa INTO DATA(member).
+ LOOP AT GROUP wa INTO DATA(member).
... member-... ...
- ENDLOOP.
+ ENDLOOP.
...
ENDLOOP.
```
@@ -71,8 +71,8 @@ defined as follows. In the simplest case, the grouping criteria are
columns of the internal table:
``` abap
-LOOP AT spfli_tab INTO wa
- GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ).
+LOOP AT spfli_tab INTO wa
+ GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ).
... wa-carrid ... wa-airpfrom ...
ENDLOOP.
```
@@ -92,9 +92,9 @@ of the representative binding in which the output area of the group loop
is reused:
``` abap
-LOOP AT spfli_tab INTO wa
- GROUP BY wa-carrid
- INTO DATA(key).
+LOOP AT spfli_tab INTO wa
+ GROUP BY wa-carrid
+ INTO DATA(key).
... key ...
ENDLOOP.
```
@@ -118,13 +118,13 @@ binding, with the difference that a group is now addressed by
`key` instead of `wa`.
``` abap
-LOOP AT spfli_tab INTO wa
- GROUP BY wa-carrid
- INTO key.
+LOOP AT spfli_tab INTO wa
+ GROUP BY wa-carrid
+ INTO key.
...
- LOOP AT GROUP key INTO member.
+ LOOP AT GROUP key INTO member.
... members ...
- ENDLOOP.
+ ENDLOOP.
...
ENDLOOP.
```
@@ -134,8 +134,8 @@ Finally, the group key binding for structured group keys:
``` abap
LOOP AT spfli_tab INTO wa
- GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom )
- INTO DATA(key).
+ GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom )
+ INTO DATA(key).
... key-key1 ... key-key2 ...
ENDLOOP.
```
@@ -150,10 +150,10 @@ can be used to save time and memory.
``` abap
LOOP AT spfli_tab INTO wa
- GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom
- index = GROUP INDEX size = GROUP SIZE )
- WITHOUT MEMBERS
- INTO DATA(key).
+ GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom
+ index = GROUP INDEX size = GROUP SIZE )
+ WITHOUT MEMBERS
+ INTO DATA(key).
... key-key1 ... key-key2 ... key-index ... key-size ...
ENDLOOP.
```
diff --git a/12_AMDP.md b/12_AMDP.md
index 6eeb9df..c9d1289 100644
--- a/12_AMDP.md
+++ b/12_AMDP.md
@@ -95,7 +95,7 @@ CLASS cl_some_amdp_class DEFINITION
PUBLIC SECTION.
"Specifying the interface is mandatory
- INTERFACES if_amdp_marker_hdb.
+ INTERFACES if_amdp_marker_hdb.
...
ENDCLASS.
```
@@ -122,12 +122,12 @@ methods:
...
PUBLIC SECTION.
- METHODS some_amdp_meth
+ METHODS some_amdp_meth
... "Here go the parameters
PRIVATE SECTION.
- CLASS-METHODS another_amdp_meth
+ CLASS-METHODS another_amdp_meth
... "Here go the parameters
...
@@ -167,11 +167,11 @@ Example for an AMDP procedure's declaration part:
PUBLIC SECTION.
"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
- IMPORTING VALUE(num) TYPE i,
- EXPORTING VALUE(tab) TYPE tab_type.
+ METHODS amdp_meth
+ IMPORTING VALUE(num) TYPE i,
+ EXPORTING VALUE(tab) TYPE tab_type.
...
```
@@ -185,10 +185,10 @@ following METHOD and the method name:
...
METHOD amdp_meth
BY DATABASE PROCEDURE
- FOR HDB
- LANGUAGE SQLSCRIPT
- OPTIONS READ-ONLY
- USING db_object. "see comments further down
+ FOR HDB
+ LANGUAGE SQLSCRIPT
+ OPTIONS READ-ONLY
+ USING db_object. "see comments further down
"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
more details as touched on further down.
-
-
## 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")
@@ -264,12 +262,12 @@ Example for an AMDP function's declaration part:
PUBLIC SECTION.
"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
- IMPORTING VALUE(num) TYPE i,
- VALUE(some_elem) TYPE c LENGTH 3,
- RETURNING VALUE(tab) TYPE tab_type.
+ METHODS amdp_func
+ IMPORTING VALUE(num) TYPE i,
+ VALUE(some_elem) TYPE c LENGTH 3,
+ 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
...
METHOD amdp_func
- BY DATABASE FUNCTION
- FOR HDB
- LANGUAGE SQLSCRIPT
- OPTIONS READ-ONLY
- USING db_object.
+ BY DATABASE FUNCTION
+ FOR HDB
+ LANGUAGE SQLSCRIPT
+ OPTIONS READ-ONLY
+ USING db_object.
"Beginning of the SQLScript code (note that it is not ABAP code although it looks similar)
@@ -331,8 +329,8 @@ function:
...
PUBLIC SECTION.
- CLASS-METHODS:
- table_func FOR TABLE FUNCTION some_ddl_source.
+ CLASS-METHODS:
+ 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:
-```abap
+```
//Here go annotations.
define table function some_ddl_source
returns
@@ -411,11 +409,11 @@ snippet:
```abap
IF NOT cl_abap_dbfeatures=>use_features(
- EXPORTING requested_features =
- VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ).
+ EXPORTING requested_features =
+ VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ).
"Result: Current database system does not support AMDP procedures
- RETURN.
+ RETURN.
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
relevant in the executable example.
-
## Executable Example
[zcl_demo_abap_amdp](./src/zcl_demo_abap_amdp.clas.abap)