This commit is contained in:
danrega
2023-08-25 15:16:35 +02:00
parent 8f8a3a6a10
commit ebbd9675a2
18 changed files with 1241 additions and 163 deletions

View File

@@ -5,7 +5,7 @@
- [Internal Tables](#internal-tables)
- [Introduction](#introduction)
- [Basic Properties of Internal Tables](#basic-properties-of-internal-tables)
- [Excursion: Table Keys in Internal Tables (Primary, Secondary, Standard, Empty)](#excursion-table-keys-in-internal-tables-primary-secondary-standard-empty)
- [Table Keys in Internal Tables (Primary, Secondary, Standard, Empty)](#table-keys-in-internal-tables-primary-secondary-standard-empty)
- [Creating Internal Tables and Types](#creating-internal-tables-and-types)
- [Filling and Copying Internal Tables](#filling-and-copying-internal-tables)
- [Excursions with Internal Tables](#excursions-with-internal-tables)
@@ -31,7 +31,7 @@ Internal Tables ...
- are used when a variable data set of a random data type needs to be processed in a structured way.
- allow access to individual table lines via a [table index](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentable_index_glosry.htm) or a [table key](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentable_key_glosry.htm).
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Basic Properties of Internal Tables
@@ -83,9 +83,9 @@ Internal Tables ...
- [Programming guidelines: Internal Tables (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)
</details>
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Excursion: Table Keys in Internal Tables (Primary, Secondary, Standard, Empty)
## Table Keys in Internal Tables (Primary, Secondary, Standard, Empty)
<details>
<summary>Expand to view the details</summary>
@@ -94,7 +94,7 @@ Internal Tables ...
**Primary table key**
- Each internal table has a primary table key.
- Can be either self-defined key or the [standard key](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_key_glosry.htm).
- Can be either a self-defined key or the [standard key](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_key_glosry.htm).
- The primary table key is ...
- sorted for sorted tables.
- hashed for hashed tables.
@@ -153,7 +153,7 @@ Internal Tables ...
</details>
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Creating Internal Tables and Types
@@ -175,7 +175,7 @@ DATA itab4 LIKE itab1 ... "Based on an existing in
> **💡 Note**<br>
> If the table category is not specified (`... TYPE TABLE OF ...`), it is automatically `... TYPE STANDARD TABLE OF ...`.
The following code snippet contains various internal table declarations. It is intended to demonstrate a selection of the rich variety of possible internal tables mentioned in the previous sections, e.g. in *Excursion: Table Keys in Internal Tables*.
The following code snippet contains various internal table declarations. It is intended to demonstrate a selection of the rich variety of possible internal tables mentioned in the previous sections, e.g. in *Table Keys in Internal Tables*.
In the examples, the internal tables are created using the structured type of a demo database table in the DDIC. The line type of the database table is automatically used when defining an internal table.
@@ -397,7 +397,7 @@ SELECT * FROM zdemo_abap_fli INTO TABLE @it_sel.
SELECT * FROM zdemo_abap_fli INTO TABLE @FINAL(it_inline5).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Filling and Copying Internal Tables
@@ -492,7 +492,7 @@ INSERT lv_struc INTO itab2 INDEX i.
INSERT LINES OF itab2 INTO itab INDEX i.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
**Adding lines using constructor expressions**
@@ -614,7 +614,7 @@ MOVE-CORRESPONDING itab_nested1 TO itab_nested2 EXPANDING NESTED TABLES.
MOVE-CORRESPONDING itab_nested1 TO itab_nested2 EXPANDING NESTED TABLES KEEPING TARGET LINES.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Excursions with Internal Tables
For more details on ABAP SQL, see the cheat sheet on [ABAP SQL](03_ABAP_SQL.md).
@@ -801,7 +801,7 @@ tables with a unique primary key, especially hashed tables.
COLLECT VALUE dtype( comp1 = a comp2 = b ... ) INTO itab.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Reading from Internal Tables
@@ -869,7 +869,7 @@ at a performance cost. Imagine that your table contains many columns or
nested components. In this case, it is better not to copy at all (although you can use
the `TRANSPORTING` addition to restrict the fields to be copied).
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
*Reading a single line by index*
@@ -922,7 +922,7 @@ DATA(line1) = VALUE #( itab[ 6 ] OPTIONAL ).
DATA(line2) = VALUE #( itab[ 7 ] DEFAULT itab[ 8 ] ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
*Reading single lines using table keys*
@@ -984,7 +984,7 @@ READ TABLE it FROM sec_keys USING KEY sec_key INTO wa.
READ TABLE it FROM sec_keys USING KEY sk INTO wa.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
**Reading a single line using a free key**
@@ -1017,7 +1017,7 @@ DATA(comp4) = dref->c.
"Note: The syntax dref->*-c is also possible.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
**Checking the existence and the index of a line in an internal table**
@@ -1077,7 +1077,7 @@ DATA(idx) = line_index( it[ b = 2 ] ).
DATA(number_of_lines) = lines( it ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Processing Multiple Internal Table Lines Sequentially
@@ -1205,7 +1205,7 @@ DATA(tab2) = VALUE ttype( FOR ls IN it WHERE ( a < 7 )
( a = ls-a b = ls-b + 5 ) ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Sorting Internal Tables
@@ -1272,11 +1272,11 @@ SORT itab BY a b ASCENDING c DESCENDING.
SORT itab BY table_line.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Modifying Internal Table Content
As mentioned above, you can modify the content of internal table lines directly in `READ TABLE` and `LOOP AT` statements using field symbols and data reference variables. You can also use table expressions for direct modification. Note that the key fields of the primary table key of sorted and hashed tables are always read-only. If you try to modify a key field, a runtime error occurs. However, this is not checked until runtime.
As mentioned above, you can modify the content of internal table lines directly in the context of `READ TABLE` and `LOOP AT` statements using field symbols and data reference variables. You can also use table expressions for direct modification. Note that the key fields of the primary table key of sorted and hashed tables are always read-only. If you try to modify a key field, a runtime error occurs. However, this is not checked until runtime.
The following examples demonstrate direct modification of recently read table lines:
``` abap
@@ -1373,7 +1373,7 @@ MODIFY it FROM line TRANSPORTING b c WHERE a < 5.
> **💡 Note**<br>
> The system field `sy-subrc` is set to `0` if at least one line was changed. It is set to `4` if no lines were changed.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Deleting Internal Table Content
@@ -1471,7 +1471,7 @@ FREE it.
"Assignment using the VALUE operator without entries in the parentheses
it = VALUE #( ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## More Information
Topic [Internal

View File

@@ -1,3 +1,5 @@
<a name="top"></a>
# Structures
- [Structures](#structures)
@@ -27,6 +29,8 @@ Structures ...
- 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.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## 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.
@@ -198,6 +202,8 @@ LOOP AT itab INTO DATA(wa_2).
ENDLOOP.
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Variants of Structures
Depending on the component type, the structure can be a [flat structure](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenflat_structure_glosry.htm "Glossary Entry"),
@@ -257,6 +263,8 @@ that is, it refers to another structure. The following example has multiple subs
>- [Work areas](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenwork_area_glosry.htm) of ABAP SQL statements cannot contain any deep components other than strings among others.
>- Especially for assignments and comparisons of deep structures, the compatibility of the source and target structure must be taken into account.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Accessing (Components of) Structures
- Structures can be accessed as a whole. You can also address the individual components of structures at the appropriate operand positions.
@@ -310,6 +318,8 @@ Nested components can be addressed using chaining:
> **💡 Note**<br>
> The [`ASSIGN`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapassign_dynamic_components.htm) statement has special variants for dynamically accessing structure components.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Populating Structures
You can copy the content of a structure to another using the [assignment operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenassignment_operator_glosry.htm) `=`.
@@ -340,6 +350,8 @@ address-street = `Vegetable Lane 11`.
address-city   = `349875 Botanica`.
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Using the VALUE Operator
- The [`VALUE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_value.htm) operator can be used to construct the content of complex data objects such as structures or internal tables.
@@ -392,6 +404,8 @@ DATA(str_ref) = NEW struc_nested( a = 1
nested_2 = VALUE #( d = 4 e = 5 ) ).
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Using the CORRESPONDING Operator and MOVE-CORRESPONDING Statements
- You can use statements with [`MOVE-CORRESPONDING`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmove-corresponding.htm)
@@ -498,6 +512,8 @@ diff_deep_struc = CORRESPONDING #( APPENDING BASE ( diff_struc ) deep_struc ).
diff_deep_struc = CORRESPONDING #( DEEP APPENDING BASE ( diff_struc ) deep_struc ).
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
                                  
## Clearing Structures
You can reset individual components to their initial values and clear the
@@ -511,6 +527,8 @@ CLEAR struc.
struc = VALUE #( ).
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Processing Structures
Structures are primarily used to process data from tables. In this context, structures often take on the role of a [work area](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenwork_area_glosry.htm "Glossary Entry").
The following code snippets cover only a selection. For more examples, see the cheat sheets about internal tables and ABAP SQL.
@@ -640,6 +658,8 @@ APPEND struc TO itab.
MODIFY TABLE itab FROM struc.
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Excursion: Including Structures
- Although their use is not recommended in the ABAP programming
@@ -681,6 +701,8 @@ TYPES BEGIN OF address_type.
TYPES END OF address_type.
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Executable Example
[zcl_demo_abap_structures](./src/zcl_demo_abap_structures.clas.abap)

View File

@@ -126,7 +126,7 @@ Views](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm
systems (that support the ABAP CDS characteristics).
</details>
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Reading Data Using SELECT
@@ -175,7 +175,7 @@ SELECT FROM source "What database table or view to read from
processing the internal table entries. Find more information in the
ABAP cheat sheet [Internal Tables](01_Internal_Tables.md). In newer ABAP releases, the declaration operator [`FINAL`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfinal_inline.htm) can be used to declare immutable variables.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Using SELECT for Multiple Purposes
@@ -260,7 +260,7 @@ SELECT FROM dbtab
ENDSELECT.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Clause Variations and Additions in SELECT Statements
@@ -454,7 +454,7 @@ SELECT FROM dbtab
INTO TABLE NEW @DATA(dref).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### More Clauses
@@ -531,7 +531,7 @@ SELECT FROM dbtab
INTO ...
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Operands and Expressions in ABAP SQL Statements
@@ -1303,7 +1303,7 @@ SELECT *
INTO TABLE @DATA(result).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Changing Data in Database Tables
@@ -1351,7 +1351,7 @@ INSERT dbtab FROM TABLE @itab ACCEPTING DUPLICATE KEYS.
INSERT dbtab FROM ( SELECT ... ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Using [`UPDATE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapupdate.htm)
- Changes the content of one or more rows of a database table specified.
@@ -1403,7 +1403,7 @@ UPDATE dbtab FROM TABLE @ind_tab INDICATORS NOT SET STRUCTURE comp_ind.
UPDATE dbtab SET comp2 = ... .
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Using [`MODIFY`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmodify_dbtab.htm)
- Inserts one or more rows into a database table specified or overwrites existing ones.
@@ -1432,7 +1432,7 @@ MODIFY dbtab FROM TABLE @( VALUE #( ( comp1 = ... comp2 = ... )
MODIFY dbtab FROM ( SELECT ... ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Using [`DELETE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdelete_dbtab.htm)
- Deletes one or more rows from a database table specified.
@@ -1466,7 +1466,7 @@ DELETE dbtab FROM TABLE @( VALUE #( ( comp1 = ... )
                                    ( comp1 = ... ) ) ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## More Information
- Note that ABAP SQL statements offer syntax options for dynamic programming. For example, you can specify the data source to read from dynamically. See more information in the ABAP Keyword Documentation or the [ABAP cheat sheet on dynamic programming](06_Dynamic_Programming.md).

View File

@@ -64,7 +64,7 @@ Classes ...
that determine the behavior of an object
- [Events](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenevent_glosry.htm "Glossary Entry") to trigger the processing of ABAP code
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Creating Classes
@@ -145,7 +145,7 @@ 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.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Visibility of Components
@@ -193,7 +193,7 @@ CLASS local_class DEFINITION.
ENDCLASS.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Defining Components
@@ -278,7 +278,7 @@ CLASS local_class IMPLEMENTATION.
ENDCLASS.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
**Methods**
@@ -357,7 +357,7 @@ In the simplest form, methods can have no parameter at all. Apart from that, met
However, when using this addition, as the name implies, a default
value is set.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
**Constructors**
@@ -436,7 +436,7 @@ CLASS local_class IMPLEMENTATION.
ENDCLASS.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Working with Objects and Components
@@ -692,7 +692,7 @@ METHOD me_ref.
ENDMETHOD.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Notes on Inheritance
@@ -714,7 +714,7 @@ ENDMETHOD.
[`FINAL`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmethods_abstract_final.htm#!ABAP_ADDITION_2@2@)
(e. g. `CLASS global_class DEFINITION PUBLIC FINAL CREATE PUBLIC. ...`).
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
**Excursion: Additions `ABSTRACT` and `FINAL`**
- Both classes and methods can be defined with the additions `ABSTRACT` and `FINAL`.
@@ -746,7 +746,7 @@ CLASS cls2 IMPLEMENTATION.
ENDCLASS.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
**Redefining Methods**
@@ -769,7 +769,7 @@ ENDCLASS.
> - Regarding the static constructor: When calling a subclass for the first time, the preceding static constructors of all of the entire inheritance tree must have been called first.
> - More information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninheritance_constructors.htm).
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Notes on Polymorphism and Casting
@@ -885,7 +885,7 @@ DATA(rtti_d) = CAST cl_abap_structdescr(
)->components.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Notes on Interfaces
@@ -911,7 +911,7 @@ Interfaces ...
`CLASS-METHODS`, are possible. Constructors are not
possible.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
Defining interfaces:
- Can be done either globally in the repository or locally in an ABAP program.
@@ -1063,7 +1063,7 @@ i_ref = NEW class( ).
... intf=>const ...
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Additional Notes
@@ -1095,7 +1095,7 @@ CLASS lo_class DEFINITION CREATE PRIVATE FRIENDS other_class ... .
CLASS global_class DEFINITION CREATE PUBLIC FRIENDS other_global_class ... .
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Events
@@ -1151,7 +1151,7 @@ SET HANDLER handler3.
"Note that multiple handler methods can be specified.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Excursion: Factory Methods and Singletons as Design Patterns
@@ -1217,7 +1217,7 @@ DATA obj_factory TYPE REF TO class.
obj_factory = class=>factory_method( par = ... ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## More Information
You can check the subtopics of

View File

@@ -70,7 +70,7 @@ implies that the data object is initialized. However, for some
constructor operators, there is an addition with which the
initialization can be avoided.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## VALUE
@@ -273,7 +273,7 @@ also valid for other constructor expressions further down but not
necessarily mentioned explicitly. See the details on the syntactical
options of the constructor operators in the ABAP Keyword Documentation.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## CORRESPONDING
@@ -352,7 +352,7 @@ two statements are not the same:
>MOVE-CORRESPONDING struc1 TO struc2.
>```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## NEW
@@ -477,7 +477,7 @@ DATA(oref3) = NEW cl2( p1 = ... p2 = ... ).
... NEW some_class( ... )->attr ...
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## CONV
@@ -532,7 +532,7 @@ DATA(f) = `hallo`.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## EXACT
@@ -568,7 +568,7 @@ TRY.
ENDTRY.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## REF
@@ -613,7 +613,7 @@ DATA(oref_a) = NEW some_class( ).
DATA(oref_b) = REF #( oref_a ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## CAST
@@ -650,7 +650,7 @@ DATA(methods) = CAST cl_abap_objectdescr(
cl_abap_objectdescr=>describe_by_name( 'LOCAL_CLASS' ) )->methods.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## COND
@@ -679,7 +679,7 @@ DATA(b) = COND #( WHEN a BETWEEN 1 AND 3 THEN w
ELSE z ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## SWITCH
@@ -699,7 +699,7 @@ DATA(b) = SWITCH #( a
ELSE z ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## FILTER
@@ -768,7 +768,7 @@ DATA(f10) = FILTER #( itab2 IN filter_tab2 USING KEY line WHERE num = table_line
DATA(f11) = FILTER #( itab2 USING KEY sec_key EXCEPT IN filter_tab2 WHERE num = table_line ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## REDUCE
@@ -800,7 +800,7 @@ DATA(sum) = REDUCE i( INIT s = 0
>- Once the loop has finished, the target variable is assigned the
resulting value.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Iteration Expressions with FOR
@@ -897,7 +897,7 @@ TYPES t_type LIKE itab.
compZ = wa3-comp3 ) ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## LET Expressions
@@ -929,7 +929,7 @@ DATA(a) = COND #( LET b = c IN
ELSE ... ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Executable Example
[zcl_demo_abap_constructor_expr](./src/zcl_demo_abap_constructor_expr.clas.abap)

View File

@@ -45,7 +45,7 @@
that include dynamic programming features may be difficult.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Excursion: Field Symbols and Data References
@@ -203,7 +203,7 @@ LOOP AT itab ASSIGNING FIELD-SYMBOL(<fs2>).
ENDLOOP.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Data References
@@ -607,7 +607,7 @@ reference variables are more powerful as far as their usage options are
concerned, and they better fit into the modern (object-oriented) ABAP
world. Recommended read: [Accessing Data Objects Dynamically (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendyn_access_data_obj_guidl.htm "Guideline").
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Dynamic ABAP Statements
@@ -855,7 +855,7 @@ Note that dynamically specifying syntax elements has downsides, too. Consider so
"The addition EXCEPTION-TABLE for exceptions is not dealt with here.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Runtime Type Services (RTTS)
@@ -905,7 +905,7 @@ F2 help information in
[ADT](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenadt_glosry.htm "Glossary Entry"),
for more details.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Getting Type Information at Runtime
@@ -1102,7 +1102,7 @@ CREATE OBJECT oref4abs TYPE (abs_name_cl).
CREATE OBJECT oref4abs TYPE ('\CLASS=ZCL_DEMO_ABAP_DYNAMIC_PROG').
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Dynamically Creating Data Types at Runtime
You can create data types at program runtime using methods of the type description classes of RTTS.
@@ -1217,7 +1217,7 @@ DATA(tdo_ref_3) = cl_abap_refdescr=>get_by_name( 'T' ).
DATA(tdo_ref_4) = cl_abap_refdescr=>get_by_name( 'ZCL_DEMO_ABAP_DYNAMIC_PROG' ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Dynamically Creating Data Objects at Runtime
@@ -1262,7 +1262,7 @@ DATA(tdo_ref) = cl_abap_refdescr=>get( cl_abap_elemdescr=>get_t( ) ).
CREATE DATA dref_cr TYPE HANDLE tdo_ref.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## More Information
- It is recommended that you also consult section [Dynamic Programming Techniques (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynamic_prog_technique_gdl.htm) in the ABAP Keyword Documentation since it provides important aspects that should be considered when dealing with dynamic programming in general (e. g. security aspects or runtime error prevention).

View File

@@ -48,7 +48,7 @@ and built-in [string functions](https://help.sap.com/doc/abapdocu_cp_index_htm/C
corresponding ABAP statements, or even more. The return value of string functions
that return character strings is always of type `string`.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Data Types for Character Strings
@@ -88,7 +88,7 @@ that must be a maximum of two characters, or for input fields in
forms that should not exceed a certain length. If limiting a string
is not relevant, text strings are a good choice.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Declaring Character-Like Data Objects
@@ -145,7 +145,7 @@ DATA char(4) TYPE c.
DATA char_len_one TYPE c.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Assigning Values
@@ -229,7 +229,7 @@ however, with [significant
differences](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenliteral_operator.htm)
to `&&`.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## String Templates
- Using string templates, you can construct strings very elegantly from
@@ -311,7 +311,7 @@ s1 = |{ CONV decfloat34( - 1 / 3 ) DECIMALS = 3 }|. "'-0.333'
> **💡 Note**<br>
> Escape `\|{}` in string templates using `\`, i. e. `\\` means `\`.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Determining the Length of Strings
@@ -333,7 +333,7 @@ len_c = numofchar( 'abc ' ). "3
len_str = numofchar( `abc ` ). "3
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Concatenating Strings
@@ -379,7 +379,7 @@ s1 = concat_lines_of( table = itab ). "Without separator
s1 = concat_lines_of( table = itab sep = ` ` ). "With separator
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Splitting Strings
@@ -420,7 +420,7 @@ SPLIT s1 AT ',' INTO TABLE itab. "Strings are added to itab in individual lines
s2 = segment( val = s1 index = 2 sep = `,` ). "world
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Modifying Strings
**Transforming to Lowercase and Uppercase**
@@ -609,7 +609,7 @@ OVERLAY txt1 WITH txt2 ONLY 'ab'.
"txt1: z.x.c.Z.x.c.A
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Processing Substrings
@@ -694,7 +694,7 @@ s2 = substring_from( val = s1 sub = `a3` ). "a3bb4
s2 = substring_to( val = s1 sub = `3b` ). "aa1bb2aa3b
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Searching and Replacing
@@ -715,7 +715,7 @@ on single characters only or more complex, pattern-based
operations on character sequences using [PCRE regular
expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpcre_regex_glosry.htm "Glossary Entry").
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Searching for Specific Characters
@@ -807,7 +807,7 @@ res = count_any_not_of( val = str sub = `Piecs ofak.` ). "0
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Replacing Specific Characters in Strings
@@ -841,7 +841,7 @@ s2 = translate( val = s1 from = `_` to = `##` ). "###abc#def#####ghi#
TRANSLATE s1 USING `_.a#g+`. "...#bc.def.....+hi.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Searching for Substrings in Strings (and Tables)
@@ -1168,7 +1168,7 @@ TRY.
ENDTRY.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Replacing Substrings in Strings (and Tables)
@@ -1415,7 +1415,7 @@ regular
expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenposix_regex_glosry.htm "Glossary Entry")
anymore, they are obsolete.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Simple Pattern-Based Searching Using Comparison Operators
@@ -1451,7 +1451,7 @@ IF s1 CP `*f#_*`. ... "true; sy-fdpos = 6
IF s1 NP `i+`. ... "true; sy-fdpos = 11 (length of searched string)
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Complex Searching and Replacing Using Regular Expressions
@@ -1517,7 +1517,7 @@ Anchors and Positions
| `\b` | Start or end of word | 1. `\ba.` <br>2. `\Dd\b` <br>3. `\b.d\b` | abcd a12d ed | 1. <ins>**ab**</ins>cd <ins>**a1**</ins>2d ed <br>2. ab<ins>**cd**</ins> a12d <ins>**ed**</ins> <br> 3. abcd a12d <ins>**ed**</ins> | 1. ab<ins>**cd**</ins> a1<ins>**2d**</ins> ed <br> 2. abcd a1<ins>**2d**</ins> ed <br> 3. <ins>**abcd**</ins> <ins>**a12d**</ins> ed |
| `\B` | Negation of `\b`, not at the start or end of words | `\Be\B` | see an elefant | s<ins>**e**</ins>e an el<ins>**e**</ins>fant | s<ins>**ee**</ins> an <ins>**e**</ins>lefant |
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
#### Searching Using Regular Expressions
@@ -1575,7 +1575,7 @@ DATA(itab) = value string_table( ( `Cathy's black cat on the mat played with the
FIND FIRST OCCURRENCE OF PCRE `\bt.` IN TABLE itab
IGNORING CASE MATCH LINE DATA(d) MATCH OFFSET DATA(e) MATCH LENGTH DATA(f). "d: 1, e: 21, f: 2
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
##### Excursion: System Classes for Regular Expressions
@@ -1608,7 +1608,7 @@ DATA(res) = cl_abap_regex=>create_pcre( pattern = `\s\w` "any blank follow
ignore_case = abap_true )->create_matcher( text = str )->find_all( ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
#### Replacing Using Regular Expressions
@@ -1660,7 +1660,7 @@ s2 = replace( val = s1
REPLACE PCRE `(.*?)PP(.*)` IN s1 WITH `$2#$1` IGNORING CASE. "pc app#ab a
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Executable Example
[zcl_demo_abap_string_proc](./src/zcl_demo_abap_string_proc.clas.abap)

View File

@@ -3,7 +3,7 @@
# ABAP for RAP: Entity Manipulation Language (ABAP EML)
- [ABAP for RAP: Entity Manipulation Language (ABAP EML)](#abap-for-rap-entity-manipulation-language-abap-eml)
- [RAP Buzzwords](#rap-buzzwords)
- [RAP Terms](#rap-terms)
- [ABAP Behavior Pools (ABP)](#abap-behavior-pools-abp)
- [RAP Handler Classes and Methods](#rap-handler-classes-and-methods)
- [RAP Saver Class and Saver Methods](#rap-saver-class-and-saver-methods)
@@ -22,10 +22,10 @@
- [More Information](#more-information)
- [Executable Examples](#executable-examples)
## RAP Buzzwords
## RAP Terms
[ABAP Entity Manipulation Language](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenaeml_glosry.htm) (or EML for short) is a subset of ABAP that allows you to access the data of [RAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenarap_glosry.htm) business objects in an ABAP program.
The following points touch on RAP-related buzzwords such as *RAP business objects* and others for setting the context:
The following points touch on RAP-related terms such as *RAP business objects* and others for setting the context:
- RAP business objects (RAP BO)
- A RAP BO is based on a special, tree-like hierarchical structure
@@ -193,7 +193,7 @@ that handles requests from outside the AS ABAP or, from inside AS ABAP,
an ABAP program using ABAP EML (which this cheat sheet and the examples
focus on).
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## ABAP Behavior Pools (ABP)
@@ -234,7 +234,7 @@ sequence](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?f
methods](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabp_saver_method_glosry.htm "Glossary Entry")
to save data from the transactional buffer to the database).
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### RAP Handler Classes and Methods
@@ -342,7 +342,7 @@ METHODS some_action FOR MODIFY
UI if something goes wrong to inform the user.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### RAP Saver Class and Saver Methods
@@ -403,7 +403,7 @@ CLASS lsc_bdef DEFINITION INHERITING FROM cl_abap_behavior_saver.
ENDCLASS.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## BDEF Derived Types
@@ -508,7 +508,7 @@ DATA rep TYPE RESPONSE FOR REPORTED entity.
> **💡 Note**<br>
> Some of the derived types can only be created and accessed in implementation classes.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Components of BDEF Derived Types
@@ -606,7 +606,7 @@ Bullet points on selected `%` components:
`if_abap_behv=>mk-off`, the values of these fields
are not returned in the result.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## EML Syntax
@@ -825,7 +825,7 @@ MODIFY ENTITIES OF root_ent
...
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### EML Syntax for Reading Operations
@@ -886,7 +886,7 @@ READ ENTITIES OF root_ent
LINK DATA(links2).
...
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
#### Dynamic Forms of EML Statements
@@ -983,7 +983,7 @@ op_tab = VALUE #(
READ ENTITIES OPERATIONS op_tab.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Persisting to the Database
@@ -1029,7 +1029,7 @@ IF sy-subrc <> 0.
ENDIF.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### EML Statements in ABAP Behavior Pools
@@ -1058,7 +1058,7 @@ MODIFY ENTITIES OF root_ent IN LOCAL MODE
...
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## RAP Excursions
@@ -1351,7 +1351,7 @@ The following restrictions apply to operations and/or statements in the individu
</details>
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## More Information
@@ -1366,7 +1366,7 @@ The following restrictions apply to operations and/or statements in the individu
consistency and reliability
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Executable Examples
This cheat sheet is supported by different executable examples demonstrating various scenarios:

View File

@@ -1,5 +1,3 @@
<a name="top"></a>
# Excursion Down to Bits and Bytes
This sheet goes a bit into the technical background of data types and

View File

@@ -2,19 +2,8 @@
# ABAP SQL: Working with Hierarchies
This cheat sheet summarizes the functions ABAP SQL offers together with
ABAP CDS for working with [hierarchical
data](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhierarchy_glosry.htm "Glossary Entry")
that is stored in database tables. Hierarchical data in database tables
means that lines of one or more database tables are connected by
[parent-child
relationships](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpcr_glosry.htm "Glossary Entry").
There are many use cases where hierarchical data plays a role and where
accessing information about the hierarchical relationship is important.
For example, a common task can be to find out the descendants or
ancestors of a given hierarchy node or to aggregate values of subtrees.
- [ABAP SQL: Working with Hierarchies](#abap-sql-working-with-hierarchies)
- [Introduction](#introduction)
- [Overview](#overview)
- [SQL Hierarchies](#sql-hierarchies)
- [Creating SQL Hierarchies](#creating-sql-hierarchies)
@@ -28,6 +17,19 @@ ancestors of a given hierarchy node or to aggregate values of subtrees.
- [Hierarchy Aggregate Navigators](#hierarchy-aggregate-navigators)
- [More Information](#more-information)
## Introduction
This cheat sheet summarizes the functions ABAP SQL offers together with
ABAP CDS for working with [hierarchical
data](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhierarchy_glosry.htm "Glossary Entry")
that is stored in database tables. Hierarchical data in database tables
means that lines of one or more database tables are connected by
[parent-child
relationships](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpcr_glosry.htm "Glossary Entry").
There are many use cases where hierarchical data plays a role and where
accessing information about the hierarchical relationship is important.
For example, a common task can be to find out the descendants or
ancestors of a given hierarchy node or to aggregate values of subtrees.
## Overview
@@ -57,6 +59,8 @@ learn some additional syntax and then you can start right away.
> **💡 Note**<br>
> The examples in this cheat sheet are only relevant for [standard ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_abap_glosry.htm), i. e. the unrestricted ABAP language scope. Find the artifacts used in the code snippets in your on-premise system.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## SQL Hierarchies
With [SQL
@@ -99,6 +103,8 @@ for each row. For creating a SQL hierarchy, you need the following:
The following topics show you step-by-step how SQL hierarchies can be
created and accessed.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Creating SQL Hierarchies
### ABAP CDS Hierarchies
@@ -252,6 +258,8 @@ From the ABAP language point of view, CDS hierarchies are the most
convenient way of using SQL hierarchies. Now let us turn to other ways,
involving more ABAP, until we do not use any CDS more in the end.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### ABAP SQL Hierarchy Generator HIERARCHY
The ABAP SQL [hierarchy
generator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhierarchy_generator_glosry.htm "Glossary Entry")
@@ -367,6 +375,8 @@ not least we will use CTEs as hierarchies themselves. You might skip the
following section and turn directly to the hierarchy navigators if you
are not too interested in this syntactic gimmicks.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### ABAP CTE Hierarchies
A CTE that produces hierarchical data can declare itself as a SQL
@@ -479,6 +489,8 @@ hierarchy association. Running
`CL_DEMO_SQL_HIERARCHIES` shows that all
assertions are fulfilled.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Hierarchy Navigators
[Hierarchy
@@ -501,6 +513,8 @@ or a CTE hierarchy. Check the examples of the
[documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenselect_hierarchy_navigators.htm),
where this is also shown.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Hierarchy Node Navigator HIERARCHY_DESCENDANTS
As the name says,
@@ -536,6 +550,8 @@ distance to the respective start node. A further parameter
`DISTANCE` - not shown here - allows you to restrict the
distance to the respective start node.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Hierarchy Node Navigator HIERARCHY_ANCESTORS
Now the other way around: ABAP SQL function
@@ -566,6 +582,8 @@ aggregate functions or evaluating the internal result table, you can now
easily extract further information like the number of ancestors and so
on.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Hierarchy Node Navigator HIERARCHY_SIBLINGS
Besides descendants and ancestors, hierarchy nodes also can have
@@ -598,6 +616,8 @@ the respective start node. Running
`CL_DEMO_SQL_HIERARCHIES`, where we start with
a node that definitely has some siblings, shows the result.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Hierarchy Aggregate Navigators
Finally let us turn to the [hierarchy aggregate
@@ -697,5 +717,7 @@ Running `CL_DEMO_SQL_HIERARCHIES` shows the
result. It also shows the result of the joined data source, where you
can check that the calculated values are correct.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## More Information
For the complete reference documentation about SQL hierarchies, see [`SELECT, FROM hierarchy_data`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenselect_hierarchy_data.htm).

View File

@@ -64,6 +64,8 @@ The member loop is executed using the group represented by `wa`
and its members are assigned to `member` and are available in
the member loop.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Grouping by More than One Column
To group by more than just one criterion, a structured group key is
@@ -83,6 +85,8 @@ This is also a representative binding in which the work area
To access the members of the groups, the exact same member loop can be
inserted as when grouping by one column.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Group Key Binding when Grouping by One Column
By explicitly specifying an [output
@@ -129,6 +133,8 @@ LOOP AT spfli_tab INTO wa 
ENDLOOP.
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Group Key Binding when Grouping by More than One Column
Finally, the group key binding for structured group keys:
@@ -165,6 +171,8 @@ INDEX`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?fil
[`GROUP
SIZE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaploop_at_itab_group_by_key.htm).
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Executable Example
[zcl_demo_abap_sql_group_by](./src/zcl_demo_abap_sql_group_by.clas.abap)

View File

@@ -69,6 +69,8 @@ in the ABAP Keyword Documentation.
>- AMDP classes can only be edited with the [ABAP development tools for Eclipse
(ADT)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenadt_glosry.htm "Glossary Entry").
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## AMDP Classes
- As mentioned above, an [AMDP
@@ -100,6 +102,7 @@ CLASS cl_some_amdp_class DEFINITION
ENDCLASS.
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## AMDP Methods
@@ -133,6 +136,7 @@ PRIVATE SECTION.
...
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## AMDP Procedures
@@ -222,6 +226,8 @@ Note:
and implementation parts. Check the ABAP Keyword Documentation for
more details as touched on further down.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## 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")
@@ -298,6 +304,8 @@ ENDMETHOD.
...
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### CDS Table Functions
- Each [CDS table
@@ -370,7 +378,7 @@ define table function some_ddl_source
You can then use the CDS table function as source for a
`SELECT` statement, for example: `SELECT * FROM some_ddl_source INTO ...`.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## More Information
@@ -428,6 +436,8 @@ 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.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Executable Example
[zcl_demo_abap_amdp](./src/zcl_demo_abap_amdp.clas.abap)

View File

@@ -49,7 +49,7 @@ ELSE.
ENDIF.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Expressions and Functions for Conditions
- So, such control structures are executed depending on conditions as specified above: `... num = 2 ...` - a [logical expression](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenlogical_expression_glosry.htm).
@@ -226,7 +226,7 @@ ENDIF.
> **💡 Note**<br>
> Logical expressions and functions can also be used in other ABAP statements.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Control Structures
@@ -295,7 +295,7 @@ ENDIF.
> sure - as implied in the example's `ELSE` statement above. However, an `ELSE` statement that is never executed might be a hint that
> logical expressions might partly be redundant.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
#### Excursion: `COND` Operator
@@ -311,7 +311,7 @@ ENDIF.
ELSE resultn ) ...
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### `CASE`: Case Distinctions
@@ -350,7 +350,7 @@ CASE TYPE OF oref.
ENDCASE.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
#### Excursion: `SWITCH` Operator
@@ -365,7 +365,7 @@ The conditional operator [`SWITCH`](https://help.sap.com/doc/abapdocu_cp_index_h
ELSE resultn ) ...
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Loops
@@ -389,7 +389,7 @@ The conditional operator [`SWITCH`](https://help.sap.com/doc/abapdocu_cp_index_h
```
- The value of the system field `sy-index` within the statement block contains the number of previous loop passes including the current pass.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
#### Interrupting and Exiting Loops
@@ -405,7 +405,7 @@ The following ABAP keywords are available for interrupting and exiting loops:
> - [`RETURN`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapreturn.htm) statements immediately terminate the current processing block. However, according to the [guidelines (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenexit_procedure_guidl.htm), `RETURN` should only be used to exit procedures like methods.
> - `EXIT` and `CHECK` might also be used for exiting procedures. However, their use inside loops is recommended.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
#### `WHILE`: Conditional Loops
@@ -419,7 +419,7 @@ WHILE log_exp.
ENDWHILE.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
#### Loops Across Tables
Further keywords for defining loops are as follows. They are not dealt with here since they are touched on in other ABAP cheat sheets.
@@ -429,7 +429,7 @@ Further keywords for defining loops are as follows. They are not dealt with here
- You can also realize loops using iteration expressions with `VALUE` and `REDUCE`. See the example class for the internal table cheat sheet.
- [`SELECT ... ENDSELECT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapselect.htm) statements loop across the result set of a database access. See also the cheat sheet on ABAP SQL.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Calling Procedures
@@ -440,7 +440,7 @@ However, ...
Regarding the exiting of procedures, note the hint mentioned above. The use of `RETURN` is recommended.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Handling Exceptions
- [Exceptions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenexception_glosry.htm) ...
@@ -561,7 +561,7 @@ Regarding the exiting of procedures, note the hint mentioned above. The use of `
>- For all exceptions that are raised by the ABAP runtime environment and that are not handled, there is a corresponding runtime error. For example, in the case of exception class `CX_SY_ZERODIVIDE`, it is the runtime error `COMPUTE_INT_ZERODIVIDE`. For self-defined exception classes, an exception that is not handled generally triggers the runtime error `UNCAUGHT_EXCEPTION`.
> - For `TRY` control structures, there are further additions available dealing with more advanced error handling, e. g. [resumable exceptions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapresume.htm).
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
#### Notes on Exception Classes
- To distinguish exception classes from *regular* classes, use the naming convention `CX` as prefix and not `CL`.
@@ -607,7 +607,7 @@ Regarding the exiting of procedures, note the hint mentioned above. The use of `
> - Each exception has a an [exception text](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenexception_text_glosry.htm) that describes the error situation and that you can retrieve as outlined above. It helps you analyze the error. Plus, imagine using exceptions in the context of user interfaces. If a user faces an error situation, such exception texts may be displayed on the UI.
> - Find more information on exception texts [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenexception_texts.htm) in the ABAP Keyword Documentation.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Raising Exceptions
@@ -630,7 +630,7 @@ RAISE EXCEPTION TYPE cx_sy_zerodivide.
ELSE THROW cx_some_error( ) ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Excursion: Runtime Errors and Terminating Programs
- Runtime errors are caused by uncatchable exceptions when a program is executed, when a catchable exception is not caught, or they can be forced by, for example, using [`ASSERT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapassert.htm) statements.
@@ -652,7 +652,7 @@ ASSERT flag = abap_true.
> - Each runtime error is identified by a name and assigned to a specific error situation.
> - In ADT, you will see a message popping up and informing you about the runtime error. You can check the details by choosing the "Show" button in the pop-up. Furthermore, you can check the content of the "Feed Reader" tab in ADT. There, just expand your project and find the runtime errors caused by you.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Executable Example
[zcl_demo_abap_prog_flow_logic](./src/zcl_demo_abap_prog_flow_logic.clas.abap)

View File

@@ -30,7 +30,7 @@ This cheat sheet contains basic information about [unit testing](https://help.sa
- In ABAP, developers have [ABAP Unit](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_unit_glosry.htm) - a test tool integrated into the ABAP runtime framework - at their disposal. It can be used to run individual or mass tests, and to evaluate test results. Note that comprehensive test runs can be performed using the [ABAP Test Cockpit](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_test_cockpit_glosry.htm)
- In ABAP programs, individual unit tests are implemented as [test methods](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentest_method_glosry.htm) of local [test classes](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentest_class_glosry.htm).
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## High-Level Steps for ABAP Unit Tests
@@ -47,7 +47,7 @@ This cheat sheet contains basic information about [unit testing](https://help.sa
> **💡 Note**<br>
> Of course, if there are no dependend-on components in your production code, you can skip the considerations of dependency isolation, test doubles and their injection into the production code.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Creating Test Classes
@@ -174,7 +174,7 @@ CLASS ltd_test_double IMPLEMENTATION.
ENDCLASS.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Creating and Implementing Test Methods
@@ -313,7 +313,7 @@ CLASS ltc_test_class IMPLEMENTATION.
ENDCLASS.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Special Methods for Implementing the Test Fixture
- Special private methods for implementing the test [fixture](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfixture_glosry.htm), which may include test data and test objects among others, can be included in the local test class.
@@ -395,7 +395,7 @@ ENDCLASS.
> **💡 Note**<br>
> You can also specify helper methods, for example, for recurring tasks such as the assertions.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Handling Dependencies
@@ -429,7 +429,7 @@ Among them, there are the following. They are demonstrated in the executable exa
- Parameter injection: The test double is passed as a parameter to the tested method (i.e. an optional importing parameter) in the class under test.
- Back door injection: A *back door* is created to inject a test double into the class under test. This *back door* is implemented by granting [friendship](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfriend_glosry.htm) to the test class. This makes internal attributes of the class under test accessible from the test class.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Test Seams
- Seams are sections of the production source code that can be dynamically included or replaced.
@@ -481,7 +481,7 @@ END-TEST-INJECTION.
...
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Running and Evaluating ABAP Unit Tests
There are many ways to run ABAP unit tests as described [here](https://help.sap.com/docs/ABAP_PLATFORM_NEW/c238d694b825421f940829321ffa326a/4ec4c6c66e391014adc9fffe4e204223.html?locale=en-US).
@@ -494,7 +494,7 @@ If you are interested in the test coverage, you can choose `Ctrl + Shift + F11`,
For more information about evaluating ABAP unit test results, see [here](https://help.sap.com/docs/ABAP_PLATFORM_NEW/c238d694b825421f940829321ffa326a/4ec49c5b6e391014adc9fffe4e204223.html?locale=en-US).
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## More Information
@@ -507,7 +507,7 @@ For more information about evaluating ABAP unit test results, see [here](https:/
- [Testing repository objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentest_relations.htm) (ABAP Keyword Documentation)
- [Development Guide for the ABAP RESTful Application Programming Model: Testing different artifacts of RAP business objects and related OData services](https://help.sap.com/docs/btp/sap-abap-restful-application-programming-model/test?locale=en-US)
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Executable Example
[zcl_demo_abap_unit_test](./src/zcl_demo_abap_unit_test.clas.abap)

View File

@@ -18,7 +18,7 @@
- [Creating Anonymous Data Objects](#creating-anonymous-data-objects)
- [Constants and Immutable Variables](#constants-and-immutable-variables)
- [Type Conversion](#type-conversion)
- [Terms Related to Types and Data Objects in a Nutshell](#terms-related-to-types-and-data-objects-in-a-nutshell)
- [Terms Related to Data Types and Objects in a Nutshell](#terms-related-to-data-types-and-objects-in-a-nutshell)
- [Notes on the Declaration Context](#notes-on-the-declaration-context)
- [Excursions](#excursions)
- [Enumerated Types and Objects](#enumerated-types-and-objects)
@@ -52,7 +52,7 @@ Data objects:
> **💡 Note**<br>
> There are several differentations that further distinguish and characterize data types and objects. See [here](#glossary-terms-in-a-nutshell).
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## ABAP Data Types
@@ -88,7 +88,7 @@ For an overview, see the [ABAP Type Hierarchy](https://help.sap.com/doc/abapdocu
> - Although they are character-like, `t` and `d` can be used for calculations.
> - See the ABAP Keyword Documentation [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuilt_in_types.htm) for more information about the initial values of the data types, the standard length, and so on.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Complex Data Types
@@ -104,7 +104,7 @@ For an overview, see the [ABAP Type Hierarchy](https://help.sap.com/doc/abapdocu
> **💡 Note**<br>
> Structured and table types are used in this cheat sheet as examples for complex types. For more information, see the ABAP Keyword Documentation and the ABAP cheat sheets for structures and internal tables.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Reference Types
- Describe data objects that contain [references](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreference_glosry.htm) to other objects (data objects and instances of classes), which are known as [reference variables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreference_variable_glosry.htm).
@@ -116,7 +116,7 @@ For an overview, see the [ABAP Type Hierarchy](https://help.sap.com/doc/abapdocu
> There are [generic ABAP types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abengeneric_abap_type_glosry.htm). Generic data types are types that do not define all of the properties of a data object. They can only be used for the typing of [formal parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenformal_parameter_glosry.htm) and [field symbols](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm).
The only generic types that can be used after `TYPE REF TO` are `data` for the generic typing of data references, and `object`, for the generic typing of object references.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Declaring Data Types
@@ -301,7 +301,7 @@ DATA itab_str TYPE TABLE OF string.
TYPES tr_like_table_ref LIKE TABLE OF REF TO itab_str.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Data Objects
@@ -469,7 +469,7 @@ DATA dref_tab_i TYPE TABLE OF REF TO i.
DATA dref_tab_str LIKE TABLE OF REF TO do_some_string.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Assigning Values to Data Objects
@@ -573,7 +573,7 @@ str_a2 = |{ str_a1 } some more bla.|. "String templates. Note: Data objects are
str_a2 = some_itab[ 2 ]-carrname.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Creating Data Objects Using Inline Declaration
@@ -682,7 +682,7 @@ SELECT * FROM zdemo_abap_carr INTO TABLE @DATA(itab_b3).
SELECT * FROM zdemo_abap_carr INTO TABLE NEW @DATA(itab_ref).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Assigning References to Data Reference Variables
@@ -777,7 +777,7 @@ dref_1_i ?= dref_3_data.
dref_1_i = CAST #( dref_6_i ).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Creating Anonymous Data Objects
@@ -872,7 +872,7 @@ SELECT *
INTO TABLE NEW @DATA(dref_14_inline).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Constants and Immutable Variables
@@ -912,7 +912,7 @@ ENDLOOP.
SELECT * FROM zdemo_abap_carr INTO TABLE @FINAL(itab_final_inl).
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Type Conversion
A value assignment means that the value of a data object is transferred to a target data object. If the data types of the source and target are compatible, the content is copied unchanged. If they are incompatible and a suitable [conversion rule](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconversion_rule_glosry.htm) exists, the content is converted.
@@ -955,9 +955,9 @@ DATA(i2str) = CONV string( -10 ).
"Result: i2str: `10-`
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Terms Related to Types and Data Objects in a Nutshell
## Terms Related to Data Types and Objects in a Nutshell
```abap
"Standalone and bound data types
@@ -1160,8 +1160,8 @@ SELECT *
**********************************************************************
"Source and target data objectsCompatibility, convertibility and
"conversion
"Compatibility, convertibility and conversion regarding source and
"target data objects
"1. Source and target are compatible, all technical type properties
" match
DATA some_dobj TYPE c LENGTH 1 VALUE 'A'.
@@ -1192,7 +1192,7 @@ DATA itab_str TYPE string_table.
"some_number = itab_str.
```
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Notes on the Declaration Context
@@ -1211,7 +1211,7 @@ The declaration context of data types (and objects) determines the validity and
- The DDIC provides many options for defining types, including elementary data types (defined as data elements), reference types, complex types such as structured types and table types. Note that the name of a database table or a view can be used in type declarations to address the line type of these repository objects (for example, a structure: `DATA a TYPE some_db_table.`).
- Note the following trap: Local declarations hide global declarations of the same name.
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Excursions
### Enumerated Types and Objects
@@ -1269,7 +1269,7 @@ dobj_enum = a.
Find more information on enumerated types in the (commented code of the) cheat sheet example and [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenenumerated_types_usage.htm).
<p align="right">(<a href="#top">back to top</a>)</p>
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Getting Type Information and Creating Types at Runtime
Using [Runtime Type Identification (RTTI)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm "Glossary Entry"), you can get type information on data objects, data types or [instances](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninstance_glosry.htm "Glossary Entry") at runtime ([Runtime Type Identification (RTTI)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm "Glossary Entry")).

297
17_SAP_LUW.md Normal file
View File

@@ -0,0 +1,297 @@
<a name="top"></a>
# SAP LUW
- [SAP LUW](#sap-luw)
- [Introduction](#introduction)
- [Terms](#terms)
- [SAP LUW Overview](#sap-luw-overview)
- [Bundling Techniques](#bundling-techniques)
- [Related ABAP Statements](#related-abap-statements)
- [Concepts Related to the SAP LUW](#concepts-related-to-the-sap-luw)
- [Notes on the SAP LUW in ABAP Cloud and RAP](#notes-on-the-sap-luw-in-abap-cloud-and-rap)
- [More Information](#more-information)
- [Executable Example](#executable-example)
## Introduction
⚠️ Most of the content of this cheat sheet is only relevant to [classic ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenclassic_abap_glosry.htm).
This cheat sheet provides a high-level introduction to the [SAP LUW](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_luw_glosry.htm) concept that deals with data consistency with a focus on SAP LUW-related statements, supported by an executable example to check the syntax in action.
When you run an application, you typically change data in a [transaction](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentransaction_glosry.htm), which may be temporarily stored in transactional buffers.
This data may be temporarily inconsistent in the buffers, but it is important that the data be in a consistent state at the end of the transaction so that it can be saved to the database.
Consider the following example of transactional consistency:
- A transaction consists of a money transfer from account A to account B, assuming the accounts are in the same bank and the data is stored in the same database.
- Such a transaction represents a logical unit. The transaction is successful when the money is debited from account A and credited to account B.
- This transaction may include other related tasks. Data may be loaded into a buffer, processed there, and become inconsistent during this time. It may also take a while for the whole process to be completed.
- However, at the end of the transaction, all data must be in a consistent state so that the database can be updated accordingly. Or, if errors occur during the transaction, it must be ensured that all changes can be reversed. It must not happen that money is credited to account B without also updating the totals of account A. In such a case, the previous consistent state must be restored.
> **💡 Note**<br>
> - This cheat sheet focuses on [classic ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenclassic_abap_glosry.htm). Hence, the links in this cheat sheet open topics in the ABAP Keyword Documentation for [Standard ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_abap_glosry.htm).
> - The SAP LUW concept is certainly relevant to ABAP Cloud, too. The [ABAP RESTful Application Programming Model (RAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenarap_glosry.htm) is the transactional programming model for [ABAP Cloud](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_cloud_glosry.htm). It comes with a well-defined transactional model and follows the rules of the SAP LUW. Find out more in this [blog](https://blogs.sap.com/2022/12/05/the-sap-luw-in-abap-cloud/).
## Terms
The following terms are related to the concept of the SAP LUW and try to give you some context about it:
- [Transaction](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentransaction_glosry.htm)
- In a business context, a transaction describes a sequence of related and/or interdependent actions, such as retrieving or modifying data.
- The result of the transaction is a consistent state of data in the database.
- [Logical unit of work (LUW)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenluw_glosry.htm)
- Describes the time interval at which one consistent state of the database is transitioned to another consistent state.
- Follows an all-or-nothing approach: It ends either with a single and final commit, which saves the changed data in the database, or with a rollback, which undoes all changes and restores the consistent state before the changes (for example, in the case of an error during the LUW). Either all data changes are committed, or none at all.
- For an [Application Server ABAP (AS ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenas_abap_glosry.htm), two types of LUWs come into play to achieve data consistency: Database LUW and SAP LUW (which is covered below).
- [Database LUW](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendatabase_luw_glosry.htm)
- Also called database transaction.
- Is an SAP-independent mechanism for transactional consistency in the database.
- Describes an indivisible sequence of database operations concluded by a [database commit](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendatabase_commit_glosry.htm), that persists data to the database.
- The [database system](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendatabase_system_glosry.htm) either executes the database LUW completely or not at all. If an error is detected within a database LUW, a [database rollback](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendatabase_rollback_glosry.htm) undoes all database changes made since the start of the database LUW.
- [Database commit](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendatabase_commit_glosry.htm)
- Marks the end of a database LUW in which changed data records are written to the database.
- An important question for developers is how and when database commits and rollbacks are triggered (especially implicitly).
- In AS ABAP, database commits can be triggered implicitly as well as by means of explicit requests.
- Find more information [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendb_commit.htm).
- Implicit database commits. Among others, implicit database commits are triggered by:
- Completing a [dialog step](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendialog_step_glosry.htm) in the context of dynpros
- A dialog step describes the state of a [user session](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenuser_session_glosry.htm) between a [user action](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenuser_action_glosry.htm) on the user interface of a dynpro and the sending of a new [screen layout](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenscreen_glosry.htm), i.e. it covers logic implemented in the [PAI](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenpai_glosry.htm) of the current dynpro and [PBO](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenpbo_glosry.htm) of the following dynpro
- When the next screen is displayed, the program waits for a user action and does not occupy a [work process](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenwork_process_glosry.htm) during this time.
- The next free work process is assigned to the program in the next dialog step.
- A work process change requires and implicitly triggers a database commit.
- Calling a [function module](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenfunction_module_glosry.htm) in a [synchronous (sRFC)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensynchronous_rfc_glosry.htm) or [asynchronous remote function call (aRFC)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenasynchronous_rfc_glosry.htm)
- This is when the current work process passes control to another work process or system. Exception: [Updates](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenupdate_glosry.htm).
- HTTP/HTTPS/SMTP communication executed using the [Internet Communication Framework (ICF)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenicf_glosry.htm)
- [`WAIT`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapwait_up_to.htm) statements that interrupt the current work process
- Sending messages ([error messages](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenerror_message_glosry.htm), [information message](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abeninformation_message_glosry.htm), and [warning](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenwarning_glosry.htm))
- Explicit database commits. For example, database commits can be triggered explicitly in ABAP programs in the following ways:
- Using the relevant database-specific [Native SQL](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abennative_sql_glosry.htm) statement
- Using the ABAP SQL statement [`COMMIT CONNECTION`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcommit_rollback_connection.htm)
- Calling the function module `DB_COMMIT`, which encapsulates the corresponding Native SQL statement.
- Using the ABAP SQL statement [`COMMIT WORK`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcommit.htm). Note that the statement is particularly relevant to the SAP LUW as shown below. It also ends the SAP LUW.
- [Database rollback](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendatabase_rollback_glosry.htm)
- Like a database commit, ...
- a database rollback marks the end of a database LUW. Here, all modifying database operations are undone until the beginning of the LUW.
- are triggered implicitly, as well as by explicit requests.
- They are implicitly triggered, for example, by a [runtime error](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenruntime_error_glosry.htm) or a [termination message](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentermination_message_glosry.htm) (message of type `A`).
- For example, explicit rollbacks are triggered by:
- Using the relevant database-specific Native SQL statement
- Using the ABAP SQL statement [`ROLLBACK CONNECTION`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcommit_rollback_connection.htm)
- Calling the function module `DB_ROLLBACK`, which encapsulates the corresponding Native SQL statement.
- Using the ABAP SQL statement [`ROLLBACK WORK`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abaprollback.htm). Note that the statement is particularly relevant to the SAP LUW as shown below. It also ends the SAP LUW.
- [Work process](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenwork_process_glosry.htm)
- As a component of an AS ABAP AS instance, work processes execute ABAP applications. Each ABAP program that is currently active requires a work process.
- AS ABAP uses its own work processes to log on to the database system. Different types of work processes are available for applications, including dialog, enqueue, background, spool, and update work processes.
- As mentioned earlier, in dialog processing, a work process is assigned to an ABAP program for the duration of a dialog step. An application program can be divided into several program sections and, in the case of dynpros, into several dialog steps that are processed sequentially by different work processes.
- For example, in the context of a dynpro, when a dialog step that is waiting for user interaction completes, the work process is released (for another workload) and a new work process is assigned. The current workload is persisted and resources are released. This approach requires an (implicit) database commit that ends the database LUW.
- A work process can execute only a single database LUW. It cannot interfere with the database LUWs of other work processes.
<p align="right">(<a href="#top">⬆️ back to top</a>)
## SAP LUW Overview
For an [SAP LUW](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_luw_glosry.htm), the following aspects come into play:
- Usually, an SAP LUW is started by opening a new [internal session](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abeninternal_session_glosry.htm). The execution of programming units can be distributed among several work processes.
- Database commits persist data in the database (especially implicit database commits when work processes are switched).
- The all-or-nothing rule applies: All database changes that occur during a transaction constitute a logical unit of work. They must be committed together, or rolled back together in the event of an error.
- This means that all database changes must be deferred and made in a final database commit (that is, in a single database LUW) at the end of a transaction - not in between.
- To ensure data consistency, all database changes are bundled, for example, in temporary tables or transactional buffers, and then, at the end of the transaction, all changes are written to the database together in a single work process, that is, in a single database LUW with a single database commit. This can be done directly using ABAP SQL statements at this stage, or using bundling techniques - special ABAP programming techniques.
Using the above bank transfer as an example:
- At the end of the transaction, the new totals of both accounts are updated (money is debited from account A and credited to B).
- You cannot debit account A in one work process and then credit account B in a separate work process. When the work process changes, new totals would be available in one account, but not in the other. Consider the consequences if an error occurs and the new totals for account B cannot be updated, and so on. You would no longer be able to easily roll back the changes.
- Consider prematurely updating the database and notifying the users or processing the data while the logical unit has not been successfully completed.
<p align="right">(<a href="#top">⬆️ back to top</a>)
### Bundling Techniques
The following bundling techniques are available for classic ABAP. This means that programming units are registered in different work processes, but are executed by a single work process. All database changes are put into one database LUW, and all changes are committed in one final database commit.
**Using [update function modules](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenupdate_function_module_glosry.htm)**
- Are specially marked, i.e. the *update module* property is marked
- Can be given specific attributes to determine the priority with which they are processed in the update work process
- Usually contain database modification operations/statements
- [CALL FUNCTION ... IN UPDATE TASK](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcall_function_update.htm) statements are used to register the update function modules for later execution; the actual execution is triggered by a `COMMIT WORK` statement
- Example of a simple update function module that has an importing parameter (a structure that is used to modify a database table)
```abap
FUNCTION zsome_update_fu_mod
IMPORTING
VALUE(values) TYPE some_dbtab.
MODIFY some_dbtab FROM values.
ENDFUNCTION.
```
- Depending on your use case, you can run the update work process in several ways:
- [Synchronous update](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensynchronous_update_glosry.htm): The calling program waits until the update work process has finished. The `COMMIT WORK` statement with the `AND WAIT` addition triggers a synchronous update in a separate update work process.
- [Asynchronous update](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenasynchronous_update_glosry.htm): The calling program does not wait for the update work process to finish. The `COMMIT WORK` statement triggers an asynchronous update in a separate update work process.
- [Local update](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenlocal_update_glosry.htm): The update is performed immediately in the current work process in a separate internal session and not in a separate update work process, so that a synchronous update is always performed (regardless of whether `COMMIT WORK` is used with `AND WAIT` or not). By default, the local update is deactivated at the start of each SAP LUW. If required, you can activate local update for an SAP LUW using the [`SET UPDATE TASK LOCAL`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapset_update_task_local.htm) statement before registering the update function modules.
```abap
"Synchronous update
DATA(st_a) = VALUE some_type( ... ).
...
"Registering the update function module specified in uppercase letters
CALL FUNCTION 'ZSOME_UPDATE_FU_MOD' IN UPDATE TASK
EXPORTING values = st_a.
...
"Triggering the synchronous update
COMMIT WORK AND WAIT.
***********************************************************************
"Asynchronous update
DATA(st_b) = VALUE some_type( ... ).
...
CALL FUNCTION 'ZSOME_UPDATE_FU_MOD' IN UPDATE TASK
EXPORTING values = st_b.
...
"Triggering the asynchronous update
COMMIT WORK.
***********************************************************************
"Local update
"Before update function modules are registered.
SET UPDATE TASK LOCAL.
DATA(st_c) = VALUE some_type( ... ).
...
CALL FUNCTION 'ZSOME_UPDATE_FU_MOD' IN UPDATE TASK
EXPORTING values = st_c.
...
"The update will be synchronous.
COMMIT WORK.
```
> **💡 Note**<br>
> If a runtime error occurs during the update, the update work process executes a database rollback, and notifies the user whose program created the entries.
**Using [remote-enabled function modules](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenremote_enabled_fm_glosry.htm)**
- Also in this case, the bundling is done through function modules.
- They are also specially marked as remote-enabled function modules.
- For example, you can use register them for later asynchronous execution in the background and through the [RFC interface](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenrfc_interface_glosry.htm) ([background Remote Function Call (bgRFC)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenbg_remote_function_glosry.htm)). With this technology, you can make calls in the same or different ABAP systems.
- More information:
- [SAP Help Portal documentation about RFC](https://help.sap.com/docs/ABAP_PLATFORM_NEW/753088fc00704d0a80e7fbd6803c8adb/4888068AD9134076E10000000A42189D)
- [`CALL FUNCTION ... IN BACKGROUND UNIT`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcall_function_background_unit.htm)
**Using [subroutines](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensubroutine_glosry.htm)**
- Subroutines that are no longer recommended for use can be registered for later execution.
- They are registered with the [`PERFORM ... ON COMMIT`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapperform_on_commit.htm) statement. These subroutines are executed when a `COMMIT WORK` statement is called.
- An addition is available to control the order of execution.
- Similarly, a subroutine can be registered "on rollback" with [`PERFORM ... ON ROLLBACK`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapperform_on_commit.htm). These subroutines are executed when a `ROLLBACK WORK` statement is called.
- When executed:
- In the current work process, before update function modules.
- When they are registered in an update function module with `ON COMMIT`, they are executed at the end of the update. This happens in the update work process for non-local updates, and in the current work process for local updates.
<p align="right">(<a href="#top">⬆️ back to top</a>)
### Related ABAP Statements
An SAP LUW is usually started by opening a new internal session.
The statements to end an SAP LUW have already been mentioned above: [`COMMIT WORK [AND WAIT]`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcommit.htm) and [`ROLLBACK WORK`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abaprollback.htm).
`COMMIT WORK [AND WAIT]`
- Closes the current SAP LUW and opens a new one.
- Commits all change requests in the current SAP LUW.
- Among other things, this statement triggers ...
- the processing of all registered update function modules.
- the update work process and the local updates in the current work process.
- a database commit for all currently open [database connections](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendatabase_connection_glosry.htm), which also terminates the current database LUW.
- Note that `COMMIT WORK` triggers an asynchronous, `COMMIT WORK AND WAIT` a synchronous update.
`ROLLBACK WORK`
- Similar to `COMMIT WORK` statements, this statement closes the current SAP LUW and opens a new one.
- Among other things, this statement ...
- causes all changes within a SAP LUW to be undone, that is, all previous registrations for the current SAP LUW are removed.
- triggers a database rollback on all currently open database connections, which also terminates the current database LUW.
> **💡 Note**<br>
> Notes on database connections:
> - The [database interface](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendatabase_interface_glosry.htm) uses the [standard connection](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_db_connection_glosry.htm) of the current work process to access the [standard database](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_db_glosry.htm) by default.
> - Optionally, database accesses can also be made by using [secondary connections](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensecondary_db_connection_glosry.htm) to [secondary databases](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensecondary_db_glosry.htm) or by using [service connections](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenservice_connection_glosry.htm) to the standard database. The secondary connections are usually used by technical components. For example, they are used for caches, traces, logs, and so on.
> - The implicit database rollback is performed on all database connections that are currently open.
> - Within the SAP LUW, database changes and commits are allowed on service connections or through secondary database connections.
<p align="right">(<a href="#top">⬆️ back to top</a>)
## Concepts Related to the SAP LUW
The following concepts are related to the SAP LUW to ensure transactional consistency. They are not discussed in detail here. For more information, see the links.
**Authorization concept**
- In an SAP system, you need to protect data from unauthorized access by making sure that only those [authorized](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenauthorization_glosry.htm) to access it can see and modify it.
- Authorization to access data can be set. Before a user can perform certain operations in your application, you need to implement authorization checks.
- Since ABAP SQL statements do not trigger any [authorization checks](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenauthorization_check_glosry.htm) in the database system, this is even more important. Database tables may be accessed without restriction using these statements. Conversely, not all users in a system are authorized to access all data available to ABAP SQL statements.
- Thus, it is up to the programmer to ensure that each user who can call the program is authorized to access the data it handles.
- More information:
- [Authorizations](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbc_authority_check.htm)
- [`AUTHORITY-CHECK`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapauthority-check.htm)
**Lock concept**
- The database system automatically sets [database locks](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendatabase_lock_glosry.htm) when ABAP SQL statements are called to modify database table entries.
- These locks are implemented by automatically setting a lock flag, which can only be set for existing database table entries.
- After a database commit, these flags are removed.
- As a result, database locks are not available for more than one database LUW, which must be considered in the context of an SAP LUW, since multiple database LUWs may be involved. Therefore, the lock flags that are set in a transaction are not sufficient. For the duration of an entire SAP LUW, a lock on database entries must remain set.
- This is where the SAP lock concept comes into play, which is independent of the automatic database locks. It is based on [lock objects](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenlock_object_glosry.htm).
- Lock objects ...
- are [repository objects](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenrepository_object_glosry.htm) that are defined in the [ABAP Dictionary](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_dictionary_glosry.htm).
- specify the database tables in which records are to be locked with a lock request.
- contain the key fields on which a lock is to be set.
- When a lock object is created, two [lock function modules](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenlock_function_module_glosry.htm) (`ENQUEUE_...` and `DEQUEUE_...`) are automatically generated. They are executed in a special enqueue work process. When a record is locked during a transaction (by the enqueue function module), a central lock table is filled with the table name and key field information. Unlike database locks, a locked entry in a lock object does not necessarily have to exist in a database table. Also, the locking must be done proactively, i. e. there is no automatic locking. You must make sure that the application implementation checks the lock entries.
- At the end of an SAP LUW, all locks should be released, either automatically during the database update or explicitly when you call the corresponding dequeue function module.
- More information: [SAP Locks](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_lock.htm)
> **💡 Note**<br>
> RAP comes with its own implementation features to cover these concepts. See the topics [Authorization Control](https://help.sap.com/docs/SAP_S4HANA_CLOUD/e5522a8a7b174979913c99268bc03f1a/375a8124b22948688ac1c55297868d06.html) and [Concurrency Control](https://help.sap.com/docs/SAP_S4HANA_CLOUD/e5522a8a7b174979913c99268bc03f1a/d315c13677d94a6891beb3418e3e02ed.html) in the *Development guide for the ABAP RESTful Application Programming Model*.
<p align="right">(<a href="#top">⬆️ back to top</a>)
## Notes on the SAP LUW in ABAP Cloud and RAP
A limited set of ABAP language features is available in ABAP Cloud ([restricted ABAP language version](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenrestricted_version_glosry.htm)).
The limitations include the fact that the above bundling techniques are not available. Note that the local update is enabled by default in ABAP Cloud. Find more information in this [blog](https://blogs.sap.com/2022/12/05/the-sap-luw-in-abap-cloud/).
In fact, RAP is the transactional programming model for ABAP Cloud.
And RAP comes with a well-defined transactional model and follows the rules of the SAP LUW. At the end of an SAP LUW in RAP, database modification operations should be performed in a final step in the [RAP late save phase](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenlate_rap_save_phase_glosry.htm) by persisting the consistent data in the [RAP transactional buffer](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentransactional_buffer_glosry.htm) to the database.
There are RAP-specific, [ABAP EML](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_eml_glosry.htm) statements for commit and rollback:
- [`COMMIT ENTITIES`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcommit_entities.htm) implicitly triggers `COMMIT WORK`. Furthermore, `COMMIT ENTITIES` provides RAP-specific functionality with various additions. These EML statements implicitly enforce local updates with `COMMIT WORK`, or `COMMIT WORK AND WAIT` if the local update fails. Therefore, the update is either a local update or a synchronous update, but never an asynchronous update.
- [`ROLLBACK ENTITIES`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abaprollback_entities.htm): Resets all changes of the current transaction and clears the transactional buffer. The statement triggers `ROLLBACK WORK`.
## More Information
- [The RAP Transactional Model and the SAP LUW](https://help.sap.com/docs/SAP_S4HANA_CLOUD/e5522a8a7b174979913c99268bc03f1a/ccda1094b0f845e28b88f9f50a68dfc4.html) (Development guide for the ABAP RESTful Application Programming Model)
- [The SAP LUW in ABAP Cloud](https://blogs.sap.com/2022/12/05/the-sap-luw-in-abap-cloud/) (blog)
- [Cheat sheet about ABAP EML](08_EML_ABAP_for_RAP.md)
<p align="right">(<a href="#top">⬆️ back to top</a>)
## Executable Example
Coming soon ...

719
18_Dynpro.md Normal file
View File

@@ -0,0 +1,719 @@
<a name="top"></a>
# Dynpro
- [Dynpro](#dynpro)
- [Introduction](#introduction)
- [About Dynpros](#about-dynpros)
- [Dynpro Flow Logic](#dynpro-flow-logic)
- [Dialog Modules](#dialog-modules)
- [Transporting Data between Dynpros and the ABAP Program](#transporting-data-between-dynpros-and-the-abap-program)
- [Dynpro Fields](#dynpro-fields)
- [OK Field and Function Codes](#ok-field-and-function-codes)
- [Program-Controlled Data Transport](#program-controlled-data-transport)
- [Calling Dialog Modules Conditionally](#calling-dialog-modules-conditionally)
- [Input Checks](#input-checks)
- [Field and Input Help](#field-and-input-help)
- [Dnypro Sequence, Calling and Leaving Dynpros](#dnypro-sequence-calling-and-leaving-dynpros)
- [Dynpro Sequence](#dynpro-sequence)
- [ABAP Statements for Calling and Leaving Dynpros](#abap-statements-for-calling-and-leaving-dynpros)
- [Modifying Static Attributes of Screen Elements](#modifying-static-attributes-of-screen-elements)
- [Statements for the GUI Status and Title](#statements-for-the-gui-status-and-title)
- [Controls](#controls)
- [Table Controls](#table-controls)
- [Tabstrips Controls](#tabstrips-controls)
- [GUI Controls](#gui-controls)
- [More Information](#more-information)
- [Example](#example)
## Introduction
⚠️ The content of this cheat sheet is only relevant to [classic ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenclassic_abap_glosry.htm).
[User interfaces (UI)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenuser_interface_glosry.htm) are not limited to displaying some information, they must also allow the user to interact with the program.
In modern UI technologies, this can be achieved through [events](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenevent_glosry.htm), i.e. [user actions](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenuser_action_glosry.htm) on a UI trigger events, and UI methods register these events and react accordingly. In this way, users control the program flow through their actions.
In the early days of ABAP, classes, methods, and events did not exist. Program flow control had to be achieved in other ways.
This is where [dynpros](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynpro_glosry.htm) (dynamic programs) representing a classic ABAP UI technology come into play.
This cheat sheet provides a high-level introduction to dynpro topics with a focus on dynpro-related statements, supported by an executable example to check the syntax in action.
> **💡 Note**<br>
> - Classic dynpros are outdated for application programs. New developments should use web-based UIs, such as SAPUI5 or Web Dynpro.
> - Dynpros cannot be created in ABAP Cloud.
> - This cheat sheet ...
> - is not intended to encourage you to start creating dynpros for programming new applications.
> - does not cover all facets, techniques, and keywords in great detail.
> - is intended to touch on a selection of dynpro-related topics and syntax that you may encounter in older ABAP code. If you need more information, always consult the ABAP Keyword Documentation.
> - Some of the statements described here - the ones used in the dynpro flow logic - are programmed in a special programming language. Although it looks like ABAP, it is not ABAP.
> - Links to the ABAP Keyword Documentation in this cheat sheet refer to the documentation for [Standard ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_abap_glosry.htm) (latest version).
## About Dynpros
- Stands for dynamic program, i.e. the program execution is dynmically controlled by user interactions
- Can only be defined in [function groups](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenfunction_group_glosry.htm), [module pools](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenmodul_pool_glosry.htm) (not [class pools](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenclass_pool_glosry.htm)) and [executable program](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenexecutable_program_glosry.htm) (*reports*; the focus in the cheat sheet is on the latter)
- Can be identified by a unique, four-digit [dynpro number](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynpro_number_glosry.htm) in an [ABAP program](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_program_glosry.htm). Note that leading zeros need not be specified when calling the dynpro. Number 1000 is reserved, as are other dynpro number ranges (e.g. used by SAP). The current dynpro can be retrieved using `sy-dynnr`.
- Is displayed in a window of [SAP GUI](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_gui_glosry.htm)
- Consists of 3 main aspects:
- Specific characteristics when creating the dynpro. To name a few:
- Dynpro type: Defines whether the dynpro is displayed in the full GUI window (if *Normal* is selected), in a pop-up window (*Modal Dialog Box*), or as a subscreen in a specific area within another dynpro in the same ABAP program.
- [Next dynpro](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abennext_dynpro_glosry.htm): Statically specifies the next dynpro to be displayed in a [dynpro sequence](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynpro_sequence_glosry.htm). Setting the next dynpro to 0 or leaving the attribute blank will make the current dynpro the last dynpro in the sequence. If the next dynpro number is the same as the current dynpro, the dynpro continues to be called. The static next dynpro can be overwritten temporarily and dynamically in the ABAP program.
- [Screen layout](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenscreen_glosry.htm):
- Has [screen elements](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenscreen_element_glosry.htm) and is visible to users
- Screen elements are, for example, checkboxes, radio buttons, custom controls, dropdown list boxes, pushbuttons, input/output fields, subscreens, table controls, tabstrip controls, text fields, and status icons.
- To add screen elements, use the [layout editor](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenlayout_editor_glosry.htm) of the [screen painter](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenscreen_painter_glosry.htm) tool. It is available only in the [ABAP Workbench](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_workbench_glosry.htm).
- For each screen element, you can define various static properties (attributes) that control its appearance. Double-clicking a screen element in the layout editor opens the attribute maintenance dialog box.
- Various static attributes of the screen elements can be overwritten dynamically from within the ABAP program using special statements.
- Has its own data objects, called [dynpro fields](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynpro_field_glosry.htm) (see more below)
- Is called either by another dynpro (as the next dynpro), by a [transaction code](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentransaction_code_glosry.htm) ([dialog transaction](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendialog_transaction_glosry.htm)), or by ABAP statements (e.g. `CALL SCREEN`). Several dynpros in a single ABAP program can be called in sequence to form a dynpro sequence.
> **💡 Note**<br>
> There are special dynpros ([selection screens](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenselection_screen_glosry.htm), [classic lists](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenclassic_list_glosry.htm)). They are created implicitly.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Dynpro Flow Logic
- Represents the procedural part of a dynpro
- Controls the dynpro processing, fills and processes the dynpro fields
- Is defined in the *Flow Logic* tab in the screen painter
- Has its own programming language, similar to ABAP, but runs in AS ABAP
- Contains [processing blocks](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenprocessing_block_glosry.htm) introduced by special keywords
- The processing blocks are executed in response to the [PAI](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenpai_glosry.htm), [PBO](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenpbo_glosry.htm), [POH](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenpoh_glosry.htm), and [POV](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenpov_glosry.htm) events of the corresponding ABAP program, and call [dialog modules](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendialog_module_glosry.htm):
- `PROCESS BEFORE OUTPUT` (often also abbreviated as PBO):
- Triggered by the ABAP runtime framework and processed before the dynpro is displayed
- Dialog modules can be called at the PBO event. They are mainly used to prepare the dynpro display, for example, by pre-populating input/output fields.
- When the dynpro is presented to the user, and the user has made entries and wants to leave the dynpro, the PAI event is triggered, for example, when a button is clicked.
- `PROCESS AFTER INPUT` (PAI),
- Processed after a user action on the dynpro
- The dialog modules called at PAI evaluate the user entries and process them.
- When the processing is complete, the processing of the current dynpro ends and the next dynpro is called.
> **💡 Note**<br>
> - The PAI processing of the current dynpro and the PBO processing of the next dynpro take place one after the other in the same [work process](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenwork_process_glosry.htm) on the application server and together form a dialog step.
> - As soon as the screen is ready for input again, only the presentation server is active until the next user action. During this time, the ABAP program waiting for user input does not occupy a work process on the application server.
- The other events are triggered when the user requests a field or input help for a field:
- `PROCESS ON HELP-REQUEST` (POH)
- `PROCESS ON VALUE-REQUEST` (POV)
Example:
```abap
PROCESS BEFORE OUTPUT.
... "Here, for example, modules can be called.
PROCESS AFTER INPUT.
...
"When you implement field or value helps, use the following processing blocks.
PROCESS ON HELP-REQUEST.
...
PROCESS ON VALUE-REQUEST.
...
```
The following statements are among the non-ABAP statements in the dynpro flow logic. They are covered briefly below.
- `MODULE` for calling dialog modules
- `FIELD` for controlling the data transport between dynpro fields and the ABAP program
- `CHAIN` and `ENDCHAIN` for combining module calls
- `LOOP` and `ENDLOOP` for processing lines of a table control (similar to the ABAP statement `LOOP`)
- `CALL SUBSCREEN` for calling the flow logic of a subscreen
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Dialog Modules
- Are processing blocks in an ABAP program
- Represent the procedural link between the dynpro and the ABAP program.
- Are implemented between the statements [`MODULE`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapmodule.htm) and [`ENDMODULE`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapendmodule.htm).
- In the [dynpro flow logic](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynpro_flow_logic_glosry.htm), they are called using the `MODULE some_module_9000.` statement, which calls an ABAP processing block called `some_module_9000`.
- By calling dialog modules during the PBO, PAI, POH, and POV events of the dynpro, the dynpro controls the flow of the associated ABAP program.
- Do not have a parameter interface. The data transport between the dynpro fields and the ABAP program therefore takes place exclusively through the global variables of the ABAP program assigned to the dynpro fields (see below).
- Do not have a local data area. Data object declarations in dialog modules result in global variables of the program. If you really need local data declarations in this context, you can make local data declarations in a method in a local class of the program and call the method.
- Within the dynpro processing block(s) ...
- `PROCESS BEFORE OUTPUT`, the dynpro statement `MODULE` can only be used to call dialog modules that were defined with the `OUTPUT` addition.
- `PROCESS AFTER INPUT`, `PROCESS ON HELP-REQUEST`, and `PROCESS ON VALUE-REQUEST`, only the dialog modules defined with the `INPUT` addition can be called.
- Are not associated with a specific dynpro and can therefore be called from different dynpros.
- You can choose random names for the dialog modules. The name chosen in the example indicates that they are modules for a dynpro with the number 9000.
Calling dialog modules in the dynpro flow logic:
```abap
"Flow Logic tab in the screen painter
PROCESS BEFORE OUTPUT.
MODULE pbo_9000.
PROCESS AFTER INPUT.
MODULE pai_9000.
```
Implementation of the dialog modules in the ABAP program
```abap
MODULE pbo_9000 OUTPUT.
...
ENDMODULE.
MODULE pai_9000 INPUT.
...
ENDMODULE.
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Transporting Data between Dynpros and the ABAP Program
### Dynpro Fields
- The transport of data between dynpros and the ABAP program is performed using [dynpro fields](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynpro_field_glosry.htm).
- Dynpro fields are the [data objects](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendata_object_glosry.htm) of dynpros. They are data objects in the working memory of a dynpro.
- All dynpro fields, except the [*OK field*](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenok_field_glosry.htm), are linked to a screen element. See the *Element List* tab of dynpros.
- The data types of dynpro fields are determined either by reference to built-in [ABAP Dictionary (DDIC)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_dictionary_glosry.htm) data types (except `CLNT` and `FLTP`) or by reference to global data objects of the ABAP program. An advantage of DDIC types is that additional properties are available for display on the user interface, including description texts, field help, and input help.
- The actual transport of the data is done in the following way:
- As a prerequisite, ...
- you have created a screen element, such as an input field in a dynpro.
- You have assigned a name for this screen element - which is the name of the dynpro field.
- you have created a data object with the same name as the dynpro field in the ABAP program.
- During PBO: You can assign a value to the data object, such as *demo text* for the input field, to prefill that input field. Or you can make no assignment to leave the input text blank.
- During PAI: After the PBO, the content of data objects are passed to dynpro fields of the same name.
- This is a two-way street: For example, when the user enters data in an input field, the data object in the ABAP program receives the value of the dynpro field.
- By default, all dynpro fields are transported directly to the ABAP program at the start of the PAI event (that is, at the start of a dialog step) and before the corresponding event block is processed. The reverse transport from the ABAP program to the dynpro takes place at the end of the dialog step, in the context of the PBO event.
- About declaring data objects in the ABAP program in the global declaration part:
- You can use a global variable with `DATA` or a public static attribute of a local class with `CLASS-DATA`.
- You can use a [`TABLES`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abaptables.htm) statement:
- Declares a [table work area](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentable_work_area_glosry.htm), i.e. a structure whose data type is taken from the identically named structured data type from the ABAP Dictionary
- Since it refers to a flat structure in the ABAP Dictionary, it is used to provide all the additional semantic information that is not available when you use `DATA` or `CLASS-DATA`.
- A [CDS entity](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abencds_entity_glosry.htm) cannot be specified after `TABLES`.
- Note that you can control the data transport explicitly (see below).
Example:
```abap
PROGRAM some_program.
"Variable declarations
DATA some_dobj TYPE abap_bool.
TABLES some_struct.
CLASS local_class DEFINITION.
PUBLIC SECTION.
CLASS-DATA: another_dobj TYPE i.
...
ENDCLASS.
CLASS demo IMPLEMENTATION.
...
ENDCLASS.
```
### OK Field and Function Codes
- Each dynpro contains a twenty-character [*OK field*](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenok_field_glosry.htm), which is a dynpro field that is not associated with a screen element.
- It is implicitly declared when a dynpro is created. It is the last entry in the *Element List* tab of the dynpro. Note that the *OK field* must be given a name, for example, `ok_code`.
- The *OK field* is relevant to [function codes](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenfunction_code_glosry.htm):
- A function code (a sequence of up to 20 characters) can be assigned to specific control elements (for example, a pushbutton, a menu item, and so on) in SAP GUI.
- When a user action is performed on a control, such as clicking a button, the PAI event is triggered. If the button is linked to a function code, the function code is placed in the *OK field* and passed to a data object of the same name.
- You can then evaluate the value in the ABAP program, for example, in a [`CASE`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcase.htm) control structure if you have multiple function codes for different control elements, and implement a response accordingly.
- Notes on working with the *OK field*:
- As with the other dynpro fields, a data object must be created in the ABAP program.
- The system field `sy-ucomm` automatically receives the value of the function code. However, it is recommended that you work with the *OK field* instead of `sy-ucomm`. You have full control over the fields you declare. Also, the value of an ABAP system field should not be changed.
- It is recommended that you store the function code in an auxiliary variable and initialize the*OK field* field in an ABAP program. This ensures that the function code of a dynpro is not filled with an unwanted value in the PBO event (for example, the next PAI event can be triggered with an empty function code). You can then read the function code from the auxiliary variable (for example, using a `CASE` structure) and control the program flow from there.
- The *OK field* field can have a different name on each dynpro. However, it is recommended that you use the same name for the field in each dynpro of an ABAP program. This way, you only need one field with the same name in the ABAP program, in which the function code is placed and from which you can read it.
- In addition to screen elements, function codes can also be linked to various things in the dynpro, e.g. the definition of the menu bar takes place in the GUI status. They also trigger a PAI event.
Example:
```abap
PROGRAM zdemo_program.
"OK field declaration and auxiliary variable, assuming the OK field is called
"ok_code in the Element List tab of the dynpro.
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE ok_code.
...
"Dialog modules in the program
"PBO
MODULE pbo_9000 OUTPUT.
...
"Prefill the value for a screen element, e.g. input field
some_input_field = 'Hallo'.
...
ENDMODULE.
"PAI
MODULE pai_9000 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
"For example, a button is linked with a function code named PUSH
WHEN 'PUSH'.
...
WHEN 'ENTER'.
...
WHEN 'CANCEL'.
...
WHEN OTHERS.
...
ENDCASE.
ENDMODULE.
...
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Program-Controlled Data Transport
- In addition to the automatic data transport between the dynpro and the ABAP program, that is, between the dynpro fields and the global ABAP variables of the same name, you can also use [`FIELD`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynpro_field_abexa.htm) statements for program-controlled data transport in the *Flow Logic* tab.
- These statements control the data transport from the dynpro to the ABAP program during the PAI event.
- Only those dynpro fields that are not specified after a `FIELD` statement are transported directly.
- In doing so, you can specify the time of the transport from the dynpro to the ABAP program.
- One or more `FIELD` statements are possible, that is, the contents of dynpro fields specified after `FIELD` are transported to the global ABAP data object of the same name when the corresponding `FIELD` statement is executed.
- In the flow logic, the statements are implemented in the processing block `PROCESS AFTER INPUT`.
Example:
```abap
"Note: More syntax options are possible with the FIELD statement.
"See some of them below and more details in the ABAP Keyword Documentation.
PROCESS AFTER INPUT.
MODULE pai_9000. "both field_a and field_b are not available
FIELD field_a.
MODULE module_a. "field_a is available, field_b is not
FIELD field_b.
MODULE module_b. "both field_a and field_b are available
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Calling Dialog Modules Conditionally
- By combining the `FIELD` statement with the `MODULE` statement, you can make the call of PAI modules dependent on conditions.
- The following statement in the flow logic calls the dialog module `mod` only if the dynpro field `dynp_field` is not empty:
```abap
FIELD dynp_field MODULE mod ON INPUT.
```
- To call a module `mod` only if the value of a dynpro field `dynp_field` has been changed (or just overwritten with the same value) by the user since the last PBO, use the following:
```abap
FIELD dynp_field MODULE mod ON REQUEST.
```
- Conditional module calls can be combined into processing chains to make processing dependent on multiple dynpro fields.
- A processing chain is defined using the dynpro statements [`CHAIN`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=dynpchain.htm) and [`ENDCHAIN`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=dynpendchain.htm):
```abap
CHAIN.
FIELD dynp_field1.
FIELD dynp_field2.
...
MODULE mod ON CHAIN-INPUT.
"Note: ON REQUEST is also possible
ENDCHAIN.
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Input Checks
- Automatic input checks
- Are performed in the PAI event before data is transported to the ABAP program and before dialog modules are called.
- If an error is detected, it is displayed in the status bar, and the affected input fields remain ready for input.
- Further PAI processing is not started until the user has successfully corrected the input.
- For example, automatic input checks are performed for required fields: Input fields marked as `required` in the screen painter must be filled in by the user.
- Exit command
- Since the automatic input checks are implicit, the user is always forced to make a valid input before the ABAP program can react.
- This is inconvenient in cases where users have changed their minds and only want to cancel processing. For this reason, there is a special function type exit command (`E`), which allows you to bypass the automatic input checks.
- You can choose this function type in the screen painter for screen elements with function codes, or in the menu painter for function codes.
- Such a function code bypasses the automatic input checks and leads directly to the call of a special dialog module using the following statement in the screen flow logic:
```abap
MODULE mod AT EXIT-COMMAND.
```
- Within the dialog module called in this way, you should end processing with an appropriate `LEAVE` statement. Otherwise, the normal PAI processing, which includes the automatic input checks, starts after the dialog module has been executed.
- Self-programmed input checks
- For input checks that go beyond the automatic checks, you can program special dialog modules in which you can issue a warning (message of type `W`) or error message (`E`) using the ABAP statement [`MESSAGE`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapmessage.htm).
- These dialog modules are called in the flow logic using the `FIELD` and `CHAIN` statements.
- To check a single field, use the `FIELD` statement as follows:
```abap
FIELD dynp_field MODULE mod.
```
- Within the dialog module `mod`, program your input validation and trigger a warning or error message if an error occurs. The field in question is the only field that is ready for input again, and users can (in the case of a warning) or must (in the case of an error message) correct their input before the dynpro can be successfully exited.
- To check several semantically related input fields, define a processing chain using the `CHAIN` statement:
```abap
CHAIN.
FIELD dynp_field1.
FIELD dynp_field2.
...
MODULE mod.
ENDCHAIN.
```
- If a warning or error message is triggered in the `mod` dialog module, all fields listed in the processing chain are ready for input again. In this way, users can correct an input that consists of several closely related individual fields, and where it is not clear from the start which of the individual fields users must change in order to create a valid input as a whole.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Field and Input Help
- Field help:
- Provides an explanation of the input field that appears when the user presses *F1* on a field on a screen layout.
- When you create input fields with reference to DDIC types, you can benefit from data element documentation (which you can create yourself if it does not exist). This documentation is then automatically displayed when the user requests F1 help.
- You can program field help yourself. You can call your own dialog modules for the POH event and program any help functions there:
```abap
PROCESS ON HELP-REQUEST
FIELD dynp_field MODULE mod.
```
- At this point, the `FIELD` statement does not transport any data to the ABAP program, since field help is always independent of user input. In the `mod` dialog module, you must then display the appropriate help yourself. You can do this by calling the function module `HELP_OBJECT_SHOW`, for example, or by using GUI controls.
- Input help:
- List of values displayed when *F4* is chosen for a field on the screen layout
- This help can either come from the ABAP Dictionary or be self-programmed.
- There are several ways to create helps in the ABAP Dictionary. For more information, see the topic [Input Helps in the ABAP Dictionary](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_dynpros_value_help_auto.htm).
- If the built-in input helps in the ABAP Dictionary and the search help exits are not sufficient for your purposes, you can program your own input helps. In this case, you can call your own dialog modules for the event POV and program input helps there.
```abap
PROCESS ON VALUE-REQUEST
FIELD dynp_field MODULE mod.
```
- As with the POH event, the `FIELD` dynpro statement does not transport data between the dynpro field and the ABAP variable. You must therefore program the data transport yourself by calling the function modules `DYNP_VALUES_READ` and `DYNP_VALUES_UPDATE`. The function module `F4IF_INT_TABLE_VALUE_REQUEST`, which you can call in your dialog module, receives an internal table as a value list and transfers the dialog with the user and the data transport for you.
- [Dropdown list box](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendropdown_listbox_glosry.htm)
- A special form that can be linked to an input field.
- When an input field is linked to a dropdown list box, the input value can only be selected from the list. Dropdown list boxes are therefore suitable for cases where the list of values is not too extensive and no other values than those in the list are allowed.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Dnypro Sequence, Calling and Leaving Dynpros
### Dynpro Sequence
- The [dynpro sequence](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynpro_sequence_glosry.htm) is a sequence of different dynpros that are presented to the user one after the other.
- The first dynpro in a dynpro sequence is the [initial dynpro](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abeninitial_dynpro_glosry.htm).
- The flow of the dynpros is determined by the next dynpro for each dynpro involved.
- Each dynpro has a next dynpro.
- The next dynpro is defined either statically (the number you enter in the dynpro properties) or in the ABAP program using statements which temporarily and dynamically overwrite the static definition of the next dynpro.
- This means that the next dynpro is automatically called when the current dynpro is exited, i.e. when the PAI processing is finished, the current dynpro is also finished and the next dynpro is called.
- A dynpro is normally exited when the end of PAI processing is reached.
- If a dynpro is connected to a next dynpro with the dynpro number 0 (this dynpro does not exist), it is the last dynpro of the dynpro sequence.
- All dynpros in a dynpro sequence are displayed in the same GUI window.
- Starting a dynpro sequence: When calling transaction codes (in a dialog transaction, the dynpro associated with the transaction code) or using a `CALL SCREEN` statement (the initial dynpro is the dynpro specified in this statement).
- Ending a dynpro sequence: As mentioned above, a dynpro sequence is terminated when the next dynpro with a dynpro number of 0 is called.
- The simplest dynpro sequence consists of a single dynpro with 0 as the next dynpro.
- When the current dynpro sequence is finished, the system returns to the previous dynpro sequence if the current dynpro sequence was nested.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### ABAP Statements for Calling and Leaving Dynpros
[`SET SCREEN dynnr.`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapset_screen.htm)
- Sets the next dynpro
- Dynamically and temporarily overwrites the static definition and/or a previously set next dynpro
- Can also be 0
- The next dynpro is automatically called when the end of PAI processing for the current dynpro is reached. If the next screen number is 0, the current dynpro sequence is terminated.
```abap
"Assumption: The static next dynpro is 9100.
"With the statement, the next dynpro is dynamically set and 9100 overwritten.
SET SCREEN 9200.
***************************
"The current dynpro sequence is terminated.
SET SCREEN 0.
```
[`CALL SCREEN dynnr.`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcall_screen.htm)
- Starts a new dynpro sequence, which is embedded in the current dynpro sequence.
- The dynpro that is specified is the initial dynpro of the dynpro sequence.
- This allows nested dynpro sequences to be created, i.e. if a dynpro sequence was already running at the time of the call, the newly started dynpro sequence is embedded in the already running one.
- By default, all the dynpros of the called dynpro sequence are displayed in the current GUI window.
```abap
"Starting a new dynpro sequence
CALL SCREEN 9300.
```
- The `STARTING AT` and `ENDING AT` additions can be used to open a dynpro in a modal dialog box, i.e. a dynpro is displayed in a popup over the previous dynpro.
```abap
"Opening a dynpro in a modal dialog box
CALL SCREEN dynnr STARTING AT col_up_left line_up.
CALL SCREEN dynnr STARTING AT col_up_left line_up ENDING AT col_up_right line_low.
```
- The specifications (integer values) for `STARTING AT` and `ENDING AT` define the position of the dialog box with respect to the previous dynpro and its size:
`col_up_left` and `line_up` stand for values for the column for the upper left corner and the upper line of the dialog box. The values refer to the GUI window with popup level 0 (maximum popup level is 9). The right column and lower line is set automatically or explicitly by specifying `col_up_right` and `line_low`. The values of `col_up_left` and `line_up` should be less than `col_up_right` and `line_low`, otherwise the behavior will be undefined.
[`LEAVE SCREEN.`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapleave_screen.htm) and [`LEAVE TO SCREEN dynnr.`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapleave_screen.htm)
- As mentioned earlier, a dynpro is normally exited at the end of PAI processing.
- `LEAVE SCREEN.` exits the current dynpro and enters the next dynpro. This is either statically defined in the properties of the current dynpro or was previously set with the `SET SCREEN` statement.
- `LEAVE TO SCREEN` does the same, but first sets the next dynpro to the specified dynpro number. This statement is a short form of the statements `SET SCREEN dynnr. LEAVE SCREEN.`.
> **💡 Note**<br>
> - The statements do not exit the entire dynpro sequence and instead branch to another dynpro in the same sequence. Only if the number 0 is used to branch to the next dynpro does a `LEAVE` statement terminate the dynpro sequence.
> - A dialog transaction can be started from an ABAP program using the [`CALL TRANSACTION`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcall_transaction.htm) or [`LEAVE TO TRANSACTION`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapleave_to_transaction.htm) statements, or directly by the user by entering the transaction code in the input field of the [standard toolbar](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_toolbar_glosry.htm). When a dialog transaction is started, the associated ABAP program is loaded and the PBO processing of the initial dynpro is called.
> - [`LEAVE PROGRAM`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapleave_program.htm) statements terminate the program.
```abap
"Assumption: The next dynpro is statically defined as 9100.
"The following statement ends the processing of the current dynpro.
"Dynpro 9100 is called.
LEAVE SCREEN.
****************************************
"The following statement ends the processing of the current dynpro.
"The statically defined dynpro 9100 is overwritten. Dynpro 9200 is called.
SET SCREEN 9200.
LEAVE SCREEN.
****************************************
"The following statement is a shorter form of the one above.
"It has the same effect.
LEAVE TO SCREEN 9200.
****************************************
"Ending the dynpro sequence
SET SCREEN 0.
LEAVE SCREEN.
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Modifying Static Attributes of Screen Elements
- For each screen element, you can define various static attributes that control, for example, its appearance or status.
- The static attributes of the screen elements can be overwritten from within the ABAP program during the PBO processing of the dynpro.
- To do this, use the ABAP statements [`LOOP AT SCREEN`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abaploop_at_screen.htm) and [`MODIFY SCREEN`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapmodify_screen.htm).
- `LOOP AT SCREEN`:
- Defines a loop over all screen elements of the current dynpro to which a dynpro field is assigned.
- A work area of type `SCREEN` should be declared.
- After the `LOOP AT SCREEN` statement, the work area contains the properties of the corresponding screen element.
- `MODIFY SCREEN`:
- Can only be used in the statement block after `LOOP AT SCREEN` and only makes sense during PBO processing.
- Expects a work area of type `SCREEN` after `FROM`.
- Modifies the properties of the current screen element with the values from the work area.
- Note the use of the values 0 and 1 by the dynpro in contrast to Boolean values in ABAP.
```abap
MODULE pbo_9000 OUTPUT.
"Assumption: An input field is not marked as required
"(i.e. the value of the component is 0).
"The example makes the input field required.
LOOP AT SCREEN INTO DATA(scr).
IF scr-name = 'SOME_INPUT_FIELD'.
scr-required = '1'.
MODIFY SCREEN FROM scr.
ENDIF.
ENDLOOP.
ENDMODULE.
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Statements for the GUI Status and Title
- [GUI status](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abengui_status_glosry.htm)
- Groups the [menu bar](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenmenu_bar_glosry.htm), [standard toolbar](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_toolbar_glosry.htm), and [application toolbar](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenapplication_toolbar_glosry.htm) of a GUI window as well as the function key settings.
- A GUI status is set using the [`SET PF-STATUS`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapset_pf-status_dynpro.htm) statement and is created using the menu painter.
```abap
"Setting the GUI status (in PBO)
SET PF-STATUS status.
****************************************
"Setting the GUI status and excluding function codes, i.e. the
"specified function codes are deactivated. fcode expects either
"a character-like data object or an internal table with a flat
"character-like line type.
SET PF-STATUS status EXCLUDING fcode.
```
- The name of the current GUI status can be obtained from the `sy-pfkey` system field and from the [`GET PF-STATUS`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapget_pf.htm) statement.
```abap
"Getting the GUI status
GET PF-STATUS status.
st = sy-pf-key.
****************************************
"The following statement inserts the function codes which are
"inactive in the current GUI status line by line into the
"internal table fcode
GET PF-STATUS status EXCLUDING fcode.
```
- [GUI title](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abengui_title_glosry.htm)
- Text that can be displayed in the title bar of a GUI window.
- A GUI title is set using the statement [`SET TITLEBAR`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapset_titlebar_dynpro.htm) and created using the menu painter.
```abap
"Setting a title (in PBO)
"Here, title is not the text content itself, but the name of a GUI title,
"a further UI component of the program.
SET TITLEBAR title.
"The name of the current GUI title is displayed in the system field sy-title.
gui_title = sy-title.
****************************************
"WITH addition
"The placeholders of a GUI title can be replaced by the formatted
"content of data objects text1, and so on.
SET TITLEBAR title WITH text1 ... text9.
```
> **💡 Note**<br>
> By separating the GUI status and title from the dynpro itself, the screen layout can remain constant when switching dynpros, and only the title and available functions can be changed.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## Controls
- Dynpro [controls](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abencontrol_glosry.htm)
- Complex screen elements with built-in functions that go beyond simple screen elements
- Require additional variables and a [`CONTROLS`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcontrols.htm) statement in the ABAP program (note that wizards are available)
- There are two types of dynpro controls:
- [Table control](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentable_control_glosry.htm) for the input and output of tabular data
- [Tabstrip control](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentabstrip_control_glosry.htm) for grouping screen elements on different tab pages
- [GUI controls](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abengui_control_glosry.htm)
- External GUI controls that are included visually in dynpros
### Table Controls
- Used to display screen elements in tabular form
- Allows users to display or edit not only individual values, but the contents of entire (internal) tables
- Declaring a table control in the ABAP program:
```abap
CONTROLS contr TYPE TABLEVIEW USING SCREEN dynnr.
```
- Result: A structure with the name of the control is created in the ABAP program. The structure components contain the properties of the table control and allow you to process the control in the ABAP program, e.g. to change and read the properties of the corresponding table control.
- For the table controls, loops must be implemented in the dynpro flow logic using [`LOOP WITH CONTROL`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=dynploop.htm) statements that process table controls.
- The loop sequentially processes the displayed lines of the table control by performing one loop pass for each table control line.
- The implementation of the loop must be done for each table control for both the PBO processing block and in the PAI processing block.
- In the loop, you can call dialog modules to process the relevant data objects in the ABAP program. For example, you can read data from an internal table at PBO and write it back to the table at PAI after processing it in the dynpro.
```abap
PROCESS BEFORE OUTPUT.
...
LOOP WITH CONTROL contr.
MODULE mod_fill_table.
ENDLOOP.
...
PROCESS AFTER INPUT.
...
LOOP WITH CONTROL contr.
MODULE mod_read_table.
ENDLOOP.
...
```
> **💡 Note**<br>
> - In a modern program, it is more comfortable to use an ALV Grid control.
> - More addiitions are available for the statement.
The ABAP statement [`REFRESH CONTROL`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abaprefresh_control.htm) initializes the properties of a table control.
```abap
"Code in an ABAP Program
...
REFRESH CONTROL contr FROM SCREEN dynnr.
...
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### Tabstrips Controls
- Allow tab pages to be displayed on dynpros
- Represent one of several available [subscreens](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensubscreen_glosry.htm) in dynpros. Users select the subscreen to be displayed using tab pages.
- Declaring a tabstrip control in the ABAP program:
```abap
CONTROLS tabstr TYPE TABSTRIP.
```
- Result: A structure with the name of the control is created in the ABAP program. From this structure, only the component `activetab` is required in the program.
- For the tabstrip controls, suitable subscreens must be called using [`CALL SUBSCREEN`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=dynpcall.htm) statements in the flow logic.
- In PBO processing, the active tab page is set by assigning the function code of a tab title to the `activetab` component. By default, the first tab page is active.
- For `CALL SUBSCREEN`, there is one variant for the PBO and one variant for the PAI event.
- PBO: `CALL SUBSCREEN sub_area INCLUDING prog dynnr.`
- Includes the subscreen dynpro of the program and the dynpro number in a subscreen area of the current dynpro. It also processes its PBO flow logic at this point. After PBO processing of the subscreen dynpro, the flow logic of the current dynpro is continued after the `CALL SUBSCREEN` statement.
- PAI: `CALL SUBSCREEN sub_area.`
- Calls the PAI flow logic of the subscreen dynpro included in the subscreen area.
Example:
```abap
"Code in a PBO dialog module
...
"Providing a dynpro number
dynnr = '9400'.
"Assign the activetab component
tabstr-activetab = 'SOME_TAB'.
"Providing teh prgram name
prog = sy-repid.
...
******************************************************
"Code in the flow logic
PROCESS BEFORE OUTPUT.
...
CALL SUBSCREEN sub_area INCLUDING prog dynnr.
...
PROCESS AFTER INPUT.
...
CALL SUBSCREEN sub_area.
...
```
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
### GUI Controls
- Are components of the presentation view of an AS ABAP.
- They are not directly integrated into the ABAP language and are therefore not part of the classic ABAP interfaces. However, they are part of the SAP GUI and are designed to integrate seamlessly with classic dynpros.
- Are relatively modern UI elements that are used, for example, to display different types of data (images, HTML pages, hierarchical trees, and so on) in different ways or to enable user input.
- Are integrated into a dynpro interface using container controls that provide a screen area for the actual GUI control (e.g. by a custom container).
- Examples of GUI controls
- Toolbar control (`CL_GUI_TOOLBAR`): Implements an application toolbar that is independent of the GUI status. The input elements are created by method calls (for example, `ADD_BUTTON`). User actions are signaled by raising ABAP Objects events (for example, `FUNCTION_SELECTED`).
- Picture control (`CL_GUI_PICTURE`): Allows to display images in BMP, JPG, or GIF format. The dynpro to be displayed is loaded using the `LOAD_PICTURE_FROM_URL` method. Events such as `PICTURE_DBLCLICK` signal user actions.
- Browser control (`CL_GUI_HTML_VIEWER`): A browser for HTML pages or XML documents on the dynpro. Special links in the document trigger the `SAPEVENT` event when the user clicks, which can then be evaluated in the ABAP program.
- Edit control (`CL_GUI_TEXTEDIT`): A simple text editor with the basic functions such as select, find, and replace on the dynpro. These functions can also be called in a program-controlled way using methods such as `FIND_AND_REPLACE`.
- Tree control: Are available in different versions (for example, `CL_GUI_SIMPLE_TREE`). They allow hierarchical relationships to be displayed in tree structures.
- ALV Grid control: Is the replacement for classic lists. It provides functions such as searching, sorting, and printing the content of the list. However, the associated class `CL_GUI_ALV_GRID` should no longer be used directly for new developments. Classes such as `CL_SALV_TABLE` encapsulate the use of the ALV Grid control and simplify the integration.
<p align="right">(<a href="#top">⬆️ back to top</a>)</p>
## More Information
- [SAP GUI User Dialogs](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_screens.htm) in the ABAP Keyword Documentation as the entry topic for dynpro-related topics
- Documentation about the [screen painter in the Help Portal](https://help.sap.com/docs/ABAP_PLATFORM_NEW/bd833c8355f34e96a6e83096b38bf192/d1801b50454211d189710000e8322d00)
- Documentation about the [menu painter in the Help Portal](https://help.sap.com/docs/ABAP_PLATFORM_NEW/bd833c8355f34e96a6e83096b38bf192/d1801ce8454211d189710000e8322d00)
- In ADT, in your system, choose `CTRL+SHIFT+A` to open the search. Insert `demo_dynpro*` to get a list of dynpro examples of the ABAP Keyword Documentation.
## Example
Coming soon ...

View File

@@ -73,6 +73,8 @@ ABAP cheat sheets[^1] ...
|[Program Flow Logic](13_Program_Flow_Logic.md)|Deals with control structures (`IF`, `CASE`), loops (`DO`, `WHILE`) and exception handling|[zcl_demo_abap_prog_flow_logic](./src/zcl_demo_abap_prog_flow_logic.clas.abap)|
|[ABAP Unit Tests](14_ABAP_Unit_Tests.md)|Contains basic information about unit testing in ABAP|[zcl_demo_abap_unit_test](./src/zcl_demo_abap_unit_test.clas.abap)|
|[CDS View Entities](15_CDS_View_Entities.md)|Note that cheat sheet content is available in [this blog](https://blogs.sap.com/2022/10/24/feature-matrix-data-modeling-with-abap-core-data-services/). The focus here is on the example CDS artifacts and the [executable example class](./src/zcl_demo_abap_cds_ve.clas.abap), which include comments.|[zcl_demo_abap_cds_ve](./src/zcl_demo_abap_cds_ve.clas.abap)|
|[SAP LUW](17_SAP_LUW.md)|Provides a high-level introduction to the [SAP LUW](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_luw_glosry.htm) concept that deals with data consistency with a focus on SAP LUW-related statements <br> 💡 Mostly relevant to [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm)|Coming soon|
|[Dynpro](18_Dynpro.md)|Provides a high-level introduction to dynpro topics with a focus on dynpro-related statements <br> 💡 Relevant to [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm)|Coming soon|
<br>