-| Using table expressions |
+ Table expressions |
Using [table
@@ -1612,7 +1685,17 @@ DATA(line3) = VALUE #( itab[ 8 ] DEFAULT VALUE #( ) ).
### Reading Single Lines Using Table Keys
Lines can be read by explicitly specifying the table keys or the alias names, if any.
-```abap
+
+
+
+
+| Statement | Details/Code Snippet |
+
+
+ READ TABLE |
+
+
+``` abap
"Example internal table with primary and secondary table key and alias names
"Assumption: All components are of type i
@@ -1620,24 +1703,6 @@ DATA it TYPE SORTED TABLE OF struc
WITH NON-UNIQUE KEY primary_key ALIAS pk COMPONENTS a b
WITH NON-UNIQUE SORTED KEY sec_key ALIAS sk COMPONENTS c d.
-"Table expressions
-
-"Key must be fully specified
-line = it[ KEY primary_key COMPONENTS a = 1 b = 2 ].
-
-"The addition COMPONENTS is optional; same as above
-line = it[ KEY primary_key a = 1 b = 2 ].
-
-"Primary key alias
-line = it[ KEY pk a = 1 b = 2 ].
-
-"Secondary table key
-line = it[ KEY sec_key c = 3 d = 4 ].
-
-"Secondary table key alias
-line = it[ KEY sk c = 3 d = 4 ].
-
-"READ TABLE statements
"Primary table key
READ TABLE it INTO wa WITH TABLE KEY primary_key COMPONENTS a = 1 b = 2.
@@ -1669,19 +1734,77 @@ READ TABLE it FROM sec_keys USING KEY sec_key INTO wa.
READ TABLE it FROM sec_keys USING KEY sk INTO wa.
```
+ |
+
+
+
+| Table expressions |
+
+
+
+``` abap
+"Key must be fully specified
+line = it[ KEY primary_key COMPONENTS a = 1 b = 2 ].
+
+"The addition COMPONENTS is optional; same as above
+line = it[ KEY primary_key a = 1 b = 2 ].
+
+"Primary key alias
+line = it[ KEY pk a = 1 b = 2 ].
+
+"Secondary table key
+line = it[ KEY sec_key c = 3 d = 4 ].
+
+"Secondary table key alias
+line = it[ KEY sk c = 3 d = 4 ].
+```
+
+ |
+
+
+
+
+
+
⬆️ back to top
### Reading Single Lines Using a Free Key
The specified components used as keys need not be part of a table key.
-``` abap
-line = it[ b = 2 ].
+
+
+| Statement | Details/Code Snippet |
+
+
+ READ TABLE |
+
+
+``` abap
"Note: Table keys are specified with the ... WITH TABLE KEY ... addition,
"free keys with ... WITH KEY ....
READ TABLE it INTO wa WITH KEY b = 2.
```
+ |
+
+
+
+| Table expressions |
+
+
+
+``` abap
+line = it[ b = 2 ].
+```
+
+ |
+
+
+
+
+
+
⬆️ back to top
### Examples of Addressing Individual Components of Read Lines
@@ -3264,46 +3387,117 @@ As mentioned above, you can modify the content of internal table lines directly
The following examples demonstrate direct modification of recently read table lines:
``` abap
-"Table declarations
+"Declaring and populating demo internal tables
+TYPES: BEGIN OF ty_struc,
+ comp1 TYPE i,
+ comp2 TYPE string,
+ comp3 TYPE c LENGTH 3,
+ END OF ty_struc.
-DATA it_st TYPE TABLE OF struc WITH NON-UNIQUE KEY a.
+DATA it_st TYPE TABLE OF ty_struc WITH NON-UNIQUE KEY comp1.
+DATA it_so TYPE SORTED TABLE OF ty_struc WITH UNIQUE KEY comp1.
+DATA it_ha TYPE HASHED TABLE OF ty_struc WITH UNIQUE KEY comp1.
-DATA it_so TYPE SORTED TABLE OF struc WITH UNIQUE KEY a.
+it_st = VALUE #( ( comp1 = 1 comp2 = `AAAAAA` comp3 = 'bbb' )
+ ( comp1 = 2 comp2 = `CCCCCC` comp3 = 'ddd' )
+ ( comp1 = 3 comp2 = `EEEEEE` comp3 = 'fff' )
+ ( comp1 = 4 comp2 = `GGGGGG` comp3 = 'hhh' )
+ ).
-"Reading table line into target area
+it_so = it_st.
+it_ha = it_st.
-READ TABLE it_st ASSIGNING FIELD-SYMBOL() INDEX 1.
+"---- Modifying internal table content by changing the ----
+"---- content of READ TABLE statement target areas --------
+"Reading table line into a target area
+READ TABLE it_st INTO DATA(wa) INDEX 1.
+READ TABLE it_so ASSIGNING FIELD-SYMBOL() INDEX 2.
+READ TABLE it_ha REFERENCE INTO DATA(dref) WITH TABLE KEY comp1 = 3. "No reading by index in case of hashed tables
-READ TABLE it_so REFERENCE INTO DATA(dref) INDEX 2.
+"------ Modification examples -------
+"Modifying all non-key components using the VALUE operator and
+"the BASE addition
+ = VALUE #( BASE comp2 = `IIIIII` comp3 = 'jjj' ).
-"Modification examples
-"Modifying the entire table line while keeping the values of other components;
-"this way is not possible for it_so because of key value change.
+"In the following example, the key value is assigned a new
+"value. Key values are protected against change in case of key tables.
+"A runtime error occurs.
+" = VALUE #( comp1 = 5 comp2 = `IIIIII` comp3 = 'jjj' ).
- = VALUE #( BASE a = 1 b = 2 ).
+dref->* = VALUE #( BASE dref->* comp2 = `KKKKKK` comp3 = 'lll' ).
-"Modifying a single component via field symbol
+"Same as above. Key values cannot be changed in this case.
+"dref->* = VALUE #( comp1 = 5 comp2 = `MMMMMM` comp3 = 'nnn' ).
--c = 3.
+"Using a MODIFY statement outlined below for changing internal
+"table content based on a read line in a work area
+MODIFY TABLE it_st FROM VALUE #( BASE wa comp2 = `OOOOOO` comp3 = 'ppp' ).
-"Modification via dereferencing
+"Modifying individual components
+READ TABLE it_st INTO wa INDEX 2.
+READ TABLE it_so ASSIGNING INDEX 3.
+READ TABLE it_ha REFERENCE INTO dref WITH TABLE KEY comp1 = 4.
-dref->b = 4.
+"Using VALUE/BASE
+ = VALUE #( BASE comp2 = `QQQQQQ` ).
+dref->* = VALUE #( BASE dref->* comp2 = `RRRRRR` ).
+MODIFY TABLE it_st FROM VALUE #( BASE wa comp2 = `SSSSSS` ).
-"Table expressions
+"Using the component selector
+-comp3 = 'ttt'.
-it_st[ 1 ] = VALUE #( a = 1 b = 2 ).
+READ TABLE it_st INTO wa INDEX 3.
+wa-comp3 = 'uuu'.
+MODIFY TABLE it_st FROM wa.
-it_st[ 2 ]-c = 3.
+"Object component selector in case of dereferencing ...
+dref->comp2 = `VVVVVV`.
+"... which is a more comfortable option compared to using the
+"dereferencing and component selector operators in the following way.
+dref->*-comp3 = 'www'.
-"Sorted table: no key field change
+"---- Modifying internal table content using table expressions -----
-it_so[ 2 ]-d = 4.
+"Changing the entire table line of a standard table
+"In standard tables, the key value change is allowed.
+it_st[ 3 ] = VALUE #( comp1 = 9 comp2 = `XXXXXX` comp3 = 'yyy' ).
+"As above, the sorted table is a key table having a unique key,
+"therefore a write cannot be performed on the entire entry. Runtime
+"errors can occur.
+"it_so[ 3 ] = VALUE #( comp2 = `XXXXXX` comp3 = 'yyy' ).
+"The same applies to hashed tables.
+"it_ha[ comp2 = `OOOOOO` ] = VALUE #( comp2 = `XXXXXX` comp3 = 'yyy' ).
+
+"Changing individual components
+it_st[ 3 ]-comp2 = `ZZZZZZ`.
+it_so[ 3 ]-comp3 = 'A1'.
+it_ha[ comp2 = `CCCCCC` ]-comp2 = `B2`.
+"As above, no key field change in key tables. Allowed in standard
+"tables.
+"it_so[ 3 ]-comp1 = 10.
+"it_ha[ comp2 = `AAAAAA` ]-comp1 = `C3`.
+it_st[ 1 ]-comp1 = 99.
+
+"---- Modifying table content in all table rows in a loop ----
+"For more syntax options regarding loops, check the section above.
+"Target area: field symbol
+LOOP AT it_st ASSIGNING FIELD-SYMBOL().
+ -comp2 = sy-tabix.
+ENDLOOP.
+
+"---- Modifying table content restricting the rows that are looped across ----
+"Target area: data reference variable
+LOOP AT it_st reference into data(lo) FROM 2 TO 3.
+ lo->comp3 = sy-tabix.
+ENDLOOP.
+
+"Target area: work area
+LOOP AT it_so into data(wa_lo) where comp1 < 4.
+ wa_lo-comp2 = sy-tabix.
+ MODIFY TABLE it_so FROM wa_lo.
+ENDLOOP.
```
-> **💡 Note**
-> If you want to modify recently read lines in a work area, for example, within a loop (`LOOP AT INTO dobj`), you can modify the line and then use a `MODIFY` statement to modify the internal table based on this line.
-
[`MODIFY`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmodify_itab.htm)
statements provide multiple ways of changing the content of single and multiple table lines by specifying the table key or a table index,
without first reading the lines into a target area.
@@ -3706,6 +3900,51 @@ ENDCLASS.
⬆️ back to top
+
+## Collecting Calues
+
+- You can use `COLLECT` statements, for example, to add the values of numeric components to the corresponding values in an internal table.
+- It is recommended that you use it mainly for internal tables with a unique primary key, especially hashed tables.
+- Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcollect.htm)
+
+``` abap
+"This example demonstrates how to insert data from a database table
+"into an internal table in a compressed way. Within a SELECT loop,
+"a COLLECT statement is used to consolidate lines with identical
+"primary key components (carrid and connid) by summing the number
+"of occupied seats in the numeric component (seatsocc).
+"Additionally, an internal table is filled by adding all read lines.
+"This table is looped across to simulate the effect of the COLLECT
+"statement.
+
+DATA: BEGIN OF seats,
+ carrid TYPE zdemo_abap_fli-carrid,
+ connid TYPE zdemo_abap_fli-connid,
+ seatsocc TYPE zdemo_abap_fli-seatsocc,
+ END OF seats,
+ seats_tab_col LIKE HASHED TABLE OF seats WITH UNIQUE KEY carrid connid,
+ seats_tab_all LIKE TABLE OF seats WITH EMPTY KEY,
+ seats_tab_loop_grp LIKE seats_tab_col.
+
+SELECT carrid, connid, seatsocc
+ FROM zdemo_abap_fli
+ INTO @seats.
+ COLLECT seats INTO seats_tab_col.
+ APPEND seats TO seats_tab_all.
+ENDSELECT.
+
+LOOP AT seats_tab_all INTO DATA(wa) GROUP BY ( key1 = wa-carrid key2 = wa-connid ).
+ INSERT VALUE #( carrid = wa-carrid connid = wa-connid ) INTO TABLE seats_tab_loop_grp ASSIGNING FIELD-SYMBOL().
+ LOOP AT GROUP wa INTO DATA(member).
+ -seatsocc = -seatsocc + member-seatsocc.
+ ENDLOOP.
+ENDLOOP.
+
+ASSERT seats_tab_loop_grp = seats_tab_col.
+```
+
+⬆️ back to top
+
## Excursions
### Improving Read Performance with Secondary Table Keys
diff --git a/02_Structures.md b/02_Structures.md
index 112fedd..5e0dc08 100644
--- a/02_Structures.md
+++ b/02_Structures.md
@@ -4,7 +4,13 @@
- [Structures](#structures)
- [Introduction](#introduction)
+ - [Globally Available Structures and Structured Types](#globally-available-structures-and-structured-types)
- [Creating Structures and Structured Types](#creating-structures-and-structured-types)
+ - [Creating Structured Types](#creating-structured-types)
+ - [Creating Structures](#creating-structures)
+ - [Creating Structures Using Existing Structured Types](#creating-structures-using-existing-structured-types)
+ - [Creating Structures by Inline Declaration](#creating-structures-by-inline-declaration)
+ - [Creating Anonymous Structures](#creating-anonymous-structures)
- [Variants of Structures](#variants-of-structures)
- [Accessing (Components of) Structures](#accessing-components-of-structures)
- [Populating Structures](#populating-structures)
@@ -25,22 +31,48 @@ Structures ...
- consist of a sequence of [components](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencomponent_glosry.htm "Glossary Entry") of any data type, that is, the components of a structure can be, for example, [elementary data objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenelementary_data_object_glosry.htm), structures themselves, [internal tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninternal_table_glosry.htm "Glossary Entry") or [references](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreference_glosry.htm).
- are used to combine different data objects that belong together. A typical example is an address. It has several components, such as name, street, city, and so on, that belong together.
- play an important role in the context of internal tables and [database tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendatabase_table_glosry.htm "Glossary Entry"). Structured types serve as [line types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrow_type_glosry.htm) for these tables. Most internal tables across [ABAP programs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_program_glosry.htm) may have structured line types. For database tables, there is no alternative to structured line types.
-- can be created locally in an ABAP program. You can also create them as global [DDIC structures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_structure_glosry.htm) in the [ABAP Dictionary](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_dictionary_glosry.htm). Such a DDIC structure defines a globally available structured type ([DDIC type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_type_glosry.htm)).
- - Note: There are other structured types available globally, which may be the structured types most commonly used in ABAP programs:
- - [Database tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_db_table_glosry.htm) defined in the ABAP Dictionary can be used as data types just like DDIC structures in an ABAP program. This means that when you create a structure in your ABAP program, for example, you can simply use the name of a database table to address the line type of the table. The structure you created will then have the same structured type as the database table. Typically, you use the database tables to create structures of such a type, or internal tables of such a structured line type, to process data read from the database table in structures or internal tables.
- - A [CDS entity](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_glosry.htm) such as a [CDS view](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_view_glosry.htm) also represents a structured data type and can be used as such in ABAP programs (but not in the ABAP Dictionary). The same applies to [DDIC views](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_view_glosry.htm) that are only available in [Standard ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_abap_glosry.htm).
- - Structures and structured data types can also be defined in the public [visibility section](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenvisibility_section_glosry.htm) of [global classes](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenglobal_class_glosry.htm) or in [global interfaces](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenglobal_interface_glosry.htm) and then used globally.
+- can be created locally in an ABAP program and globally. This cheat sheet focuses on locally defined structures and structured types.
⬆️ back to top
+## Globally Available Structures and Structured Types
+
+- Apart from the local declaration of a structured type, you can create such a type, for example, as global [DDIC structure](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_structure_glosry.htm) in the [ABAP Dictionary](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_dictionary_glosry.htm). Such a DDIC structure defines a globally available structured type ([DDIC type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_type_glosry.htm)).
+- There are other structured types available globally, which may be the structured types most commonly used in ABAP programs:
+ - [Database tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_db_table_glosry.htm) defined in the ABAP Dictionary can be used as data types just like DDIC structures in an ABAP program. This means that when you create a structure in your ABAP program, for example, you can simply use the name of a database table to address the line type of the table. The structure you created will then have the same structured type as the database table. Typically, you use the database tables to create structures of such a type, or internal tables of such a structured line type, to process data read from the database table in structures or internal tables.
+ - Various [CDS entities](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_glosry.htm) are globally available structured types. For example, a [CDS view entity](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_v2_view_glosry.htm) represents a structured data type and can be used as such in ABAP programs (but not in the ABAP Dictionary).
+ - Structures and structured data types can be defined in the public [visibility section](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenvisibility_section_glosry.htm) of [global classes](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenglobal_class_glosry.htm) or in [global interfaces](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenglobal_interface_glosry.htm) and then used globally.
+
+```abap
+"Creating structures based on globally available structured types
+"Database table
+DATA struc_from_dbtab TYPE zdemo_abap_fli.
+"CDS view entity
+DATA struc_from_cds_ve TYPE zdemo_abap_fli.
+"CDS abstract entity
+DATA struc_from_cds_abs TYPE zdemo_abap_abstract_ent.
+"CDS table function
+DATA struc_from_cds_tab_func TYPE zdemo_abap_table_function.
+
+"Globally available structured type in the public visibility section of
+"classes/interfaces
+DATA struc_from_struc_type_in_cl TYPE zcl_demo_abap_amdp=>fli_struc.
+
+"Creating structured types based on globally available structured types
+TYPES ty_struc_from_dbtab TYPE zdemo_abap_fli.
+TYPES ty_struc_from_cds_ve TYPE zdemo_abap_fli.
+```
+
+> **💡 Note**
+> - This cheat sheet focuses on locally defined structures and structured types.
+> - Classic [DDIC views](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_view_glosry.htm) are not available in [ABAP Cloud](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_cloud_glosry.htm). They can only be used as structured types in [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm).
+
## Creating Structures and Structured Types
The typical language elements for creating structures and structured types locally in an ABAP program are [`BEGIN OF ... END OF ...`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaptypes_struc.htm). They are used in combination with the [`TYPES`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaptypes.htm) keyword to create a structured type and the [`DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdata.htm) keyword to create a structure.
-> **💡 Note**
-> This cheat sheet focuses on locally defined structures and structured types.
-**Creating structured types**
+### Creating Structured Types
- The following statement defines a structured type introduced by `TYPES`. The type name is preceded by `BEGIN OF` (which marks the beginning of the structured type definition) and `END OF` (the end of the definition).
- The components - at least one must be defined - are listed in between.
@@ -95,9 +127,9 @@ TYPES: BEGIN OF struc_type,
> Outside of classes, you can also refer to DDIC types using `LIKE` (`... comp11 LIKE ddic_type, ...`). If you actually want to refer to an existing data object, but due to typing errors you inadvertently specify a name that exists as DDIC type, errors may be unavoidable.
-**Creating structures**
+### Creating Structures
-- To create a structure in an ABAP program, you can use the `DATA` keyword.
+- To create a structure (i.e. a structured data object) in an ABAP program, you can use the `DATA` keyword.
- It works in the same way as the `TYPES` statement above.
- Unlike the `TYPES` statement, you can use the [`VALUE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdata_options.htm) addition to set default values.
@@ -127,7 +159,7 @@ DATA END OF struc.
>- The keywords [`CLASS-DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapclass-data.htm) and [`CONSTANTS`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapconstants.htm) can also be used to create structures. In principle, they represent special cases of the general statement shown above. See the ABAP Keyword Documentation for more information.
>- Structures can also be created [inline](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninline_declaration_glosry.htm) using [`DATA(...)`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_inline.htm) or [`FINAL(...)`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfinal_inline.htm), as shown below.
-**Creating structures using existing structured types**
+### Creating Structures Using Existing Structured Types
``` abap
"Local structured type
@@ -156,7 +188,7 @@ DATA: struc_6 LIKE struc_1,
```
-**Creating structures by inline declaration**
+### Creating Structures by Inline Declaration
- This is particularly useful for declaring data objects at the [operand positions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenoperand_position_glosry.htm) where you actually need them.
- In this way, you can avoid an extra declaration of the structure in different contexts.
@@ -214,7 +246,7 @@ LOOP AT itab INTO DATA(wa_2).
ENDLOOP.
```
-**Anonymous Structures**
+### Creating Anonymous Structures
Using the instance operator [`NEW`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_new.htm) and [`CREATE DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcreate_data.htm) statements, you can create [anonymous data objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenanonymous_data_object_glosry.htm "Glossary Entry"), such as anonymous structures.
The `NEW` addition of the `INTO` clause of an ABAP SQL `SELECT` statement also creates an anonymous data object.
diff --git a/06_Dynamic_Programming.md b/06_Dynamic_Programming.md
index 7ec9a93..dab8f82 100644
--- a/06_Dynamic_Programming.md
+++ b/06_Dynamic_Programming.md
@@ -74,7 +74,7 @@
- In general, dynamic programming also comes with some downsides. For example:
- The ABAP compiler cannot check the dynamic programming feature like the `SELECT` statement mentioned above. There is no syntax warning or suchlike.
- The checks are performed only at runtime, which has an impact on the performance.
- - The testing of [procedure](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenprocedure_glosry.htm "Glossary Entry") that include dynamic programming features may be difficult.
+ - The testing of [procedures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenprocedure_glosry.htm "Glossary Entry") that include dynamic programming features may be difficult.
- Including external input in dynamic ABAP SQL statements without an appropriate handling, there can be potential security risks. You can, for example, use the `CL_ABAP_DYN_PRG` class to manage security risks.
@@ -182,7 +182,7 @@ ASSIGN num TO FIELD-SYMBOL().
"symbol when assigning memory areas
TYPES c_len_3 TYPE c LENGTH 3.
DATA(chars) = 'abcdefg'.
-
+table_linebetween
FIELD-SYMBOLS TYPE c_len_3.
"Implicit casting
diff --git a/08_EML_ABAP_for_RAP.md b/08_EML_ABAP_for_RAP.md
index 1e05fde..347e749 100644
--- a/08_EML_ABAP_for_RAP.md
+++ b/08_EML_ABAP_for_RAP.md
@@ -10,6 +10,7 @@
- [RAP Saver Class and Saver Methods](#rap-saver-class-and-saver-methods)
- [BDEF Derived Types](#bdef-derived-types)
- [Components of BDEF Derived Types](#components-of-bdef-derived-types)
+ - [Constants for BDEF Derived Type Components](#constants-for-bdef-derived-type-components)
- [Secondary Table Keys of BDEF Derived Types](#secondary-table-keys-of-bdef-derived-types)
- [Type Mapping for RAP](#type-mapping-for-rap)
- [RAP-Specific Additions to the CORRESPONDING Operator](#rap-specific-additions-to-the-corresponding-operator)
@@ -865,6 +866,22 @@ Bullet points on selected `%` components:
`if_abap_behv=>mk-off`, the values of these fields
are not returned in the result.
+⬆️ back to top
+
+### Constants for BDEF Derived Type Components
+
+Several BDEF derived types contain `%` components, which have a specific type and represent flags. The mentioned `%control` structure of type `ABP_BEHV_FLAG` is such a component. When assigning values to these components, ensure you use appropriate values. The `IF_ABAP_BEHV` interface provides a range of structured constants for this purpose. Although these constants are technically identical, it is recommended that you use them in the right context.
+
+| Type | Structured Constant | Details |
+| -------- | ------- | ------- |
+| ABP_BEHV_FLAG | IF_ABAP_BEHV=>MK | Marks and unmarks fields in ABAP EML modify and read operations, such as in %control and %element. |
+| ABP_BEHV_FIELD_PERM | IF_ABAP_BEHV=>PERM-F | Used in the context of field permission results, such as a field marked as mandatory or read-only. |
+| ABP_BEHV_OP_PERM | IF_ABAP_BEHV=>PERM-O | For operation permission results, such as a delete operation that is marked as enabled. |
+| ABP_BEHV_FIELD_CTRL | IF_ABAP_BEHV=>FC-F | For field feature control results, such as a field marked with no restrictions. |
+| ABP_BEHV_OP_CTRL | IF_ABAP_BEHV=>FC-O | For operation feature control results, such as a disabled update operation. |
+| ABP_BEHV_AUTH | IF_ABAP_BEHV=>AUTH | For authorization results, such as an unauthorized operation. |
+
+
⬆️ back to top
### Secondary Table Keys of BDEF Derived Types
@@ -875,7 +892,8 @@ Bullet points on selected `%` components:
- `entity`: Includes `%key`
- `cid`: Includes `%cid` or `%cid_ref`, and can - depending on the type - also include `%key` and `%pid`
- `draft`: Available in draft scenarios; includes `%is_draft`; can also include `%key` and `%pid`
- - `pid` (alias name `id`): Available in late numbering scenarios; includes `%pid`; can also include `%tmp` and `%key`
+ - `pid`: Available in late numbering scenarios; includes `%pid`; can also include `%tmp` and `%key`
+ - The [alias name](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenalias_glosry.htm) `id` is available for either `entity`, `draft`, or `pid` depending on the context. Check the F2 information in ADT for the respective types.
```abap
DATA itab_cr TYPE TABLE FOR CREATE zdemo_abap_rap_ro_m.
diff --git a/19_ABAP_for_Cloud_Development.md b/19_ABAP_for_Cloud_Development.md
index 32ed814..0b6067e 100644
--- a/19_ABAP_for_Cloud_Development.md
+++ b/19_ABAP_for_Cloud_Development.md
@@ -57,15 +57,7 @@ It provides references to more detailed information on the topic.

- For deprecated and invalid syntax in ABAP for Cloud Development, refer to the following example code. You can create a demo class and insert the code below (adjust the class name if necessary). Several syntax errors and warnings will be displayed:
- - ABAP SQL statements
- - The first two ABAP SQL statements select from demo database tables. The first one is a demo table provided by SAP, but it cannot be accessed directly in the case of ABAP for Cloud Development like in the case of Standard ABAP. Therefore, it cannot be used as a data source for selection.
- - The second one is a database table from the ABAP cheat sheet GitHub repository. If you have imported the repository into the system, you can use it as a data source.
- - The CDS view is released and can be accessed in the restricted ABAP language scope.
- - Although the source code provides an invalid data source, the dynamic ABAP SQL statement does not produce a syntax error during compilation. However, it would result in a runtime error because you cannot select from that data source. You can check the validity of dynamic specifications using the `cl_abap_dyn_prg` class, which supports dynamic programming.
- - The addition `USING CLIENT` for client handling is not allowed in the restricted ABAP language scope.
- - When using APIs and types like `string_table`, ensure that they are released. The `IF_OO_ADT_CLASSRUN` interface is released, and you can implement it to run an ABAP class. In ADT, you can do this by choosing *F9*. However, the example class will not run because the class cannot be activated due to the syntax errors. To output the content of data objects, you can use `out->write( ... )` in the `main` method.
- - The example includes a selection of deprecated and invalid syntax in ABAP for Cloud Development. It includes the invalid statement `MOVE ... TO` and others that are added for demonstration purposes (some alternatives are provided). Certain system fields should not be accessed. The pointless `WRITE` statement within the method implementation represents invalid classic ABAP UI-related statements. Executable programs (*reports*) are not allowed in the restricted ABAP language scope. To set breakpoints in ADT, double-click the area to the left of the code line number.
+ For deprecated and invalid syntax in ABAP for Cloud Development, refer to the following (nonsensical) example code. You can create a demo class and insert the code below (adjust the class name if necessary). Several syntax errors and warnings will be displayed:
```abap
CLASS zcl_some_class DEFINITION
@@ -79,39 +71,87 @@ It provides references to more detailed information on the topic.
CLASS zcl_some_class IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
- "ABAP SQL statements
- "Using database tables and CDS views as data sources
- SELECT carrid, connid FROM spfli WHERE carrid = 'LH' INTO TABLE @DATA(it1).
- SELECT carrid, connid FROM zdemo_abap_fli WHERE carrid = 'LH' INTO TABLE @DATA(it2).
- SELECT SINGLE * FROM i_timezone WHERE TimeZoneID = 'EST' INTO @DATA(tz_info).
- "Dynamic ABAP SQL statements
- SELECT SINGLE carrid, connid FROM ('SPFLI') WHERE carrid = 'LH' INTO NEW @DATA(ref_a).
- SELECT SINGLE carrid, connid FROM ('ZDEMO_ABAP_FLI') WHERE carrid = 'LH' INTO NEW @DATA(ref_b).
- "ABAP SQL Statement involving client handling
- DATA(clnt) = sy-mandt.
- SELECT carrid, connid FROM zdemo_abap_fli USING CLIENT @clnt WHERE carrid = 'LH' INTO TABLE @DATA(it3).
+ "Example that demonstrates (not) released APIs, deprecated and
+ "invalid syntax in ABAP for Cloud Development
- "(Not) released APIs
- "Released API: Getting a random integer
+ "Released DDIC data elements
+ DATA dobj1 TYPE timestampl.
+ DATA dobj2 TYPE land1.
+
+ "Attributes of the accessible type pool ABAP
+ DATA flag TYPE abap_boolean.
+ flag = abap_true.
+
+ "Released table types
+ DATA it1 TYPE string_table.
+ DATA it2 TYPE string_hashed_table.
+ DATA it3 TYPE xstring_table.
+
+ "Released CDS object
+ DATA s1 TYPE i_timezone.
+
+ "Released interface
+ "The if_oo_adt_classrun interface is released, and you can implement it to run an ABAP class.
+ "In ADT, you can do this by choosing F9. To output the content of data objects, you can use
+ "out->write( ... ). in the main method.
+ DATA ref_classrun TYPE REF TO if_oo_adt_classrun.
+
+ "Not released DDIC database table
+ DATA s2 TYPE scarr.
+
+ "Classes
+ "(Not) Released classes
+ DATA(ixml1) = cl_ixml_core=>create( ).
+ "Not released (API for classic ABAP)
+ DATA(ixml2) = cl_ixml=>create( ).
+
+ "Getting a random integer
DATA(random_num) = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
- min = 1
- max = 100 )->get_next( ).
+ min = 1
+ max = 100 )->get_next( ).
"Released APIs from the XCO library
"Retrieving the current user date
- DATA(user_date) = xco_cp=>sy->date( xco_cp_time=>time_zone->user
- )->as( xco_cp_time=>format->iso_8601_extended
- )->value.
+ DATA(user_date) = xco_cp=>sy->date( xco_cp_time=>time_zone->user
+ )->as( xco_cp_time=>format->iso_8601_extended
+ )->value.
+
"Retrieving the current user time
DATA(user_time) = xco_cp=>sy->time( xco_cp_time=>time_zone->user
- )->as( xco_cp_time=>format->iso_8601_extended
- )->value.
+ )->as( xco_cp_time=>format->iso_8601_extended
+ )->value.
"Not released API: Querying whether the current database supports AMDP methods
DATA(amdp_allowed) = xsdbool( cl_abap_dbfeatures=>use_features(
EXPORTING requested_features = VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ) ).
- "Examples for deprecated and invalid syntax in ABAP for Cloud Development
+ "ABAP SQL statements
+ "Selecting from a
+ "... not released database table
+ SELECT carrid, connid FROM spfli WHERE carrid = 'LH' INTO TABLE @DATA(spfli_tab).
+
+ "... released CDS view
+ SELECT SINGLE * FROM i_timezone WHERE TimeZoneID = 'EST' INTO @DATA(tz_info).
+
+ "... not released database table using a dynamic ABAP SQL statement
+ "Although the source code provides an invalid data source, the dynamic ABAP SQL statement
+ "does not produce a syntax error during compilation. However, it would result in a runtime
+ "error because you cannot select from that data source. You can check the validity of dynamic
+ "specifications using the `cl_abap_dyn_prg` class, which supports dynamic programming.
+ SELECT SINGLE carrid, connid FROM ('SPFLI') WHERE carrid = 'LH' INTO NEW @DATA(ref_spfli_tab).
+
+ "ABAP SQL Statement involving client handling; using a cheat sheet database table
+ "The addition `USING CLIENT` for client handling is not allowed in the restricted ABAP language scope.
+ DATA(clnt) = sy-mandt.
+ SELECT carrid, connid FROM ('ZDEMO_ABAP_FLI') USING CLIENT @clnt WHERE carrid = 'LH' INTO TABLE NEW @DATA(ref_demo_tab).
+
+ "The example includes a selection of deprecated and invalid syntax in ABAP for Cloud Development. They are added
+ "for demonstration purposes. For example, classic UI technology-related (such as dynpro) syntax is not allowed.
+ "The pointless WRITE statement within the method implementation represents invalid classic list-related statements.
+ "Executable programs (reports) are not allowed in the restricted ABAP language scope. To set breakpoints in ADT,
+ "double-click the area to the left of the code line number.
+
+ "Assignments
DATA(num1) = 1.
DATA(num2) = 1.
DATA(num3) = 2.
@@ -120,26 +160,37 @@ It provides references to more detailed information on the topic.
"Using the assignment operator
num2 = num3.
- DATA(it4) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ).
- "Invalid statement for determining the number of lines in an internal table
- DESCRIBE TABLE it4 LINES DATA(num_lines1).
- DATA(num_lines2) = lines( it4 ).
+ "Determining the number of lines in an internal table
+ DATA(str_table) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ).
+ DATA(num_lines1) = lines( str_table ).
+ "Invalid statement
+ DESCRIBE TABLE str_table LINES DATA(num_lines2).
+ "Getting references
DATA: ref1 TYPE REF TO i,
ref2 TYPE REF TO i.
- "Deprecated statement for references
- GET REFERENCE OF num1 INTO ref1.
- "Using the REF operator instead
- ref2 = REF #( num1 ).
+ ref1 = REF #( num1 ).
+ "Deprecated statement
+ GET REFERENCE OF num1 INTO ref2.
+ "Classic ABAP-related statements and syntax
"Various sy components should not be used in ABAP for Cloud Development
- DATA(current_time) = sy-uzeit.
- DATA(current_date) = sy-datum.
+ DATA(current_as_abap_time) = sy-uzeit.
+ DATA(current_as_abap_date) = sy-datum.
+ DATA(current_local_time) = sy-timlo.
- DATA str_itab TYPE string_table.
- "Various invalid statements
- READ REPORT 'ZCL_DEMO_ABAP_UNIT_TEST=======CCAU' INTO str_itab.
+ "Various invalid statements
+ DATA scarr_tab TYPE TABLE OF scarr WITH EMPTY KEY.
+ TRY.
+ cl_salv_table=>factory( IMPORTING r_salv_table = DATA(alv)
+ CHANGING t_table = scarr_tab ).
+ "The exception class is not released, too.
+ CATCH cx_salv_msg.
+ ENDTRY.
+
+ DATA code TYPE string_table.
+ READ REPORT 'ZCL_DEMO_ABAP_UNIT_TEST=======CCAU' INTO code.
WRITE 'hi'.
BREAK-POINT.
ENDMETHOD.
@@ -156,7 +207,7 @@ It provides references to more detailed information on the topic.
For the example class created, check the information in the *Properties* tab. Choose *General*. The *ABAP Language Version* is maintained as *Standard ABAP*:

- If you have not imported the ABAP cheat sheet GitHub repository, remove the lines of code using artifacts from that repository, i.e. remove the statements using objects starting with `Z...`. You should not see any syntax errors. Activate the class.
- - Run the class with *F9*. The code should have been processed up to the `BREAK-POINT` statement and the debugger should have started. You may want to check the content of the variables in the debugger. Choose *Terminate* to exit the debugger.
+ - Run the class with *F9*. The code should have been processed up to the `BREAK-POINT` statement and the debugger should have started. Choose *Terminate* to exit the debugger.
- So, unlike in the case of ABAP for Cloud Development above, you should be able to activate and run the code (which does not represent a meaningful code example).
c) Verifying cloud-readiness of your code in classic ABAP
diff --git a/22_Misc_ABAP_Classes.md b/22_Misc_ABAP_Classes.md
index 7d36b7a..983af85 100644
--- a/22_Misc_ABAP_Classes.md
+++ b/22_Misc_ABAP_Classes.md
@@ -3288,8 +3288,6 @@ cl_abap_unit_assert=>assert_equals(
exp = 100
msg = `The value does not match the expected result`
quit = if_abap_unit_constant=>quit-no ).
-
-ENDDO.
```
|
diff --git a/25_Authorization_Checks.md b/25_Authorization_Checks.md
index 5882f9e..b02f738 100644
--- a/25_Authorization_Checks.md
+++ b/25_Authorization_Checks.md
@@ -441,7 +441,7 @@ CLASS zcl_demo_abap_auth IMPLEMENTATION.
IF flag = abap_true.
out->write( `Something went wrong with the example procedure. There should only be entries with the condition countryfr = 'US'.` ).
ELSE.
- out->write( `Excepted result. There are only entries with the condition countryfr = 'US' in the internal table.` ).
+ out->write( `Expected result. There are only entries with the condition countryfr = 'US' in the internal table.` ).
ENDIF.
out->write( |\n| ).
@@ -451,7 +451,7 @@ CLASS zcl_demo_abap_auth IMPLEMENTATION.
out->write( `SELECT statements that specify WHERE clauses:` ).
IF itab3 IS NOT INITIAL AND itab4 IS INITIAL.
- out->write( `Excepted result. Only entries with the condition countryfr = 'US' should be accessible.` ).
+ out->write( `Expected result. Only entries with the condition countryfr = 'US' should be accessible.` ).
ELSE.
out->write( `Something went wrong with the example procedure. There should only be entries with the condition countryfr = 'US'.` ).
ENDIF.