From e2655e8ddf199a879136d929821fd520fdc9a960 Mon Sep 17 00:00:00 2001
From: danrega <16720986+danrega@users.noreply.github.com>
Date: Fri, 24 May 2024 20:37:58 +0200
Subject: [PATCH] Update
---
01_Internal_Tables.md | 22 ++---
04_ABAP_Object_Orientation.md | 173 ++++++++++++++++++++++++++++++++++
22_Misc_ABAP_Classes.md | 2 +-
3 files changed, 185 insertions(+), 12 deletions(-)
diff --git a/01_Internal_Tables.md b/01_Internal_Tables.md
index 6b88307..9455fa7 100644
--- a/01_Internal_Tables.md
+++ b/01_Internal_Tables.md
@@ -10,10 +10,10 @@
- [Populating Internal Tables](#populating-internal-tables)
- [Copying Internal Tables](#copying-internal-tables)
- [Using INSERT and APPEND Statements to Populate Internal Tables](#using-insert-and-append-statements-to-populate-internal-tables)
- - [Creating and Filling Internal Tables Using Constructor Expressions](#creating-and-filling-internal-tables-using-constructor-expressions)
+ - [Creating and Populating Internal Tables Using Constructor Expressions](#creating-and-populating-internal-tables-using-constructor-expressions)
- [VALUE operator](#value-operator)
- [CORRESPONDING operator](#corresponding-operator)
- - [FILTER Operator\*\*](#filter-operator)
+ - [FILTER Operator](#filter-operator)
- [NEW Operator](#new-operator)
- [Reading Single Lines from Internal Tables](#reading-single-lines-from-internal-tables)
- [Determining the Target Area when Reading Single Lines](#determining-the-target-area-when-reading-single-lines)
@@ -80,7 +80,7 @@ Internal Tables ...
| Category | Internally managed by | Access | Primary table key | When to use | Hints |
|---|---|---|---|---|---|
-|`STANDARD`|Primary table index (that's why these tables are called [index tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenindex_table_glosry.htm))|
|- Always non-unique, i.e. duplicate entries are always allowed
- Definition of an empty key is possible if the key is not relevant(`WITH EMPTY KEY`)
|- If you primarily access the table content for sequential processing or via the table index.
- Response time for accessing the table using the primary key: This kind of table access is optimized only for sorted and hashed tables. For standard tables, primary key access uses a linear search across all lines. That means that large standard tables (more than 100 lines) are not ideal if the you primarily access the table using the table key.>
|- There is no particular sort order, but the tables can be sorted using `SORT`.
- Filling this kind of table: Lines are either appended at the end of the table or inserted at a specific position.
- [Secondary table keys](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensecondary_table_key_glosry.htm) can be defined to make key access to standard tables more efficient.
- Standard and sorted tables have the least [administration costs (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenadmin_costs_dyn_mem_obj_guidl.htm).
|
+|`STANDARD`|Primary table index (that's why these tables are called [index tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenindex_table_glosry.htm))||- Always non-unique, i.e. duplicate entries are always allowed
- Definition of an empty key is possible if the key is not relevant(`WITH EMPTY KEY`)
|- If you primarily access the table content for sequential processing or via the table index.
- Response time for accessing the table using the primary key: This kind of table access is optimized only for sorted and hashed tables. For standard tables, primary key access uses a linear search across all lines. That means that large standard tables (more than 100 lines) are not ideal if the you primarily access the table using the table key.>
|- There is no particular sort order, but the tables can be sorted using `SORT`.
- Populating this kind of table: Lines are either appended at the end of the table or inserted at a specific position.
- [Secondary table keys](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensecondary_table_key_glosry.htm) can be defined to make key access to standard tables more efficient.
- Standard and sorted tables have the least [administration costs (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenadmin_costs_dyn_mem_obj_guidl.htm).
|
|`SORTED`|Primary table index (that's why these tables are called [index tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenindex_table_glosry.htm))||- Non-unique
- Unique
... used to sort the table in ascending order.
|- Enables an optimized access to table content using table key and index.
- If access via table key is the main access method, but no unique key can be defined.
|- Sorting is done automatically when lines are inserted or deleted. As a consequence, the table index must usually be reorganized.
- The response time for accessing the table using the primary key depends logarithmically on the number of table entries, since a binary search is used.
- Standard and sorted tables have the least administration costs.
|
|`HASHED`|Hash algorithm |- Table key
- [Secondary table index](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensecondary_table_index_glosry.htm)
|Always unique|- For large internal tables.
- Optimized for key access. Access to table content via table key is the main access method and a unique key can be defined.
|- The response time for primary key access is constant and independent of the number of entries in the table.
- Hashed tables have the highest administration costs.
|
@@ -166,7 +166,7 @@ Internal Tables ...
- When accessing internal tables using the secondary table key, the key name (or the alias if specified) must be specified. They are not selected automatically. If no secondary key is specified in a processing statement, the primary key or primary table index is always used. If you want to make use of this key in ABAP statements, for example, `READ`, `LOOP AT` or `MODIFY` statements, you must specify the key explicitly using the appropriate additions, for example, `WITH ... KEY ... COMPONENTS` or `USING KEY`.
- Use cases:
- To improve read performance.
- - For very large internal tables (that are filled once and changed very often)
+ - For very large internal tables (that are populated once and changed very often)
- Standard tables, whose primary table keys cannot be unique, can be provided with a means of ensuring that unique table entries are read.
- Note that defining secondary table keys involves additional administration costs (additional memory consumption). Therefore, the use of secondary table keys should be reserved for cases where the benefits outweigh the extra costs.
- For more details, see the programming guidelines for secondary keys: [Secondary
@@ -542,7 +542,7 @@ INSERT LINES OF itab2 INTO itab INDEX i.
⬆️ back to top
-### Creating and Filling Internal Tables Using Constructor Expressions
+### Creating and Populating Internal Tables Using Constructor Expressions
The constructor expressions can be specified in/with various positions/statements in ABAP. In most of the following snippets, simple assignments are demonstrated.
#### VALUE operator
@@ -668,7 +668,7 @@ MOVE-CORRESPONDING itab_nested1 TO itab_nested2 EXPANDING NESTED TABLES.
MOVE-CORRESPONDING itab_nested1 TO itab_nested2 EXPANDING NESTED TABLES KEEPING TARGET LINES.
```
-#### FILTER Operator**
+#### FILTER Operator
To create an internal table by copying data from another internal table and
filtering out lines that do not meet the `WHERE` condition, you can use the [`FILTER`
@@ -1130,7 +1130,7 @@ LOOP AT it INTO wa WHERE a > 1 AND b < 4.
...
ENDLOOP.
-"No interest in the table content; only relevant system fields are filled
+"No interest in the table content; only relevant system fields are populated
"Mandatory WHERE clause
LOOP AT it TRANSPORTING NO FIELDS WHERE a < 5.
@@ -1239,11 +1239,11 @@ SELECT db1~comp1, db1~comp2, db2~comp_abc, db2~comp_xyz ...
INTO TABLE @DATA(it_join_result).
```
-Filling an internal table from a database table using
+Populating an internal table from a database table using
[subqueries](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensubquery_glosry.htm "Glossary Entry").
-The following two examples fill an internal table from a database table. In the first example, a subquery is specified in the
+The following two examples populate an internal table from a database table. In the first example, a subquery is specified in the
`WHERE` clause with the `NOT IN` addition. It checks whether a value matches a value in a set of values
-specified in parentheses. The second example fills an internal table depending on data in another table. A subquery with the `EXISTS` addition is specified in
+specified in parentheses. The second example populates an internal table depending on data in another table. A subquery with the `EXISTS` addition is specified in
the `WHERE` clause. In this
case, the result of the subquery, which is another
`SELECT` statement, is checked to see if an entry exists in
@@ -1599,7 +1599,7 @@ statements allow you to delete the entire table content.
The difference between the two is in the handling of the memory space originally allocated to the table. When a table is cleared with `CLEAR`,
the content is removed, but the memory space initially requested remains
-allocated. If the table is filled again later, the memory space is still
+allocated. If the table is populated again later, the memory space is still
available, which is a performance advantage over
clearing an internal table with `FREE`. Such a statement also
deletes the table content, but it also releases the memory
diff --git a/04_ABAP_Object_Orientation.md b/04_ABAP_Object_Orientation.md
index 6cfad41..687d7b0 100644
--- a/04_ABAP_Object_Orientation.md
+++ b/04_ABAP_Object_Orientation.md
@@ -7,6 +7,7 @@
- [Creating Classes](#creating-classes)
- [Creating a Local Class](#creating-a-local-class)
- [Creating a Global Class](#creating-a-global-class)
+ - [Excursion: Class Pool and Include Programs](#excursion-class-pool-and-include-programs)
- [Visibility of Components](#visibility-of-components)
- [Creating the Visibility Sections](#creating-the-visibility-sections)
- [Defining Components](#defining-components)
@@ -154,6 +155,178 @@ of the class itself, and of its
be instantiated in methods of the class itself or of its friends. Hence,
it cannot be instantiated as an inherited component of subclasses.
+⬆️ back to top
+
+#### Excursion: Class Pool and Include Programs
+
+- A class pool is an ABAP program containing the definition of one global class (*Global Class* tab in ADT)
+- Global classes are marked as such with the `PUBLIC` addition to the `CLASS` statement: `CLASS zcl_demo_test DEFINITION PUBLIC ...`
+- Additionally, a class pool can also contain local classes that are defined in dedicated include programs (CCDEF and the other include names are internal names the include programs end with):
+ - CCDEF include (*Class-relevant Local Types* tab in ADT): Is included in front of the declaration part of the global class
+ - CCIMP include (*Local Types* tab in ADT): Is included behind the declaration part and in front of the implementation part of the global class
+ - CCAU include (*Test classes* tab in ADT): Test include; contains ABAP Unit test classes
+
+The following simplified example demonstrates include programs.
+
+
+ Expand to view the details
+
+
+ Global class:
+- Create a new global class (the example uses the name `zcl_demo_test`) and copy and paste the following code in the *Global Class* tab in ADT.
+- The method in the private section makes use of local types that are defined in the CCDEF include. In the example the method is deliberately included in the private visibility section. Having it like this in the public section is not possible due to the use of local types.
+- The `if_oo_adt_classrun~main` implementation contains method calls to this method. It also contains method calls to a method implemented in a local class in the CCIMP include.
+- As a prerequisite to activate the class, you also need to copy and paste the code snippets further down for the CCDEF and CCIMP include. Once you have pasted the code, the syntax errors in the global class will disappear.
+- You can run the class using F9. Some output is displayed.
+- When you have copied and pasted the CCAU code snippet for the simple ABAP Unit test, and activated the class, you can choose *CTRL+Shift+F10* in ADT to run the ABAP Unit test. Alternatively, you can make a right click in the class code, choose *Run As* and *4 ABAP Unit Test*.
+
+```abap
+CLASS zcl_demo_test DEFINITION
+ PUBLIC
+ FINAL
+ CREATE PUBLIC .
+
+ PUBLIC SECTION.
+ INTERFACES if_oo_adt_classrun.
+
+ PROTECTED SECTION.
+ PRIVATE SECTION.
+ "This methods uses types (data type c1 and the local exception class)
+ "defined in the CCDEF include
+ METHODS calculate IMPORTING num1 TYPE i
+ operator TYPE c1
+ num2 TYPE i
+ RETURNING VALUE(result) TYPE i
+ RAISING lcx_wrong_operator.
+ENDCLASS.
+
+CLASS zcl_demo_test IMPLEMENTATION.
+
+ METHOD if_oo_adt_classrun~main.
+
+ "---- The method called uses type declarations in the CCDEF include ----
+ TRY.
+ DATA(result1) = calculate( num1 = 10 operator = '+' num2 = 4 ).
+ out->write( data = result1 name = `result1` ).
+ CATCH lcx_wrong_operator.
+ out->write( `Operator not allowed` ).
+ ENDTRY.
+
+ TRY.
+ DATA(result2) = calculate( num1 = 10 operator = '-' num2 = 4 ).
+ out->write( data = result2 name = `result2` ).
+ CATCH lcx_wrong_operator.
+ out->write( `Operator not allowed` ).
+ ENDTRY.
+
+ TRY.
+ DATA(result3) = calculate( num1 = 10 operator = '*' num2 = 4 ).
+ out->write( data = result3 name = `result3` ).
+ CATCH lcx_wrong_operator.
+ out->write( `Operator not allowed` ).
+ ENDTRY.
+
+ "---- Using local class implemented in the CCIMP include ----
+ DATA(hi1) = lcl_demo=>say_hello( ).
+ out->write( data = hi1 name = `hi1` ).
+ DATA(hi2) = lcl_demo=>say_hello( xco_cp=>sy->user( )->name ).
+ out->write( data = hi2 name = `hi2` ).
+
+ "--------------- Test include (CCAU) ---------------
+ "For running the ABAP Unit test, choose CTRL+Shift+F10 in ADT.
+ "Or you can make a right click in the class code, choose
+ "'Run As' and '4 ABAP Unit Test'.
+ ENDMETHOD.
+
+ METHOD calculate.
+ result = SWITCH #( operator
+ WHEN '+' THEN num1 + num2
+ WHEN '-' THEN num1 - num2
+ ELSE THROW lcx_wrong_operator( ) ).
+ ENDMETHOD.
+
+ENDCLASS.
+```
+Code snippet for the CCDEF include:
+```abap
+CLASS lcx_wrong_operator DEFINITION INHERITING FROM cx_static_check.
+ENDCLASS.
+
+TYPES c1 type c length 1.
+```
+
+Code snippet for the CCIMP include:
+```abap
+CLASS lcl_demo DEFINITION.
+ PUBLIC SECTION.
+ CLASS-METHODS: say_hello IMPORTING name TYPE string optional
+ RETURNING VALUE(hi) type string.
+
+ENDCLASS.
+
+CLASS lcl_demo IMPLEMENTATION.
+
+ METHOD say_hello.
+ hi = |Hallo{ COND #( when name is supplied then ` ` && name ) }!|.
+ ENDMETHOD.
+
+ENDCLASS.
+```
+
+Code snippet for the test include (CCAU):
+```abap
+CLASS ltc_test DEFINITION DEFERRED.
+CLASS zcl_demo_test DEFINITION LOCAL FRIENDS ltc_test.
+
+CLASS ltc_test DEFINITION FOR TESTING
+RISK LEVEL HARMLESS
+DURATION SHORT.
+
+ PRIVATE SECTION.
+ METHODS test_calculate FOR TESTING.
+
+ENDCLASS.
+
+CLASS ltc_test IMPLEMENTATION.
+
+ METHOD test_calculate.
+ "Creating an object of class under test
+ DATA(ref_cut) = NEW zcl_demo_test( ).
+
+ "Calling method that is to be tested
+ TRY.
+ DATA(result1) = ref_cut->calculate( num1 = 10 operator = '+' num2 = 4 ).
+ CATCH lcx_wrong_operator.
+ ENDTRY.
+
+ TRY.
+ DATA(result2) = ref_cut->calculate( num1 = 10 operator = '-' num2 = 4 ).
+ CATCH lcx_wrong_operator.
+ ENDTRY.
+
+ "Assertions
+ cl_abap_unit_assert=>assert_equals(
+ act = result1
+ exp = 14
+ quit = if_abap_unit_constant=>quit-no ).
+
+ cl_abap_unit_assert=>assert_equals(
+ act = result2
+ exp = 6
+ quit = if_abap_unit_constant=>quit-no ).
+ ENDMETHOD.
+
+ENDCLASS.
+```
+
+
+
+
+
+
+
+
+
⬆️ back to top
### Visibility of Components
diff --git a/22_Misc_ABAP_Classes.md b/22_Misc_ABAP_Classes.md
index 8fc0f9b..19aa376 100644
--- a/22_Misc_ABAP_Classes.md
+++ b/22_Misc_ABAP_Classes.md
@@ -2439,7 +2439,7 @@ ENDCLASS.
XCO_CP_GENERATION |
-For creating, updating and deleting ABAP repository objects. More information: [Generation APIs](https://help.sap.com/docs/btp/sap-business-technology-platform/generation-apis) The rudimentary snippet is taken from the executable example of the ABAP for Cloud Development cheat sheet.
+For creating, updating and deleting ABAP repository objects. More information: Generation APIs The rudimentary snippet is taken from the executable example of the ABAP for Cloud Development cheat sheet.
|