This commit is contained in:
danrega
2025-01-09 17:33:00 +01:00
parent 5e93fe0d8f
commit 4f3be4ac3e
17 changed files with 528 additions and 308 deletions

View File

@@ -665,26 +665,34 @@ FINAL(it_c) = it_a.
"As shown below and in other cheat sheets, constructor operators
"are handy when creating internal tables in place. The following
"examples uses the VALUE operator and an internal table type.
"examples uses the VALUE operator and an internal table type. You
"may also use the NEW operator to create anonymous data objects.
DATA(it_d) = VALUE string_table( ( `aaa` )
( `bbb` ) ).
TYPES it_type TYPE TABLE OF zdemo_abap_carr with empty key.
DATA(it_e) = VALUE it_type( ( carrid = 'XY' carrname = 'XY Airlines' )
( carrid = 'YZ' carrname = 'Air YZ' ) ).
"Not providing any table lines means the table is initial
"and has the same effect as the declaration of it_f.
DATA(it_e) = VALUE string_table( ).
DATA it_f TYPE string_table.
DATA(it_f) = VALUE string_table( ).
DATA it_g TYPE string_table.
DATA(it_h) = VALUE it_type( ).
DATA it_i TYPE it_type.
"Excursion
"Table declared inline in the context of a SELECT statement;
"a prior extra declaration of an internal table is not needed.
SELECT * FROM zdemo_abap_fli INTO TABLE @DATA(it_g).
SELECT * FROM zdemo_abap_fli INTO TABLE @DATA(it_j).
"Instead of
DATA it_h TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY.
SELECT * FROM zdemo_abap_fli INTO TABLE @it_h.
DATA it_k TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY.
SELECT * FROM zdemo_abap_fli INTO TABLE @it_k.
"Using FINAL
SELECT * FROM zdemo_abap_fli INTO TABLE @FINAL(it_i).
SELECT * FROM zdemo_abap_fli INTO TABLE @FINAL(it_l).
```
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -1233,7 +1241,7 @@ INSERT VALUE s( a = 'yyy' b = 3 ) INTO TABLE dref_tab->*.
### Example: Exploring Populating Internal Tables
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class.
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class.
The example is set up to display output in the console, but only for few data objects. You may want to set a break point at the earliest possible position and walk through the example in the debugger. This will allow you to double-click on data objects and observe how the different statements affect their contents.
<details>
@@ -1241,7 +1249,7 @@ The example is set up to display output in the console, but only for few data ob
<!-- -->
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1255,7 +1263,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -1537,49 +1545,101 @@ There are three different ways to specify the line to read:
- by free key
The following code snippets include [`READ TABLE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapread_table.htm) statements and [table expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentable_expressions.htm) to read from internal tables.
Note that you can also use ABAP SQL `SELECT` statements to read from internal tables. This is covered further down.
### Determining the Target Area when Reading Single Lines in READ TABLE Statements
- Copying a line to a data object using the addition `INTO`.
After the copying, the line found exists separately in the internal table and
in the data object. If you change the
data object or the table line, the change does not affect the other.
However, you can modify the copied table line and use a
`MODIFY` statement to modify the table based on the modified
table line (see below). The `TRANSPORTING` addition
specifies which components to copy. If
it is not specified, all components are respected.
``` abap
READ TABLE itab INTO dobj ... "dobj must have the table's structure type
<table>
READ TABLE itab INTO DATA(dobj_inl) ...
<tr>
<td> Target Area </td> <td> Notes </td>
</tr>
READ TABLE itab INTO ... TRANSPORTING comp1 [comp2 ... ].
```
<tr>
<td>
- Assigning a line to a [field
symbol](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm "Glossary Entry"),
for example, using an inline declaration (`... ASSIGNING FIELD-SYMBOL(<fs>) ...`). When you then access the field symbol, it means that you access the found table line. There is no actual copying of
content. Therefore, modifying the field symbol means
modifying the table line directly. Note that you cannot use the
`TRANSPORTING` addition since the entire table is
assigned to the field symbol.
Data object
``` abap
READ TABLE itab ASSIGNING <fs1> ... "The field symbol must have an appropriate type.
</td>
READ TABLE itab ASSIGNING FIELD-SYMBOL(<fs2>) ... "The field symbol is created inline.
```
<td>
- Reading a line into a [data reference
variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_reference_variable_glosry.htm "Glossary Entry")
using `REFERENCE INTO`. In this case, no copying takes place. If you want to address the line, you must first [dereference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendereferencing_operat_glosry.htm) the data reference. You cannot use the addition `TRANSPORTING`.
- Used to copy a line to a data object using the addition `INTO`.
- After the copying, the line found exists separately in the internal table and in the data object.
- If you change the data object or the table line, the change does not affect the other.
- However, you can modify the copied table line and use a `MODIFY` statement to modify the table based on the modified table line (see below).
- The `TRANSPORTING` addition specifies which components to copy. If it is not specified, all components are respected.
<br>
``` abap
READ TABLE itab REFERENCE INTO dref ...
``` abap
"dobj must have the table's structure type
READ TABLE itab INTO dobj ...
READ TABLE itab REFERENCE INTO DATA(dref_inl) ...
```
READ TABLE itab INTO DATA(dobj_inl) ...
READ TABLE itab INTO ... TRANSPORTING comp1 [comp2 ... ].
```
</td>
</tr>
<tr>
<td>
Field symbol
</td>
<td>
- Assigning a line to a [field symbol](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm "Glossary Entry"),
for example, using an inline declaration (`... ASSIGNING FIELD-SYMBOL(<fs>) ...`).
- When you then access the field symbol, it means that you access the found table line. There is no actual copying of content. Therefore, modifying the field symbol means
modifying the table line directly.
- Note that you cannot use the `TRANSPORTING` addition since the entire table is assigned to the field symbol.
<br>
``` abap
"The field symbol must have an appropriate type.
READ TABLE itab ASSIGNING <fs1> ...
"Inline declaration
READ TABLE itab ASSIGNING FIELD-SYMBOL(<fs2>) ...
```
</td>
</tr>
<tr>
<td>
Data reference variable
</td>
<td>
- Reading a line into a [data reference variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_reference_variable_glosry.htm "Glossary Entry") using `REFERENCE INTO`.
- In this case, no copying takes place.
- If you want to address the line, you must first [dereference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendereferencing_operat_glosry.htm) the data reference.
- You cannot use the addition `TRANSPORTING`.
<br>
``` abap
"The data reference variable must have an appropriate type.
READ TABLE itab REFERENCE INTO dref ...
"Inline declaration
READ TABLE itab REFERENCE INTO DATA(dref_inl) ...
```
</td>
</tr>
</table>
> **✔️ Hint**<br>
> Which to use then? Since all syntax options basically provide similar
@@ -2188,7 +2248,7 @@ READ TABLE itab WITH KEY ... BINARY SEARCH ...
- Depending on the number of times you need to access the internal table, it is recommended to work with sorted tables or tables with secondary keys. If you only need to read one or a few data sets, consider the administrative costs of setting up the index.
- Note: The `BINARY SEARCH` addition is not available for table expressions. If `KEY ...` is specified, an optimized search is performed by default. There are no performance differences between using the `READ TABLE` statement and table expressions.
To try it out the following example, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
To try it out the following example, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
The example includes multiple reads on standard internal tables using a `READ TABLE` statement ...
- without `BINARY SEARCH`.
@@ -2198,7 +2258,7 @@ The runtime of the reads is determined and stored in internal tables. The read o
The example is intended to demonstrate the performance gain using the `BINARY SEARCH` addition (and also using a secondary table key).
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -2211,7 +2271,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"Line type and internal table declarations
TYPES: BEGIN OF demo_struc,
@@ -2311,7 +2371,7 @@ ENDCLASS.
### Example: Exploring READ TABLE Statements and Table Expressions
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class.
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class.
The example is not set up to display output in the console. You may want to set a break point at the first position possible and walk through the example in the debugger. This will allow you to double-click on data objects and observe how the different statements affect their contents.
<details>
@@ -2319,7 +2379,7 @@ The example is not set up to display output in the console. You may want to set
<!-- -->
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -2333,7 +2393,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -3216,7 +3276,7 @@ DATA(deep_tab) = VALUE tab_type( ( compa = 1
DATA(num1) = deep_tab[ 2 ]-compb[ 1 ][ 2 ]-comp2.
ASSERT num1 = 14.
"Such a statement instead of, for example, multiple statements as follows.
"A statement such as the previous one instead of, for example, multiple statements as follows.
READ TABLE deep_tab INDEX 2 INTO DATA(wa1).
READ TABLE wa1-compb INDEX 1 INTO DATA(wa2).
READ TABLE wa2 INTO DATA(wa3) INDEX 2.
@@ -3328,14 +3388,14 @@ line = itab[ KEY primary_key (comp_name) = 1 ].
- The following example emphasizes that table expressions - expression enabling in modern ABAP as such - comes in very handy.
- However, also take the maintainability, debuggability and readbility of your code into consideration.
- The example includes the table expression chaining example from above (that may be fairly hard to understand) and a nonsensical, bad example overusing table expressions (affecting performance).
- Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
- Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
<details>
<summary>🟢 Click to expand for example code</summary>
<!-- -->
``` abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -3348,7 +3408,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"-------------- Chaining table expressions -------------
@@ -4237,12 +4297,12 @@ Notes and restrictions:
- the restrictions [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_engine_restr.htm).
- the various ABAP SQL functionalities in the ABAP Keyword Documentation and in the [ABAP SQL cheat sheet](03_ABAP_SQL.md). The following code snippets cover a selection.
The following example explores various `SELECT` queries with internal tables as data sources. To try it out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example uses objects of the ABAP cheat sheets repository and is set up to display output in the console.
The following example explores various `SELECT` queries with internal tables as data sources. To try it out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example uses objects of the ABAP cheat sheets repository and is set up to display output in the console.
Example:
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -4256,7 +4316,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"----------- Exploiting ABAP SQL functionality with internal tables -----------
@@ -5070,10 +5130,10 @@ More information:
- Iteration expressions can also handle table grouping (`FOR ... IN GROUP`). For example, see the [Constructor Expressions](05_Constructor_Expressions.md) cheat sheet.
- [Internal Tables: Grouping](11_Internal_Tables_Grouping.md) cheat sheet
The example class below demonstrates internal table grouping options. To try it out, create a demo class named `zcl_some_class` and paste the following code into it. After activation, choose *F9* in ADT to execute the class. The example is designed to display results in the console.
The example class below demonstrates internal table grouping options. To try it out, create a demo class named `zcl_demo_abap` and paste the following code into it. After activation, choose *F9* in ADT to execute the class. The example is designed to display results in the console.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -5085,7 +5145,7 @@ CLASS zcl_some_class DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
TYPES: BEGIN OF demo_struct,
comp1 TYPE c LENGTH 1,
@@ -5276,13 +5336,13 @@ Consider a scenario where you have a standard internal table, and you frequently
The following example creates two demo internal tables. One without a secondary table key and the other with a secondary table key. The tables are populated with a lot of data. Then, in a `DO` loop, many reads are performed on the internal tables. One example uses a free key for the read, the other uses a secondary table key that includes the components used for the free key search. Before and after the reads, the current timestamp is stored in variables, from which the elapsed time is calculated. There should be a significant delta of the elapsed time.
```abap
CLASS zcl_some_class DEFINITION PUBLIC FINAL CREATE PUBLIC.
CLASS zcl_demo_abap DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
TYPES: BEGIN OF demo_struc,
idx TYPE i,
@@ -5374,7 +5434,7 @@ ENDCLASS.
- Read accesses are executed using `READ TABLE` statements, which access the tables by:
- Index (both primary and secondary table index)
- Key (primary table key, secondary table key, free key)
- To try this, create a demo class named `zcl_some_class` and insert the provided code. After activation, choose *F9* in ADT to execute the class. It may take some time to finish and display the output. The example is set up to display the results of the read performance test in the console.
- To try this, create a demo class named `zcl_demo_abap` and insert the provided code. After activation, choose *F9* in ADT to execute the class. It may take some time to finish and display the output. The example is set up to display the results of the read performance test in the console.
> **💡 Note**<br>
> - This example is used for [exploration and experimentation ⚠️](./README.md#%EF%B8%8F-disclaimer). It is solely for demonstration purposes, and it is **not** a *tool* for proper and accurate runtime and performance testing. Due to its simplified nature, the results may not be entirely accurate. However, multiple test runs should reflect the notes below.
@@ -5432,14 +5492,14 @@ Notes on ...
- fast and optimized for both primary and secondary table keys
- consistent for large internal tables due to a special hash algorithm
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. Note that, when running the class, it may take a while to complete and display output in the console.
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. Note that, when running the class, it may take a while to complete and display output in the console.
<details>
<summary>🟢 Click to expand for example code</summary>
<!-- -->
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -5529,7 +5589,7 @@ CLASS zcl_some_class DEFINITION
METHODS check_example_components RETURNING VALUE(are_included) TYPE abap_boolean.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
prepare_itabs( number_of_lines = 5000 ).
@@ -5828,7 +5888,7 @@ ENDCLASS.
- The following example mainly demonstrates formal parameters of methods that are typed with generic table types. The method calls and the tables passed are only possible if the generic types fit. For example, you cannot pass a hashed table to a method whose importing parameter is typed with the generic type `INDEX TABLE`. Invalid method calls and table passing are commented out.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -5844,7 +5904,7 @@ CLASS zcl_some_class DEFINITION
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA standard_tab TYPE TABLE OF string WITH EMPTY KEY.

View File

@@ -1028,10 +1028,10 @@ ENDLOOP.
The following example demonstrates a selection of ABAP system fields. It uses artifacts from the ABAP cheat sheet repository. Note the comments in the code because a syntax warning will be displayed when inserting the code in a demo class that uses ABAP for Cloud Development. It is meant to emphasize that multiple system fields should not to be used in ABAP for Cloud Development.
To try the example out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
To try the example out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1043,7 +1043,7 @@ CLASS zcl_some_class DEFINITION
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"In ABAP for Cloud Development, the following statement will show a syntax warning saying that
@@ -1317,7 +1317,7 @@ The following example illustrates boxed components:
- The tables are populated in a loop under various conditions.
- The example demonstrates the impact of boxed components on memory usage.
- To try it out, proceed as follows:
- Create a demo class named `zcl_some_class`, paste the code into it, and activate it.
- Create a demo class named `zcl_demo_abap`, paste the code into it, and activate it.
- The example does not display output in the console.
- It includes sections you can comment in and out. See notes in the examples.
- The code sections compare the memory usage of boxed and non-boxed components:
@@ -1347,7 +1347,7 @@ The following example illustrates boxed components:
<br>
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1360,7 +1360,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.

View File

@@ -2419,11 +2419,11 @@ INSERT dbtab FROM TABLE @( CORRESPONDING #( another_itab MAPPING key_field = key
### Example: Exploring Create, Update, and Delete Operations with ABAP SQL Statements
To try the following example out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example uses a database table of the ABAP cheat sheets repository and is set up to display output in the console.
To try the following example out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example uses a database table of the ABAP cheat sheets repository and is set up to display output in the console.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -2437,7 +2437,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.

View File

@@ -45,7 +45,7 @@
- [Friendship between Global and Local Classes](#friendship-between-global-and-local-classes)
- [Events](#events)
- [ABAP Examples of Design Patterns in Object-Oriented Programming](#abap-examples-of-design-patterns-in-object-oriented-programming)
- [Class-Based Exceptions](#class-based-exceptions)
- [Class-Based and Classic Exceptions](#class-based-and-classic-exceptions)
- [ABAP Unit Tests](#abap-unit-tests)
- [ABAP Doc Comments](#abap-doc-comments)
- [More Information](#more-information)
@@ -396,7 +396,7 @@ Summary:
#### Creating the Visibility Sections
At least one section must be specified.
``` abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
@@ -468,7 +468,7 @@ can be used in the public visibility section. Effect:
Declaring attributes in visibility sections. In the code snippet below, all attributes are declared in the public section.
``` abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
@@ -493,7 +493,7 @@ CLASS zcl_some_class DEFINITION
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
... "Here go all method implementations.
@@ -533,7 +533,7 @@ parameters of the demo methods below are defined by just using the
parameter name. This means passing by reference (returning parameters
require to be passed by value).
``` abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
@@ -588,7 +588,7 @@ CLASS zcl_some_class DEFINITION
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD inst_meth1.
...
ENDMETHOD.
@@ -615,8 +615,9 @@ In the simplest form, methods can have no parameter at all. Apart from that, met
> **💡 Note**<br>
> - It is advisable to avoid specifying multiple different output parameters (exporting, returning, changing) in a signature to reduce complexity.
> - Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmethods_general.htm).
> - You may find the addition `EXCEPTIONS` especially in definitions of older classes. They are for non-class-based exceptions. This addition should not be used in ABAP for Cloud Development.
> - You may find the addition `EXCEPTIONS` especially in definitions of older classes. They are for non-class-based exceptions. This addition should not be used in ABAP for Cloud Development. See the section [Class-Based Exceptions](#class-based-exceptions), and the section [Classic Exceptions](27_Exceptions.md#classic-exceptions) in the [Exceptions and Runtime Errors](27_Exceptions.md) cheat sheet.
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -638,7 +639,7 @@ In the simplest form, methods can have no parameter at all. Apart from that, met
The following example (which anticipates aspects described in the following sections, such as calling methods) shows a class with a simple method demonstrating the syntax for formal parameter specifications. Complete types are used.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -659,7 +660,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -705,7 +706,7 @@ Syntax for [completely](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-
> - The considerations also apply to the typing of field symbols.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -776,7 +777,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -802,7 +803,7 @@ ENDCLASS.
Find more information on generic types in the [Data Types and Data Objects](16_Data_Types_and_Objects.md#generic-types) cheat sheet. The following code snippet anticipates aspects described in the following sections, such as calling methods.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -847,7 +848,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -1050,7 +1051,7 @@ num1: "7" / num2 (is not supplied; initial value): "0" / num3 (is supplied): "8"
```
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1070,7 +1071,7 @@ CLASS zcl_some_class DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA(meth1_result_a) = meth1( ).
@@ -1133,7 +1134,7 @@ ENDCLASS.
- When you call a method and specify a single actual parameter without specifying the name of the formal parameter in an assignment, the actual parameter is automatically assigned to the preferred parameter.
The following example (which anticipates aspects described in the following sections, such as calling methods) shows a simple method with input parameters of type `i` (an addition is performed using the actual parameter values), where one parameter is preferred. The `IS SUPPLIED` addition in `COND` statements checks whether parameters are supplied. The final output shows the preferred parameter assigned automatically when the formal parameter is not specified explicitly.
To try the example out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console. The example should display the following:
To try the example out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console. The example should display the following:
```
IS SUPPLIED: num1 "X", num2 "X", num3 "X" / Addition result "9"
@@ -1149,7 +1150,7 @@ IS SUPPLIED: num1 "X", num2 "", num3 "" / Addition result "4"
Example code:
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1167,7 +1168,7 @@ CLASS zcl_some_class DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA(text1) = meth( num1 = 3 num2 = 3 num3 = 3 ).
@@ -1234,7 +1235,7 @@ ENDCLASS.
instantiated and an instance is created.
- Can have `IMPORTING` parameters and raise exceptions.
The following example (which anticipates aspects described in the following sections, such as creating instances of classes) demonstrates static and instance constructors. To try the example out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
The following example (which anticipates aspects described in the following sections, such as creating instances of classes) demonstrates static and instance constructors. To try the example out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
Notes:
- The example class defines the instance and static constructors.
@@ -1256,7 +1257,7 @@ Notes:
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1274,13 +1275,13 @@ CLASS zcl_some_class DEFINITION
CLASS-DATA instance_constr_call_count TYPE i.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA itab TYPE string_table.
DO 5 TIMES.
DATA(inst) = NEW zcl_some_class( |inst{ sy-index }| ).
DATA(inst) = NEW zcl_demo_abap( |inst{ sy-index }| ).
APPEND |-------------- Instance "{ inst->instance_name }" --------------| TO itab.
APPEND |instance_timestamp: { inst->instance_timestamp }| TO itab.
APPEND |static_timestamp: { inst->static_timestamp }| TO itab.
@@ -1467,9 +1468,11 @@ methods are called using `->` via a reference variable.
methods are called using `=>` via the class name. When used
within the class in which it is declared, the static method can also be
called without `class_name=>...`.
- Static methods can but should not be called via reference variable (<s><code>oref->some_static_method( ).</code></s>).
- When methods are called, the (non-optional) parameters must be specified within parentheses.
- You might also stumble on method calls with [`CALL METHOD`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcall_method_static.htm)
statements. These statements should no longer be used. Note that `CALL METHOD` statements are the only option in the context of [dynamic programming](06_Dynamic_Programming.md). Therefore, `CALL METHOD` statements should be reserved for dynamic method calls.
- Find an example class demonstrating various method calls in section [Excursion: Example Class](#excursion-example-class).
Examples for instance method calls and static method calls:
@@ -1570,7 +1573,7 @@ class_name=>meth( EXPORTING i = j k = l RECEIVING m = DATA(n) ).
- Additional code snippets illustrate various ways to use methods declared with returning parameters in expression positions.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1589,17 +1592,17 @@ CLASS zcl_some_class DEFINITION
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"Note: Calling the method in the same class means specifying 'zcl_some_class=>' is optional here.
"Note: Calling the method in the same class means specifying 'zcl_demo_abap=>' is optional here.
"Standalone method call
"Specifying target data objects for all output parameters
"Inline declarations are handy because you can create an
"appropriately typed data object in place. No need to
"create an extra variable, check on the type etc.
zcl_some_class=>meth1(
zcl_demo_abap=>meth1(
EXPORTING
i_str = `ABAP`
IMPORTING
@@ -1614,7 +1617,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"Note: In this case, you cannot specify inline declarations for the exporting parameters.
DATA e TYPE decfloat34.
DATA f TYPE string_table.
DATA(g) = zcl_some_class=>meth1(
DATA(g) = zcl_demo_abap=>meth1(
EXPORTING
i_str = `ABAP`
IMPORTING
@@ -1628,13 +1631,13 @@ CLASS zcl_some_class IMPLEMENTATION.
"The following snippets show a selection (and ignore the available exporting
"parameters).
CASE zcl_some_class=>meth1( i_str = `ABAP` ).
CASE zcl_demo_abap=>meth1( i_str = `ABAP` ).
WHEN 0. ...
WHEN 1. ...
WHEN OTHERS. ...
ENDCASE.
IF zcl_some_class=>meth1( i_str = `ABAP` ) > 5.
IF zcl_demo_abap=>meth1( i_str = `ABAP` ) > 5.
...
ELSE.
...
@@ -1645,25 +1648,25 @@ CLASS zcl_some_class IMPLEMENTATION.
"method call is not initial and false if it is initial. The data type of the result
"of the functional meth1od call, i. e. the return value of the called functional method,
"is arbitrary. A check is made for the type-dependent initial value.
IF zcl_some_class=>meth1( i_str = `ABAP` ).
IF zcl_demo_abap=>meth1( i_str = `ABAP` ).
...
ELSE.
...
ENDIF.
DO zcl_some_class=>meth1( i_str = `ABAP` ) TIMES.
DO zcl_demo_abap=>meth1( i_str = `ABAP` ) TIMES.
...
ENDDO.
"Method call result as actual parameter
DATA(j) = zcl_some_class=>meth1( i_str = `ABAP` i_tab = zcl_some_class=>meth2( ) ).
DATA(j) = zcl_demo_abap=>meth1( i_str = `ABAP` i_tab = zcl_demo_abap=>meth2( ) ).
"Examples of returning parameters typed with a table type
LOOP AT zcl_some_class=>meth2( ) INTO DATA(wa1).
LOOP AT zcl_demo_abap=>meth2( ) INTO DATA(wa1).
...
ENDLOOP.
READ TABLE zcl_some_class=>meth2( ) INTO DATA(wa2) INDEX 1.
READ TABLE zcl_demo_abap=>meth2( ) INTO DATA(wa2) INDEX 1.
ENDMETHOD.
@@ -1696,7 +1699,7 @@ You can also address the entire object, which is illustrated in the example of s
The following code snippet declares a local data object in a method. It has the same name as a data object declared in the private visibility section. shows a method implementation. `me` is used to access the non-local data object.
``` abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1709,7 +1712,7 @@ CLASS zcl_some_class DEFINITION
METHODS meth RETURNING VALUE(text) TYPE string.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
str = `AP`.
@@ -1806,7 +1809,7 @@ DATA(json) = xco_cp_json=>data->builder( )->begin_object(
Self-contained example class demonstrating chained method calls with a functional method call and a standalone statement:
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1814,9 +1817,9 @@ CLASS zcl_some_class DEFINITION
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
METHODS add_text IMPORTING str TYPE string
RETURNING VALUE(ref) TYPE REF TO zcl_some_class.
METHODS add_space RETURNING VALUE(ref) TYPE REF TO zcl_some_class.
METHODS add_period RETURNING VALUE(ref) TYPE REF TO zcl_some_class.
RETURNING VALUE(ref) TYPE REF TO zcl_demo_abap.
METHODS add_space RETURNING VALUE(ref) TYPE REF TO zcl_demo_abap.
METHODS add_period RETURNING VALUE(ref) TYPE REF TO zcl_demo_abap.
METHODS return_text RETURNING VALUE(str) TYPE string.
METHODS display_text IMPORTING cl_run_ref TYPE REF TO if_oo_adt_classrun_out.
DATA text TYPE string.
@@ -1824,7 +1827,7 @@ CLASS zcl_some_class DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"----------------------------------------------------------------
@@ -1832,7 +1835,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"----------------------------------------------------------------
"Hallo NAME. This is an example of method chaining.
DATA(text1) = NEW zcl_some_class(
DATA(text1) = NEW zcl_demo_abap(
)->add_text( `Hallo`
)->add_space(
)->add_text( xco_cp=>sy->user( )->name
@@ -1861,7 +1864,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"the attribute.
"Example result: Today is 2025-03-05. It's 14:30:38. Have a nice day.
DATA(text2) = NEW zcl_some_class(
DATA(text2) = NEW zcl_demo_abap(
)->add_text( `Today`
)->add_space(
)->add_text( `is`
@@ -1898,7 +1901,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"includes the writing to the console.
"Console output: Lorem ipsum dolor sit amet
NEW zcl_some_class( )->add_text( `Lorem`
NEW zcl_demo_abap( )->add_text( `Lorem`
)->add_space(
)->add_text( `ipsum`
)->add_space(
@@ -3977,7 +3980,7 @@ i_ref = NEW class( ).
### Excursion: Example Interface
Expand the following collapsible section for example code. To try it out, create a demo interface named `zif_some_interface`, a class named `zcl_some_class`, and paste the code into the artifacts. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
Expand the following collapsible section for example code. To try it out, create a demo interface named `zif_some_interface`, a class named `zcl_demo_abap`, and paste the code into the artifacts. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
<details>
<summary>🟢 Click to expand for more information and example code</summary>
@@ -4014,7 +4017,7 @@ Example class implementations:
- The example class also implements the interface `if_oo_adt_classrun`.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -4028,7 +4031,7 @@ CLASS zcl_some_class DEFINITION
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
ENDMETHOD.
@@ -4046,7 +4049,7 @@ ENDCLASS.
- Adding the implementations for the interface methods declared with `DEFAULT IGNORE` and `DEFAULT FAIL`.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -4060,7 +4063,7 @@ CLASS zcl_some_class DEFINITION
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
ENDMETHOD.
@@ -4089,7 +4092,7 @@ ENDCLASS.
- The example demonstrates method calls using object and interface reference variables.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -4105,12 +4108,12 @@ CLASS zcl_some_class DEFINITION
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"Examples using an object reference variable
DATA(oref) = NEW zcl_some_class( ).
DATA(oref) = NEW zcl_demo_abap( ).
oref->add( num1 = 1 num2 = 2 ).
DATA(res1) = oref->res.
@@ -4136,7 +4139,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"Similar examples using an interface reference variable
DATA iref TYPE REF TO zif_some_interface.
iref = NEW zcl_some_class( ).
iref = NEW zcl_demo_abap( ).
iref->addition( num1 = 3 num2 = 5 ).
DATA(res3) = iref->add_result.
@@ -4188,7 +4191,10 @@ tests](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file
- Friends of a class can create instances of the class without restrictions.
- Friendship is a one-way street, i. e. a class granting friendship to another class is not granded friendship the other way round. If class `a` grants friendship to class `b`, class `b` must also explicitly grant friendship to class `a` so that `a` can access the invisible components of class `b`.
- Friendship and inheritance: Heirs of friends and interfaces that contain a friend as a component interface also become friends. However, granting friendship is not inherited, i. e. a friend of a superclass is not automatically a friend of its subclasses.
- Additions in the context of granting friendship:
- `FRIENDS`: For local classes, e.g. local classes granting friendship to other local classes or the global class of the class pool
- `GLOBAL FRIENDS`: Used in global classes to grant friendship to other global classes and interfaces
- `LOCAL FRIENDS`: Used for global classes to grant friendship to local classes and interfaces in its own class pool; however, it is a dedicated statement, as shown in the example below (the declaration `CLASS zcl_demo_abap DEFINITION LOCAL FRIENDS local_class.` in the CCDEF include)
You specify the befriended class in the definition part using a `FRIENDS` addition:
``` abap
@@ -4220,15 +4226,30 @@ For more information, see the following topics:
<br>
<table>
**Global class**
- Create a new global class (the example uses the name `zcl_some_class`) and copy and paste the following code in the *Global Class* tab in ADT.
<tr>
<td> Class include </td> <td> Code </td>
</tr>
<tr>
<td>
Global class
</td>
<td>
- Create a new global class (the example uses the name `zcl_demo_abap`) and copy and paste the following code in the *Global Class* tab in ADT.
- The class has a type and method declaration in the private section. They are used in the local class.
- Once activated (and the code of the other includes has been inserted), you can choose *F9* in ADT to run the class.
- When running the class, a method of the local class that is declared in the private section there is called. As a result of this method call, a string is assigned to an attribute that is also declared in the private section of the local class. This attribute is accessed by the global class, and finally displayed in the ADT console.
<br>
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -4243,7 +4264,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
local_class=>say_hello( ).
DATA(hello) = local_class=>hello.
@@ -4255,44 +4276,73 @@ CLASS zcl_some_class IMPLEMENTATION.
ENDCLASS.
```
**CCDEF include (*Class-relevant Local Types* tab in ADT)**
</td>
</tr>
<tr>
<td>
CCDEF include (Class-relevant Local Types tab in ADT)
</td>
<td>
- Regarding the includes, see the information in section [Excursion: Class Pool and Include Programs](#excursion-class-pool-and-include-programs)
- The `LOCAL FRIENDS` addition makes the local class a friend of the global class. The private components of the global class can then be accessed by the local class.
<br>
```abap
CLASS local_class DEFINITION DEFERRED.
CLASS zcl_some_class DEFINITION LOCAL FRIENDS local_class.
CLASS zcl_demo_abap DEFINITION LOCAL FRIENDS local_class.
```
**CCIMP include (*Local Types* tab in ADT)**
</td>
</tr>
<tr>
<td>
CCIMP include (Local Types tab in ADT)
</td>
<td>
- The `FRIENDS` addition makes the global class a friend of the local class. The private components of the local class can then be accessed by the global class.
- A type declared in the private section of the global class is used to type an attribute.
- The method, which is also declared in the private section, includes a method call in the implementation. It is a method declared in the private section of the global class.
<br>
```abap
CLASS local_class DEFINITION FRIENDS zcl_some_class.
CLASS local_class DEFINITION FRIENDS zcl_demo_abap.
PUBLIC SECTION.
PROTECTED SECTION.
PRIVATE SECTION.
CLASS-DATA hello TYPE zcl_some_class=>str.
CLASS-DATA hello TYPE zcl_demo_abap=>str.
CLASS-METHODS say_hello.
ENDCLASS.
CLASS local_class IMPLEMENTATION.
METHOD say_hello.
hello = |{ zcl_some_class=>get_hello( ) } { sy-uname }.|.
hello = |{ zcl_demo_abap=>get_hello( ) } { sy-uname }.|.
ENDMETHOD.
ENDCLASS.
```
</td>
</tr>
</table>
</details>
<p align="right"><a href="#top">⬆️ back to top</a></p>
### Events
@@ -6949,10 +6999,36 @@ ENDCLASS.
<p align="right"><a href="#top">⬆️ back to top</a></p>
### Class-Based Exceptions
### Class-Based and Classic Exceptions
- [Catchable exceptions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencatchable_exception_glosry.htm) are represented by exception objects of exception classes.
- Predefined global exception classes exist, custom exception classes can be created. You can also create local exception classes.
- Find an overview in the [Exceptions and Runtime Errors](27_Exceptions.md) cheat sheet.
- See the following code snippet for an ABAP class that specifies the `EXCEPTIONS` addition, which should not be specified anymore for new developments, raising classic, non-class based exceptions.
```abap
"ABAP class (creates UUIDs) raising a class-based exception
TRY.
DATA(uuid) = cl_system_uuid=>create_uuid_x16_static( ).
CATCH cx_uuid_error.
ENDTRY.
"ABAP class (provides type information, see the Dynamic Programming cheat sheet) specified with the EXCEPTIONS addition raising a non-class based exception
cl_abap_typedescr=>describe_by_name( EXPORTING p_name = `TYPE_THAT_DOES_NOT_EXIST`
RECEIVING p_descr_ref = DATA(tdo1)
EXCEPTIONS type_not_found = 4 ).
IF sy-subrc <> 0.
"Type not found
...
ENDIF.
cl_abap_typedescr=>describe_by_name( EXPORTING p_name = `ABAP_BOOLEAN`
RECEIVING p_descr_ref = DATA(tdo2)
EXCEPTIONS type_not_found = 4 ).
ASSERT sy-subrc = 0.
```
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -6984,7 +7060,7 @@ ENDCLASS.
"!
"! <p>This class serves as an example to illustrate comments for ABAP Doc.
"! The comments begin with the string <strong>"!</strong>, a special form of regular comments introduced by <strong>"</strong>. <br/><br/>
"! The {@link zcl_some_class.METH:calculate} method of the example class performs a calculation. </p>
"! The {@link zcl_demo_abap.METH:calculate} method of the example class performs a calculation. </p>
"! <h2>Notes</h2>
"! <ul>
"! <li>ABAP Doc documents declarations in ABAP programs.</li>
@@ -6995,7 +7071,7 @@ ENDCLASS.
"! </ul>
"! <h2>Steps</h2>
"! <ol>
"! <li>Create a demo class named <em>zcl_some_class</em></li>
"! <li>Create a demo class named <em>zcl_demo_abap</em></li>
"! <li>Copy and paste the code of this example and activate.</li>
"! <li>Click the class name to display the comments in the <em>ABAP Element Info</em> ADT tab.</li>
"! <li>You can also choose F2 for the class name to display the information.</li>
@@ -7005,21 +7081,21 @@ ENDCLASS.
"! <h3>Link examples</h3>
"! <ul>
"! <li>Repository objects such as the following, and more:
"! <ul><li>Classes, e.g. {@link zcl_some_class}</li>
"! <ul><li>Classes, e.g. {@link zcl_demo_abap}</li>
"! <li>Interfaces, e.g. {@link if_oo_adt_classrun}</li>
"! <li>CDS artifacts, e.g. {@link i_apisforclouddevelopment}</li>
"! <li>DDIC database tables, e.g. {@link zdemo_abap_carr}</li>
"! <li>DDIC data elements, e.g. {@link land1}</li></ul>
"! <li>Method: {@link zcl_some_class.METH:calculate}</li>
"! <li>Constant: {@link zcl_some_class.DATA:const}</li>
"! <li>Data object: {@link zcl_some_class.DATA:dobj}</li>
"! <li>Method parameter: {@link zcl_some_class.METH:calculate.DATA:operator}</li>
"! <li>Interface implemented in a class: {@link zcl_some_class.INTF:if_oo_adt_classrun}</li>
"! <li>Interface method implemented in a class: {@link zcl_some_class.INTF:if_oo_adt_classrun.METH:main}</li>
"! <li>Method: {@link zcl_demo_abap.METH:calculate}</li>
"! <li>Constant: {@link zcl_demo_abap.DATA:const}</li>
"! <li>Data object: {@link zcl_demo_abap.DATA:dobj}</li>
"! <li>Method parameter: {@link zcl_demo_abap.METH:calculate.DATA:operator}</li>
"! <li>Interface implemented in a class: {@link zcl_demo_abap.INTF:if_oo_adt_classrun}</li>
"! <li>Interface method implemented in a class: {@link zcl_demo_abap.INTF:if_oo_adt_classrun.METH:main}</li>
"! <li>DDIC domain: {@link DOMA:land1}</li>
"! <li>XSLT: {@link XSLT:id}</li>
"! </ul>
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -7060,7 +7136,7 @@ CLASS zcl_some_class DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA(result_plus) = calculate( num1 = 1 num2 = 10 operator = en_calc-plus ).

View File

@@ -446,7 +446,6 @@ Assigning incompatible structures and internal tables
- The example makes use of the `BASE` addition, and includes a `CORRESPONDING` expression.
- The `s1` structure is assigned the identically named components of the `s2` structure. Other components are assigned by explicitly specifying them.
- Another example performs an assignment with internal tables, using a table iteration with a `FOR` loop.
-
<br>

View File

@@ -614,22 +614,22 @@ is required to access objects and their components. That means objects are not d
- Find more information in the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcreate_object.htm) and the [ABAP Object Orientation](04_ABAP_Object_Orientation.md) cheat sheet
```abap
DATA oref_a TYPE REF TO zcl_some_class.
DATA oref_a TYPE REF TO zcl_demo_abap.
oref_a = NEW #( ).
"Using inline declaration
DATA(oref_b) = NEW zcl_some_class( ).
DATA(oref_b) = NEW zcl_demo_abap( ).
"Generic type
DATA oref_c TYPE REF TO object.
oref_c = NEW zcl_some_class( ).
oref_c = NEW zcl_demo_abap( ).
"This object creation with the NEW operator corresponds to the older
"syntax using CREATE OBJECT, and replaces it. See more examples in the
"context of dynamic object creation that require the CREATE OBJECT
"syntax further down.
DATA oref_d TYPE REF TO zcl_some_class.
DATA oref_d TYPE REF TO zcl_demo_abap.
CREATE OBJECT oref_d.
DATA oref_e TYPE REF TO object.
CREATE OBJECT oref_e TYPE zcl_some_class.
CREATE OBJECT oref_e TYPE zcl_demo_abap.
```
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -2356,10 +2356,10 @@ CALL METHOD class=>(meth) PARAMETER-TABLE ptab.
**Example class 1**
The following example class explores dynamic method calls with simple methods. You can create a demo class called `zcl_some_class` and copy and paste the following code. Once activated, you can choose *F9* in ADT to run the class. The example is not designed to display output in the console.
The following example class explores dynamic method calls with simple methods. You can create a demo class called `zcl_demo_abap` and copy and paste the following code. Once activated, you can choose *F9* in ADT to run the class. The example is not designed to display output in the console.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -2376,12 +2376,12 @@ CLASS zcl_some_class DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"The following examples use both named and unnamed data objects randomly,
"i.e. ...=>(meth_name) or ...=>(`SOME_METH`), for example.
DATA(cl_name) = `ZCL_SOME_CLASS`.
DATA(cl_name) = `ZCL_DEMO_ABAP`.
DATA(meth_name1) = `STAT_METH1`.
"------------------------------------------------------------------------
@@ -2396,52 +2396,52 @@ CLASS zcl_some_class IMPLEMENTATION.
CALL METHOD me->(meth_name1).
"-------- Class specified statically, method specified dynamically --------
CALL METHOD zcl_some_class=>(meth_name1).
CALL METHOD zcl_demo_abap=>(meth_name1).
"-------- Class specified dynamically, method specified statically --------
CALL METHOD (`ZCL_SOME_CLASS`)=>stat_meth1.
CALL METHOD (`ZCL_DEMO_ABAP`)=>stat_meth1.
"-------- Class and method specified dynamically --------
CALL METHOD (`ZCL_SOME_CLASS`)=>(`STAT_METH1`).
CALL METHOD (`ZCL_DEMO_ABAP`)=>(`STAT_METH1`).
"-------- Specifying non-optional parameters --------
CALL METHOD (`ZCL_SOME_CLASS`)=>stat_meth2 EXPORTING text = `hallo`.
CALL METHOD (`ZCL_DEMO_ABAP`)=>stat_meth2 EXPORTING text = `hallo`.
"Specifying the output parameter is optional
DATA res TYPE string.
CALL METHOD (`ZCL_SOME_CLASS`)=>stat_meth2 EXPORTING text = `hallo` IMPORTING result = res.
CALL METHOD (`ZCL_DEMO_ABAP`)=>stat_meth2 EXPORTING text = `hallo` IMPORTING result = res.
ASSERT res = `HALLO`.
"-------- Some examples for handling errors when calling methods wrongly --------
"Instance method called using =>
TRY.
CALL METHOD zcl_some_class=>(`INST_METH1`).
CALL METHOD zcl_demo_abap=>(`INST_METH1`).
CATCH cx_sy_dyn_call_illegal_method.
ENDTRY.
"The example method declares a non-optional parameter.
TRY.
CALL METHOD (`ZCL_SOME_CLASS`)=>stat_meth2.
CALL METHOD (`ZCL_DEMO_ABAP`)=>stat_meth2.
CATCH cx_sy_dyn_call_param_missing.
ENDTRY.
"Specifying a wrong parameter name
TRY.
CALL METHOD (`ZCL_SOME_CLASS`)=>stat_meth2 EXPORTING hallo = `hallo`.
CALL METHOD (`ZCL_DEMO_ABAP`)=>stat_meth2 EXPORTING hallo = `hallo`.
CATCH cx_sy_dyn_call_param_missing.
ENDTRY.
"Assigning wrong, incompatible type
TRY.
CALL METHOD (`ZCL_SOME_CLASS`)=>stat_meth2 EXPORTING text = VALUE string_table( ( `hi` ) ).
CALL METHOD (`ZCL_DEMO_ABAP`)=>stat_meth2 EXPORTING text = VALUE string_table( ( `hi` ) ).
CATCH cx_sy_dyn_call_illegal_type.
ENDTRY.
"Specifying wrong parameter kinds (the example method specifies importing
"and exporting parameters, and not a returning parameter)
TRY.
CALL METHOD (`ZCL_SOME_CLASS`)=>stat_meth2 EXPORTING text = `hallo` RECEIVING result = res.
CALL METHOD (`ZCL_DEMO_ABAP`)=>stat_meth2 EXPORTING text = `hallo` RECEIVING result = res.
CATCH cx_sy_dyn_call_illegal_type.
ENDTRY.
@@ -2451,7 +2451,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"Creating an instance of a class by specifying the type dynamically
DATA oref TYPE REF TO object.
CREATE OBJECT oref TYPE ('ZCL_SOME_CLASS').
CREATE OBJECT oref TYPE ('ZCL_DEMO_ABAP').
"--- Object reference variable specified statically, method specified dynamically ---
"Note: This is a also possible for interface reference variables.
@@ -2474,15 +2474,15 @@ CLASS zcl_some_class IMPLEMENTATION.
"------------------------------------------------------------------------
"------- Static equivalents to the dynamic statement below -------
DATA(oref_stat) = NEW zcl_some_class( ).
DATA(oref_stat) = NEW zcl_demo_abap( ).
res = oref_stat->inst_meth2( `abc` ).
ASSERT res = `ABC`.
"For demo purposes, including chained method call options:
"Functional method call
res = NEW zcl_some_class( )->inst_meth2( `def` ).
res = NEW zcl_demo_abap( )->inst_meth2( `def` ).
ASSERT res = `DEF`.
"Standalone statement
NEW zcl_some_class( )->inst_meth2( EXPORTING text = `ghi` RECEIVING result = res ).
NEW zcl_demo_abap( )->inst_meth2( EXPORTING text = `ghi` RECEIVING result = res ).
ASSERT res = `GHI`.
"------- Dynamic CALL METHOD statements using the PARAMETER-TABLE addition -------
@@ -2509,15 +2509,15 @@ CLASS zcl_some_class IMPLEMENTATION.
value = NEW string( ) ) ).
"Static/dynamic specification variants
CALL METHOD (`ZCL_SOME_CLASS`)=>(`STAT_METH2`) PARAMETER-TABLE ptab.
CALL METHOD (`ZCL_DEMO_ABAP`)=>(`STAT_METH2`) PARAMETER-TABLE ptab.
res = ptab[ name = 'RESULT' ]-('VALUE')->*.
ASSERT res = `MNO`.
CALL METHOD zcl_some_class=>(`STAT_METH2`) PARAMETER-TABLE ptab.
CALL METHOD zcl_demo_abap=>(`STAT_METH2`) PARAMETER-TABLE ptab.
res = ptab[ name = 'RESULT' ]-('VALUE')->*.
ASSERT res = `MNO`.
CALL METHOD (`ZCL_SOME_CLASS`)=>stat_meth2 PARAMETER-TABLE ptab.
CALL METHOD (`ZCL_DEMO_ABAP`)=>stat_meth2 PARAMETER-TABLE ptab.
res = ptab[ name = 'RESULT' ]-('VALUE')->*.
ASSERT res = `MNO`.
@@ -2724,7 +2724,7 @@ It is crucial to perform checks and handle dynamic programming techniques cautio
For more details, refer to the ABAP Keyword Documentation [here (Standard ABAP documentation)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendynamic_programming_scrty.htm).
To try the example out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example uses objects of the ABAP cheat sheets repository and is set up to display output in the console.
To try the example out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example uses objects of the ABAP cheat sheets repository and is set up to display output in the console.
It covers the following aspects:
- Dynamic `WHERE` clause and specifying the data object holding external input as operand and literal
- Verifying input for not allowed database table access
@@ -2734,7 +2734,7 @@ It covers the following aspects:
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -2747,7 +2747,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -3193,11 +3193,11 @@ The type properties are represented by attributes that are accessible through th
The following code example demonstrates a range of RTTI attribute accesses and method calls. It includes retrieving type information at runtime for elementary and enumerated types, structures, internal tables, data references, classes, and interfaces. Find more information in the section below.
To try the example out, create a demo class named `zcl_some_class` and paste the code into it.
To try the example out, create a demo class named `zcl_demo_abap` and paste the code into it.
The example is not set up to display output in the console. So, after activation, you may want to set a break point at the first position possible and choose *F9* in ADT to execute the class. You can then walk through the example in the debugger. This will allow you to double-click on the variables and check out the contents. The example is similar to the one below, however, this only focuses on the method calls and attribute accesses without output preparation among others.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -3211,7 +3211,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"------------------------------------- Elementary types/data objects -------------------------------------
@@ -3386,7 +3386,7 @@ Notes:
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -3398,7 +3398,7 @@ CLASS zcl_some_class DEFINITION
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"Data objects to work with in the example

View File

@@ -514,22 +514,32 @@ the string function
Syntax examples:
``` abap
"&& and string template
DATA(s1) = `AB` && `AP`. "ABAP
DATA(s2) = `ab` && `ap` && ` ` && s1. "abap ABAP
DATA(s3) = |{ s1 }. { s2 }!|. "ABAP. abap ABAP!
"abcd
DATA(s1) = `ab` && `cd`.
"efgh abcd
DATA(s2) = `ef` && `gh` && ` ` && s1.
"abcd. efgh abcd!
DATA(s3) = |{ s1 }. { s2 }!|.
"CONCATENATE statements
CONCATENATE s1 s2 INTO s3. "ABAPabap ABAP
"uvwxyz
DATA(s4) = `uvw`.
DATA(s5) = `xyz`.
CONCATENATE s4 s5 INTO s3.
"Multiple data objects and target declared inline
CONCATENATE s1 ` ` s2 INTO DATA(s5). "ABAP abap ABAP
"uvw xyz
CONCATENATE s4 ` ` s5 INTO DATA(s6).
CONCATENATE s1 s2 s5 INTO DATA(s6). "ABAPabap ABAPABAP abap ABAP
"abcdefgh abcduvwxyz
CONCATENATE s1 s2 s4 s5 INTO DATA(s7).
"You can also add a separation sign using the addition SEPARATED BY
CONCATENATE s1 s2 INTO s3 SEPARATED BY ` `. "ABAP abap ABAP
"uvw xyz
CONCATENATE s4 s5 INTO DATA(s8) SEPARATED BY ` `.
CONCATENATE s1 s2 INTO s3 SEPARATED BY `#`. "ABAP#abap ABAP
"uvw#xyz
CONCATENATE s4 s5 INTO DATA(s9) SEPARATED BY `#`.
"Keeping trailing blanks in the result when concatenating fixed length
"strings. The ones of variable length strings are respected by default.
@@ -1124,6 +1134,7 @@ removed from the result.
- You can use
[`TRANSLATE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaptranslate.htm)
statements to perform replacements directly on the source field.
- If you want to replace single characters or fixed sequences of characters with a specified string, you can also use `REPLACE` statements and the `replace` function.
Syntax examples:
``` abap
@@ -1183,12 +1194,18 @@ Syntax Overview (see the syntax diagram in the [ABAP Keyword Documentation](http
``` abap
FIND
FIRST OCCURRENCE OF "(or) ALL OCCURRENCES OF
FIRST OCCURRENCE OF
"or
ALL OCCURRENCES OF
"1. Only the first occurrence is searched
"2. All occurrences are searched
"Note: If none of these two additions is specified, only the first occurrence is searched for.
SUBSTRING some_substring "(or) PCRE some_regex
SUBSTRING some_substring
"or
some_substring
"or
PCRE some_regex
"1. Searching for exactly one string, specifying SUBSTRING is optional (e.g. for emphasis);
" some_substring is a character-like operand; note: Trailing blanks are not ignored if it is of type string
"2. Searching for a substring matching a regular expression; only the PCRE addition should be used;
@@ -2509,14 +2526,14 @@ SPLIT xstr AT blank_xstr INTO TABLE DATA(xstr_tab) IN BYTE MODE.
- Reads a bit at a specified position in a byte string into a target data object.
Expand the following collapsible section for example code, which experiments with byte string processing (converting a hexadecimal value to the character-like representation of the binary values by reading bits, getting hexadecimal values from the character-like representation of the binary values, setting bits). To try it out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
Expand the following collapsible section for example code, which experiments with byte string processing (converting a hexadecimal value to the character-like representation of the binary values by reading bits, getting hexadecimal values from the character-like representation of the binary values, setting bits). To try it out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
<details>
<summary>🟢 Click to expand for example code</summary>
<!-- -->
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -2529,7 +2546,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.

View File

@@ -863,7 +863,7 @@ Here, the expression result is passed to the returning parameter without naming
Example:
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
@@ -876,7 +876,7 @@ CLASS zcl_some_class DEFINITION
num2 TYPE i
RETURNING VALUE(result) TYPE i.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA(res1) = multiply( num1 = 2 num2 = 3 ).
DATA(res2) = multiply( num1 = 10 num2 = 10 ).

View File

@@ -557,7 +557,7 @@ DATA do_i_like_init LIKE do_i VALUE IS INITIAL.
"the class, too.
"Declaration in the example:
"CLASS-DATA: read_only_attribute TYPE string VALUE `Hallo` READ-ONLY.
IF zcl_some_class=>read_only_attribute = `abc`.
IF zcl_demo_abap=>read_only_attribute = `abc`.
...
ELSE.
...
@@ -1145,7 +1145,7 @@ In [ABAP programs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/in
| `space` constant | It is of type type `c`, length 1, and contains a blank character. |
| `me` self-reference | Used in ABAP Objects, it's a local reference variable for instance method implementations. At runtime, it points to the instance executing the method. It is primarily used to be explicit about, for exmaple, using instance attributes of the class, especially if there is a local data object with the same name.|
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
<details>
@@ -1153,7 +1153,7 @@ Expand the following collapsible section for example code. To try it out, create
<!-- -->
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1167,7 +1167,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"In ABAP for Cloud Development, the following statement will show a syntax warning saying that

View File

@@ -60,7 +60,7 @@ It provides references to more detailed information on the topic.
For deprecated and invalid syntax in ABAP for Cloud Development, refer to the following (nonsensical) example code. You can create a demo class and insert the code below (adjust the class name if necessary). Several syntax errors and warnings will be displayed:
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -69,7 +69,7 @@ It provides references to more detailed information on the topic.
INTERFACES if_oo_adt_classrun.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"Example that demonstrates (not) released APIs, deprecated and
"invalid syntax in ABAP for Cloud Development

View File

@@ -530,10 +530,10 @@ CALL TRANSFORMATION ... SOURCE ...
The following example explores various syntax options for `CALL TRANSFORMATION` statements, using the predefined identity transformation `ID`.
To try the example out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
To try the example out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -546,7 +546,7 @@ CLASS zcl_some_class DEFINITION
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -729,7 +729,7 @@ ENDCLASS.
> - For additional information and examples, see the [ABAP and JSON](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_json.htm) section of the ABAP Keyword Documentation.
Expand the following collapsible section for example classes. To try them out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. This example is set up to display output in the console.
Expand the following collapsible section for example classes. To try them out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. This example is set up to display output in the console.
**Creating JSON Data using the sXML library**
@@ -744,7 +744,7 @@ Expand the following collapsible section for example classes. To try them out, c
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -758,7 +758,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"In this example, the following JSON data should be created.
@@ -844,7 +844,7 @@ ENDCLASS.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -858,7 +858,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"Creating demo JSON data
@@ -1130,14 +1130,14 @@ DATA json_to_abap_table TYPE string_table.
CHANGING data = json_to_abap_table ).
```
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. This example is set up to display output in the console.
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. This example is set up to display output in the console.
<details>
<summary>🟢 Click to expand for example code</summary>
<!-- -->
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1151,7 +1151,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
TYPES: BEGIN OF demo_struc,
@@ -1282,7 +1282,7 @@ ENDCLASS.
- Find more information and examples [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenasxml_class_instances.htm) in the ABAP Keyword Documentation.
Expand the following collapsible section for example classes. To try them out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The examples are set up to display output in the console.
Expand the following collapsible section for example classes. To try them out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The examples are set up to display output in the console.
<details>
<summary>🟢 Click to expand for example code</summary>
@@ -1299,7 +1299,7 @@ Expand the following collapsible section for example classes. To try them out, c
- The values of all deserialized instance attributes are displayed.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1317,7 +1317,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -1331,7 +1331,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"Creating objects, assigning values to instance attributes, and serializing objects
DO 3 TIMES.
DATA(oref) = NEW zcl_some_class( ).
DATA(oref) = NEW zcl_demo_abap( ).
oref->timestamp = utclong_current( ).
oref->random_number = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
min = 1
@@ -1351,7 +1351,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"Deserializing objects
LOOP AT serialized_obj_tab INTO DATA(wa).
DATA deserialized_obj TYPE REF TO zcl_some_class.
DATA deserialized_obj TYPE REF TO zcl_demo_abap.
CALL TRANSFORMATION id SOURCE XML wa
RESULT obj = deserialized_obj.
@@ -1383,7 +1383,7 @@ ENDCLASS.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1407,7 +1407,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -1421,7 +1421,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"Creating objects, assigning values to instance attributes, and serializing objects
DO 3 TIMES.
DATA(oref) = NEW zcl_some_class( ).
DATA(oref) = NEW zcl_demo_abap( ).
oref->timestamp = utclong_current( ).
oref->random_number = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
min = 1
@@ -1441,7 +1441,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"Deserializing objects
LOOP AT serialized_obj_tab INTO DATA(wa).
DATA deserialized_obj TYPE REF TO zcl_some_class.
DATA deserialized_obj TYPE REF TO zcl_demo_abap.
CALL TRANSFORMATION id SOURCE XML wa
RESULT obj = deserialized_obj.
@@ -1573,7 +1573,7 @@ The following example covers:
- Exporting and importing class objects
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1588,7 +1588,7 @@ CLASS zcl_some_class DEFINITION
DATA text TYPE string.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA buffer TYPE xstring.
@@ -1721,7 +1721,7 @@ CLASS zcl_some_class IMPLEMENTATION.
DATA info_tab TYPE TABLE OF info WITH EMPTY KEY.
DO 3 TIMES.
DATA(obj_ref) = NEW zcl_some_class( |Instance { sy-index }| ).
DATA(obj_ref) = NEW zcl_demo_abap( |Instance { sy-index }| ).
CALL TRANSFORMATION id SOURCE oref = obj_ref RESULT XML DATA(xml).
EXPORT xml_data = xml TO DATA BUFFER buffer COMPRESSION ON.

View File

@@ -128,7 +128,7 @@ The following example makes use of the <code>CL_DEMO_CLASSRUN</code> class. A st
<br><br>
``` abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
INHERITING FROM cl_demo_classrun
PUBLIC
CREATE PUBLIC.
@@ -139,7 +139,7 @@ CLASS zcl_some_class DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD main.
TYPES: BEGIN OF s,
comp1 TYPE string,
@@ -529,7 +529,7 @@ The following example explores the generation of arbitraty numeric values.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -540,7 +540,7 @@ CLASS zcl_some_class DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
TYPES: BEGIN OF random_values,
@@ -603,22 +603,21 @@ CLASS zcl_some_class IMPLEMENTATION.
DATA(c) = cl_abap_random_float=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(d) = cl_abap_random_int=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(e) = cl_abap_random_int8=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(f) = cl_abap_random_packed=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(g) = cl_abap_random_packed=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(h) = cl_abap_random_packed_dec1=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(i) = cl_abap_random_packed_dec2=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(j) = cl_abap_random_packed_dec3=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(k) = cl_abap_random_packed_dec4=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(l) = cl_abap_random_packed_dec5=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(m) = cl_abap_random_packed_dec6=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(n) = cl_abap_random_packed_dec7=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(o) = cl_abap_random_packed_dec8=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(p) = cl_abap_random_packed_dec9=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(q) = cl_abap_random_packed_dec10=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(r) = cl_abap_random_packed_dec11=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(s) = cl_abap_random_packed_dec12=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(t) = cl_abap_random_packed_dec13=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(u) = cl_abap_random_packed_dec14=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(f) = cl_abap_random_packed=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(g) = cl_abap_random_packed_dec1=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(h) = cl_abap_random_packed_dec2=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(i) = cl_abap_random_packed_dec3=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(j) = cl_abap_random_packed_dec4=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(k) = cl_abap_random_packed_dec5=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(l) = cl_abap_random_packed_dec6=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(m) = cl_abap_random_packed_dec7=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(n) = cl_abap_random_packed_dec8=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(o) = cl_abap_random_packed_dec9=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(p) = cl_abap_random_packed_dec10=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(q) = cl_abap_random_packed_dec11=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(r) = cl_abap_random_packed_dec12=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(s) = cl_abap_random_packed_dec13=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
DATA(t) = cl_abap_random_packed_dec14=>create( seed = cl_abap_random=>seed( ) )->get_next( ).
ENDMETHOD.
@@ -1294,10 +1293,10 @@ Provides context information relevant to the current ABAP session.
<br><br>
``` abap
"Getting current date in UTC (not the system or user time), e.g. 20240101
"Getting the current date in UTC (not the system or user time), e.g. 20240101
DATA(sys_date) = cl_abap_context_info=>get_system_date( ).
"Getting current time in UTC, e.g. 152450
"Getting the current time in UTC, e.g. 152450
DATA(sys_time) = cl_abap_context_info=>get_system_time( ).
```
@@ -1880,7 +1879,7 @@ Provides methods to get information about filled components in structures allowi
<br><br>
``` abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1890,7 +1889,7 @@ CLASS zcl_some_class DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
out->write( `---------- filled_components method ----------` ).
"It returns an internal table containing the names of the non-initial
@@ -2137,6 +2136,7 @@ ENDTRY.
<tr>
<td> Class </td> <td> Details/Code Snippet </td>
</tr>
<tr>
<td> <code>CL_ABAP_CONTEXT_INFO</code> </td>
<td>
@@ -2146,8 +2146,6 @@ Provides context information relevant to the current ABAP session.
``` abap
"User alias, e.g. XY0000001234
DATA(alias) = cl_abap_context_info=>get_user_alias( ).
"You can also get user information using XCO classes
DATA(user_w_xco) = xco_cp=>sy->user( )->name.
"Formatted name, e.g. John Doe
TRY.
@@ -2157,15 +2155,27 @@ ENDTRY.
"The class also provides the option to retrieve the current date and time
"in UTC.
"Getting current date in UTC (not the system or user time), e.g. 20240101
"Getting the current date in UTC (not the system or user time), e.g. 20240101
DATA(sys_date) = cl_abap_context_info=>get_system_date( ).
"Getting current time in UTC, e.g. 152450
"Getting the current time in UTC, e.g. 152450
DATA(sys_time) = cl_abap_context_info=>get_system_time( ).
```
</td>
</tr>
<tr>
<td> <code>XCO_CP</code> </td>
<td>
``` abap
DATA(user_w_xco) = xco_cp=>sy->user( )->name.
```
</td>
</tr>
</table>
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -2350,8 +2360,8 @@ DATA(all_tables) = xco_cp_abap_repository=>objects->tabl->all->in( xco_cp_abap=>
"Refining the search by applying a filter
"Creating a filter and adding a search pattern
DATA(filter1) = xco_cp_abap_repository=>object_name->get_filter(
xco_cp_abap_sql=>constraint->contains_pattern( 'ZDEMO_ABAP_RAP_R%' ) ).
DATA(filter1) = xco_cp_abap_repository=>object_name->get_filter(
xco_cp_abap_sql=>constraint->contains_pattern( 'ZDEMO_ABAP_RAP_R%' ) ).
"Getting all BDEFs in the system having a specific pattern
DATA(bdefs_in_package) = xco_cp_abap_repository=>objects->bdef->where( VALUE #( ( filter1 )
@@ -2371,6 +2381,42 @@ DATA(filter4) = xco_cp_abap_repository=>object_name->get_filter( xco_cp_abap_sql
DATA(filtered_classes) = xco_cp_abap_repository=>objects->clas->where( VALUE #( ( filter3 ) ( filter4 )
) )->in( xco_cp_abap=>repository )->get( ).
"Checking if a repository object with a specific name exists in the system
DATA(type_names) = VALUE string_table( ( `ZDEMO_ABAP_FLI` ) ( `ZDEMO_ABAP_FLSCH_VE` ) ).
LOOP AT type_names INTO DATA(type_name).
DATA(filter5) = xco_cp_abap_repository=>object_name->get_filter( xco_cp_abap_sql=>constraint->equal( type_name ) ).
"A table is returned containing found repository objects of the specified name
DATA(repo_objects) = xco_cp_abap_repository=>objects->where( VALUE #( ( filter5 ) ) )->in( xco_cp_abap=>repository )->get( ).
"Some examples for further processing the returned objects
"You can explore more options, e.g., by adding the object component selector (->)
"to the final parenthesis and checking the suggestions by ADT.
LOOP AT repo_objects INTO DATA(obj).
"Retrieving the four-character value of the object type
DATA(val) = obj->type->value.
"Retrieving the package name of the repository object
DATA(package) = obj->get_package( )->name.
"The following example implementation retrieves key component.
CASE val.
WHEN `TABL`.
"Retrieving the key component names of DDIC database tables
DATA(table_keys) = xco_cp_abap_repository=>object->tabl->database_table->for( CONV #( obj->name->value ) )->fields->key->get_names( ).
WHEN `DDLS`.
"Retrieving the key component names of CDS entities
DATA(ddls_key_spec) = xco_cp_abap_repository=>object->ddls->for( CONV #( obj->name->value ) )->entity( )->fields->all->get_names( ).
LOOP AT ddls_key_spec INTO DATA(field).
DATA(is_key) = xco_cp_abap_repository=>object->ddls->for( CONV #( obj->name->value ) )->view_entity( )->field( field )->content( )->get_key_indicator( ).
DATA ddls_keys TYPE string_table.
IF is_key IS NOT INITIAL.
APPEND field TO ddls_keys.
ENDIF.
ENDLOOP.
CLEAR ddls_keys.
ENDCASE.
ENDLOOP.
ENDLOOP.
"Getting information about some of the technical properties of different
"repository objects. The examples show the creation of handlers. You can
"explore more options, e.g., by adding the object component selector (->)
@@ -2394,7 +2440,7 @@ DATA(subcl) = xco_cp_abap=>class( 'CL_ABAP_TYPEDESCR' )->subclasses->all->get( )
"Getting the names of the subclasses
DATA(subcl_names) = xco_cp_abap=>class( 'CL_ABAP_TYPEDESCR' )->subclasses->all->get_names( ).
"Getting the direct superclass
DATA(direct_super_class) = xco_cp_abap=>class( 'CL_ABAP_DATADESCR' )->definition->content(
DATA(direct_super_class) = xco_cp_abap=>class( 'CL_ABAP_DATADESCR' )->definition->content(
)->get_superclass( )->name.
"Taking an XCO handler for a database table as an example, see some of the
@@ -2716,7 +2762,7 @@ Notes on the example:
<br>
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -2740,15 +2786,15 @@ CLASS zcl_some_class DEFINITION
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
APPEND VALUE #( time_stamp = time_stamp instance = `----` comment = `Time stamp stored when first running/calling the class` ) TO info.
DATA(inst1) = NEW zcl_some_class( `inst1` ).
DATA(inst2) = NEW zcl_some_class( `inst2` ).
DATA(inst3) = NEW zcl_some_class( `inst3` ).
DATA(inst4) = NEW zcl_some_class( `inst4` ).
DATA(inst5) = NEW zcl_some_class( `inst5` ).
DATA(inst1) = NEW zcl_demo_abap( `inst1` ).
DATA(inst2) = NEW zcl_demo_abap( `inst2` ).
DATA(inst3) = NEW zcl_demo_abap( `inst3` ).
DATA(inst4) = NEW zcl_demo_abap( `inst4` ).
DATA(inst5) = NEW zcl_demo_abap( `inst5` ).
APPEND VALUE #( time_stamp = utclong_current( ) instance = `----` comment = `Time stamp stored before starting parallel processing` ) TO info.
@@ -2768,7 +2814,7 @@ CLASS zcl_some_class IMPLEMENTATION.
APPEND VALUE #( time_stamp = utclong_current( ) instance = `----` comment = `Time stamp stored after the WAIT statement` ) TO info.
LOOP AT result_info INTO DATA(wa).
DATA(res) = CAST zcl_some_class( wa-inst ).
DATA(res) = CAST zcl_demo_abap( wa-inst ).
APPEND LINES OF res->parallel_proc TO info.
APPEND VALUE #( time_stamp = res->time_stamp instance = res->instance_name comment = `Time stamp stored in constructor implementation when instantiating class` ) TO info.
ENDLOOP.
@@ -2950,7 +2996,7 @@ The following, self-contained, and oversimplified example is intended to give a
<br>
``` abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -2963,7 +3009,7 @@ CLASS zcl_some_class DEFINITION
CLASS-DATA number TYPE i.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"Deleting a demo database table
DELETE FROM zdemo_abap_tabca.
@@ -2978,7 +3024,7 @@ CLASS zcl_some_class IMPLEMENTATION.
DO 2 TIMES.
"Creating an instance of the example class (that implements the bgPF-relevant
"interface if_bgmc_op_single_tx_uncontr)
DATA(inst) = NEW zcl_some_class( ).
DATA(inst) = NEW zcl_demo_abap( ).
TRY.
"Getting the default factory for transactional background processes and
@@ -3052,7 +3098,7 @@ This example is similar to example 1. Unlike example 1, example 2 executes opera
<br>
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -3071,7 +3117,7 @@ CLASS zcl_some_class DEFINITION
METHODS get_uuid RETURNING VALUE(uuid) TYPE sysuuid_x16.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"Deleting a demo database table
DELETE FROM zdemo_abap_tabca.
@@ -3086,7 +3132,7 @@ CLASS zcl_some_class IMPLEMENTATION.
DO 2 TIMES.
"Creating an instance of the example class (that implements the bgPF-relevant
"interface if_bgmc_op_single)
DATA(inst) = NEW zcl_some_class( num = sy-index ).
DATA(inst) = NEW zcl_demo_abap( num = sy-index ).
TRY.
"Getting the default factory for transactional background processes and
@@ -3154,7 +3200,7 @@ CLASS zcl_some_class IMPLEMENTATION.
METHOD get_uuid.
TRY.
uuid = cl_system_uuid=>create_uuid_x16_static( ) .
uuid = cl_system_uuid=>create_uuid_x16_static( ).
CATCH cx_uuid_error.
ENDTRY.
ENDMETHOD.
@@ -3252,7 +3298,7 @@ To check out examples in demo classes, expand the collapsible sections below.
<details>
<summary>🟢 1. Read example: Getting Markdown content and sending ZIP file via email</summary>
<summary>🟢 1. Read example: Retrieving ABAP cheat sheet markdown content using a GitHub API and sending a ZIP file with the content via email</summary>
<!-- -->
> **⚠️ Note/Disclaimer**<br>
@@ -3265,13 +3311,13 @@ To check out examples in demo classes, expand the collapsible sections below.
> - The example is generally about calling external APIs and parsing the HTTP responses. It retrieves the Markdown files of the ABAP cheat sheet documents Markdown contained in the ABAP cheat sheet GitHub repository.
> - Before using the GitHub APIs, make sure that you have consulted the following documentation: <a href="https://docs.github.com/en">GitHub Docs</a>, <a href="https://docs.github.com/en/enterprise-cloud@latest/rest/markdown/markdown?apiVersion=2022-11-28#render-a-markdown-document">Render a Markdown document</a>, <a href="https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28">Rate limits for the REST API</a>
> - For the example to work and send emails, make sure that the configurations from [here](https://help.sap.com/docs/btp/sap-business-technology-platform/emailing) have been performed.
> - To run the example class, copy and paste the code into a class named `zcl_some_class`. Run the class using F9. The email sending status will be displayed, and you can expect an email to be sent.
> - To run the example class, copy and paste the code into a class named `zcl_demo_abap`. Run the class using F9. The email sending status will be displayed, and you can expect an email to be sent.
<br>
``` abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -3298,7 +3344,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -3421,12 +3467,12 @@ ENDCLASS.
> **⚠️ Note/Disclaimer**<br>
> - As stated for the previous example, also note for this example: Before using the GitHub APIs, make sure that you have consulted the following documentation: <a href="https://docs.github.com/en">GitHub Docs</a>, <a href="https://docs.github.com/en/enterprise-cloud@latest/rest/markdown/markdown?apiVersion=2022-11-28#render-a-markdown-document">Render a Markdown document</a>, <a href="https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28">Rate limits for the REST API</a>
> - To run the example class, copy and paste the code into a class named `zcl_some_class`. Run the class using F9. It is set up to display HTML content in the console. Using the GitHub API, sample Markdown content is sent and converted to HTML.
> - To run the example class, copy and paste the code into a class named `zcl_demo_abap`. Run the class using F9. It is set up to display HTML content in the console. Using the GitHub API, sample Markdown content is sent and converted to HTML.
<br>
``` abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -3440,7 +3486,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -3652,7 +3698,7 @@ The XLSX XCO module works with XLSX content in the form of an xstring. The follo
**Exploring the XCO XLSX Module**
Assuming you have the XLSX content created and uploaded above on your system, you can explore the following example using the XCO classes/methods. Set up a demo class called `zcl_some_class` and use the code provided below. After activating it, choose *F9* in ADT to run the class. The example is designed to show output in the console.
Assuming you have the XLSX content created and uploaded above on your system, you can explore the following example using the XCO classes/methods. Set up a demo class called `zcl_demo_abap` and use the code provided below. After activating it, choose *F9* in ADT to run the class. The example is designed to show output in the console.
> **💡 Note**<br>
> - Refer to the comments in the code for information.
@@ -3660,7 +3706,7 @@ Assuming you have the XLSX content created and uploaded above on your system, yo
> - If your artifacts have a different setup, names, or XLSX content, the example class will not function properly. You willl need to modify the class code to match your specific requirements.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -3674,7 +3720,7 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -4217,7 +4263,7 @@ cl_abap_unit_assert=>assert_equals(
<br><br>
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -4228,7 +4274,7 @@ CLASS zcl_some_class DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA(dimension_inst) = cl_uom_dim_maintenance=>get_instance( ).
@@ -4461,7 +4507,7 @@ SELECT *
<br>
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -4472,12 +4518,12 @@ CLASS zcl_some_class DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA num TYPE i VALUE 1.
GET REFERENCE OF num INTO DATA(ref).
DATA(current_time) = sy-uzeit.
out->write( `Some text` ).
**********************************************************************
@@ -4488,7 +4534,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"Creating an ATC run and starting it
"The ATC run result is stored in a variable.
DATA(atc_result) = atc->create_run(
atc->create_run_configuration( atc->create_object_set_for_list( VALUE #( ( obj_type = 'CLAS' obj_name = 'ZCL_SOME_CLASS' ) ) )
atc->create_run_configuration( atc->create_object_set_for_list( VALUE #( ( obj_type = 'CLAS' obj_name = 'ZCL_DEMO_ABAP' ) ) )
)->set_check_variant( atc->get_check_variant_by_name(
'ABAP_CLOUD_READINESS'
"'ABAP_CLOUD_DEVELOPMENT_DEFAULT'

View File

@@ -12,6 +12,11 @@
- [Numeric Access/Calculations](#numeric-accesscalculations)
- [CL\_ABAP\_DATFM: Date Conversions](#cl_abap_datfm-date-conversions)
- [Time](#time)
- [Retrieving the Current Time](#retrieving-the-current-time)
- [Accessing Time Values](#accessing-time-values)
- [Creating Time Values](#creating-time-values)
- [Performing Time Calculations](#performing-time-calculations)
- [CL\_ABAP\_TIMEFM: Converting Time Values](#cl_abap_timefm-converting-time-values)
- [Time Stamps](#time-stamps)
- [Time Stamps of Type utclong](#time-stamps-of-type-utclong)
- [Retrieving the Current Time Stamp](#retrieving-the-current-time-stamp)
@@ -478,6 +483,7 @@ ENDLOOP.
## Time
The code snippet below provides examples of time processing, such as retrieving the current time, accessing time values, creating time values, and performing time calculations. You can also utilize the XCO library in different scenarios. Note that the return value in most of the code snippets using XCO is of type `string`.
### Retrieving the Current Time
```abap
"--------------------- Retrieving the current time --------------------
@@ -492,7 +498,11 @@ DATA(utc_time) = cl_abap_context_info=>get_system_time( ).
DATA(time_w_xco) = xco_cp=>sy->time( xco_cp_time=>time_zone->user
)->as( xco_cp_time=>format->iso_8601_extended
)->value.
```
### Accessing Time Values
```abap
"--------------------- Accessing time values --------------------
"Note: As mentioned in a previous section on dates, the access to time fields
@@ -520,7 +530,11 @@ DATA(sec_w_xco) = xco_cp=>sy->time( xco_cp_time=>time_zone->user )->second.
DATA(min_w_xco) = xco_cp=>sy->time( xco_cp_time=>time_zone->user )->minute.
"e.g. 10
DATA(hr_w_xco) = xco_cp=>sy->time( xco_cp_time=>time_zone->user )->hour.
```
### Creating Time Values
```abap
"--------------------- Creating times --------------------
DATA time_cr1 TYPE t.
@@ -541,7 +555,11 @@ DATA(time_cr4) = xco_time->as( xco_cp_time=>format->iso_8601_extended )->value.
DATA(hours_from_time) = xco_time->hour. "08
DATA(minutes_from_time) = xco_time->minute. "34
DATA(seconds_from_time) = xco_time->second. "05
```
### Performing Time Calculations
```abap
"------------ Performing time calculations ------------
"Retrieving seconds, minutes, and hours from a time value in a data object
@@ -669,7 +687,11 @@ DATA(hours_w_div) = ( ( time2 - time1 ) MOD 86400 ) DIV 3600.
DATA(hours_no_div) = ( ( time2 - time1 ) MOD 86400 ) / 3600.
"15.72833333333333333333333333333333
DATA(hours_no_div_dec) = CONV decfloat34( ( ( time2 - time1 ) MOD 86400 ) / 3600 ).
```
### CL_ABAP_TIMEFM: Converting Time Values
```abap
"------------ Conversions with the CL_ABAP_TIMEFM class ------------
"Using the CL_ABAP_TIMEFM class, you can perform conversions with external

View File

@@ -758,7 +758,7 @@ Using the [XCO library](https://help.sap.com/docs/btp/sap-business-technology-pl
> - The executable example uses both the created repository objects as described in this cheat sheet and some repository objects of the ABAP cheat sheet repository. The example explores and uses code snippets of this cheat sheet, emphasizing the use of global types in ABAP programs.
> - [Disclaimer](./README.md#%EF%B8%8F-disclaimer)
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
Expand the following collapsible section for example code. To try it out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
<details>
<summary>🟢 Click to expand for example code</summary>
@@ -766,7 +766,7 @@ Expand the following collapsible section for example code. To try it out, create
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -775,7 +775,7 @@ CLASS zcl_some_class DEFINITION
INTERFACES if_oo_adt_classrun.
ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"Populating demo database tables from the ABAP cheat sheet repository

View File

@@ -1181,14 +1181,14 @@ Runtime errors ...
- You can also check the content of the *Feed Reader* tab in ADT. There, expand your project and find the runtime errors caused by you.
Example of a catchable exception not handled:
- In ADT, run a class (e.g. `zcl_some_class`) that, for example, contains the statement `DATA(res) = 1 / 0.`, without a `TRY` control structure to handle the exception.
- In ADT, run a class (e.g. `zcl_demo_abap`) that, for example, contains the statement `DATA(res) = 1 / 0.`, without a `TRY` control structure to handle the exception.
- When running the class, a popup is displayed.
- Clicking the *Show* button opens the short dump, providing information such as the following:
```
Short Text Division by 0 (type I or INT8)
Runtime Error COMPUTE_INT_ZERODIVIDE
Exception CX_SY_ZERODIVIDE
Program ZCL_SOME_CLASS================CP
Exception CX_SY_ZERODIVIDE
Program ZCL_DEMO_ABAP=================CP
...
```
@@ -1243,7 +1243,7 @@ ASSERT flag = abap_true.
### Local Exception Classes
The following simplified example demonstrates a local exception class:
- In a class, e.g. `zcl_some_class`, go to the [CCDEF include](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenccdef_glosry.htm), i.e. the *Class-relevant local types* tab in ADT.
- In a class, e.g. `zcl_demo_abap`, go to the [CCDEF include](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenccdef_glosry.htm), i.e. the *Class-relevant local types* tab in ADT.
- Add the following local class declaration
```abap
CLASS lcx_error DEFINITION INHERITING FROM cx_static_check.
@@ -1258,7 +1258,7 @@ The following simplified example demonstrates a local exception class:
- You can run the class using *F9*.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -1274,7 +1274,7 @@ The following simplified example demonstrates a local exception class:
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.

View File

@@ -680,10 +680,10 @@ ctrl_verb_string = replace( val = |abc\ndef\rghi\r\njkl|
The following example shows how to use callouts to call an ABAP method from a PCRE regular expression. It creates an object-oriented representation of a PCRE regex using the `CL_ABAP_REGEX` class, applying different PCRE syntaxes for callout specifications. The class implements the `IF_ABAP_MATCHER_CALLOUT` interface, and the `callout` method uses a demo class instance as the callout handler. If the regex matches, the method is called for each callout position. The `callout` method populates a string table with accessible details. This demonstrates that regex processing can be influenced, and in the example, processing stops when a condition is met. As a result, `found` is false because the regex is not fully processed. For more details, refer to the class documentation.
To try the example out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
To try the example out, create a demo class named `zcl_demo_abap` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
```abap
CLASS zcl_some_class DEFINITION
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
@@ -699,13 +699,13 @@ ENDCLASS.
CLASS zcl_some_class IMPLEMENTATION.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA(text_to_search) = `abcdefghijklmnopq`.
DATA(regex) = cl_abap_regex=>create_pcre( pattern = `(...)(?C1)(..)(?C2)(....)(?C3)(.)(?C"D")(....)(?C"E")(...)(?C"F")` ).
DATA(matcher) = regex->create_matcher( text = text_to_search ).
DATA(handler) = NEW zcl_some_class( ).
DATA(handler) = NEW zcl_demo_abap( ).
matcher->set_callout( handler ).
DATA(found) = matcher->match( ).

View File

@@ -444,7 +444,7 @@ CLASS zcl_demo_abap_objects_misc IMPLEMENTATION.
out->write( zcl_demo_abap_aux=>heading( `6) Excursion: Inline Declarations, Returning Parameters` ) ).
"Note:
"- Calling the method in the same class means specifying 'zcl_some_class=>' is optional here.
"- Calling the method in the same class means specifying 'zcl_demo_abap=>' is optional here.
"- There is no proper implementation in the method implementations.
"- There is not output for this section as it is meant to visualize on syntax options.