Update
This commit is contained in:
@@ -1231,7 +1231,7 @@ TYPES: BEGIN OF s,
|
||||
DATA(dref_tab) = NEW tab_type( ( a = 'aaa' b = 1 )
|
||||
( a = 'bbb' b = 2 ) ).
|
||||
|
||||
"Access by derefencing
|
||||
"Access by dereferencing
|
||||
DATA(copy_deref_itab) = dref_tab->*.
|
||||
DATA(read_line) = dref_tab->*[ 2 ].
|
||||
DATA(read_comp) = dref_tab->*[ 1 ]-a.
|
||||
@@ -3060,7 +3060,7 @@ line = itab_so[ comp1 = 1 ].
|
||||
|
||||
``` abap
|
||||
"The search is and cannot be optimized as the component is not part of
|
||||
"the primary table key of the sorted table. Plus, no appropriate
|
||||
"the primary table key of the table. Plus, no appropriate
|
||||
"secondary table key can be applied.
|
||||
line = itab[ comp4 = 'ccc' ].
|
||||
```
|
||||
@@ -3925,7 +3925,7 @@ ENDLOOP.
|
||||
"Table content: 3 / 6 / 9 / 12 / 15
|
||||
```
|
||||
|
||||
The expressions are covered in the cheat sheet [Constructor Expressions](05_Constructor_Expressions.md):
|
||||
The expressions are covered in the [Constructor Expressions](05_Constructor_Expressions.md) cheat sheet:
|
||||
- [Iteration Expressions Using FOR](05_Constructor_Expressions.md#iteration-expressions-using-for)
|
||||
- Special reduction operator `REDUCE` that is based on iteration expressions: [REDUCE](05_Constructor_Expressions.md#reduce)
|
||||
|
||||
@@ -3933,7 +3933,7 @@ The expressions are covered in the cheat sheet [Constructor Expressions](05_Cons
|
||||
|
||||
### Interrupting and Exiting Loops
|
||||
|
||||
ABAP keywords such as `CONTINUE`, `CHECK`, and `EXIT`, are available to exit and interrupt loops. Find more information in the [Program Flow Logic](13_Program_Flow_Logic.md#interrupting-and-exiting-loops) cheat sheet.
|
||||
ABAP keywords such as `CONTINUE` (terminating the current loop pass, continuing with the next), `CHECK` (conditional termination termination of the current loop pass if the logical expression is false), and `EXIT` (loop terminated completely), are available to exit and interrupt loops. Find more information in the [Program Flow Logic](13_Program_Flow_Logic.md#interrupting-and-exiting-loops) cheat sheet.
|
||||
|
||||
In the following example, the loop is exited using the `EXIT` statement when a certain condition is met.
|
||||
```abap
|
||||
@@ -4597,8 +4597,8 @@ DATA(itab1) = VALUE tab_type1( ( key1 = 1 a = 'a' b = 'b' c = 'c' )
|
||||
( key1 = 2 a = 'd' b = 'e' c = 'f' )
|
||||
( key1 = 3 a = 'g' b = 'h' c = 'i' ) ).
|
||||
|
||||
DATA(itab2) = VALUE tab_type2( ( key2 = 1 d = `j` e = `k` )
|
||||
( key2 = 2 d = `l` e = `m` ) ).
|
||||
DATA(itab2) = VALUE tab_type2( ( key2 = 1 d = 'j' e = 'k' )
|
||||
( key2 = 2 d = 'l' e = 'm' ) ).
|
||||
|
||||
"SELECT statement, inner join
|
||||
"Note: With the inner join, the target table contains all
|
||||
|
||||
@@ -166,7 +166,7 @@ Views](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm
|
||||
- However, there are plenty of additions and syntax variants, some of which are mentioned in the cheat sheet. In general, choose `F1` for the keywords and additions to get all the details in the ABAP Keyword Documentation.
|
||||
|
||||
``` abap
|
||||
SELECT FROM source "What data source read from
|
||||
SELECT FROM source "What data source to read from
|
||||
FIELDS field_list "What columns should be read
|
||||
WHERE condition "Specifies conditions on which a row/rows should be read
|
||||
INTO target. "Specifies the target of the result set
|
||||
@@ -1592,7 +1592,7 @@ SELECT FROM zdemo_abap_flsch
|
||||
## SQL Expressions
|
||||
|
||||
- SQL expressions can be specified in various positions of ABAP SQL statements.
|
||||
- They that passed to the database system for evaluation.
|
||||
- They are passed to the database system for evaluation.
|
||||
- For example, SQL expressions can be specified as columns in the
|
||||
`SELECT` list as demonstrated in most of the following examples.
|
||||
- Find information on more possible positions and general information
|
||||
@@ -2781,7 +2781,7 @@ SELECT *
|
||||
|
||||
<br>
|
||||
|
||||
- The example uses a zoo animal context. To explore the example, create three ABAP repository objects: 2 CDS entities, 1 example class.
|
||||
- The example uses a zoo animal context. To explore the example, create three ABAP repository objects: 2 CDS artifacts, 1 example class.
|
||||
- For the CDS artifacts, right-click your package and choose *New -> Other ABAP Repository Objects* in ADT. Filter for *data definition*, and walk through the wizard. Use the example's artifact names (`zdemo_abap_animals_te` for the table entity, and `zdemo_abap_animals_we` for the writable CDS view entity), or use other names and adapt the code accordingly.
|
||||
- After activation, choose *F9* in the class in ADT to execute it. The example is set up to display output in the console.
|
||||
- The example class performs CRUD operations on both CDS artifacts. The example includes ABAP SQL `SELECT`, `INSERT`, `MODIFY`, `UPDATE`, and `DELETE` statements.
|
||||
@@ -2960,7 +2960,7 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
out->write( |\n| ).
|
||||
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Performing CRUD operations using a writable CDS view entities and ABAP SQL
|
||||
*& Performing CRUD operations using a writable CDS view entity and ABAP SQL
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
out->write( `---- Performing CRUD operations on a writable CDS view entity using ABAP SQL ----` ).
|
||||
|
||||
@@ -165,12 +165,12 @@ ENDCLASS.
|
||||
|
||||
- You can create local classes, for example, in the [CCIMP include](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenccimp_glosry.htm) (*Local Types* tab in ADT) of a [class pool](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclass_pool_glosry.htm).
|
||||
- Local classes are used in their own ABAP program. While dynamic access beyond program boundaries is possible, it is not recommended.
|
||||
- The cheat sheet's focus is on global classes. Local classes are also mentioned in the [friendship](#friendship) section.
|
||||
- In the cheat sheet, local classes are used in several sections, particularly for self-contained examples that require multiple classes.
|
||||
|
||||
The following snippet shows the skeleton of local class declaration.
|
||||
- It does not specify any class options after `DEFINITION`.
|
||||
- The `PUBLIC` addition makes a class a global class in the class library. Not possible in the context of local classes.
|
||||
- The `PUBLIC` addition makes a class a global class in the class library. This is not possible for local classes.
|
||||
- It does not specify `CREATE ...`. Note that `CREATE PUBLIC` is the default, which means that not specifying any `CREATE ...` addition makes the class implicitly specified with `CREATE PUBLIC`.
|
||||
- More additions are possible. They are covered in the following sections.
|
||||
|
||||
``` abap
|
||||
"Declaration part
|
||||
@@ -195,7 +195,7 @@ ENDCLASS.
|
||||
|
||||
#### Additions in the Class Declaration Part
|
||||
|
||||
This section covers a selection of additions to declare classes. They are also covered in other sections below, e.g. [Additions Related to Inheritance and Instantiation](#additions-related-to-inheritance-and-instantiation). Find more information on the additions in the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapclass_options.htm).
|
||||
This section covers a selection of additions to declare classes. They are also covered in other sections below, e.g. [Additions Related to Inheritance and Instantiation](#additions-related-to-inheritance-and-instantiation). Find more information on the additions in the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapclass_options.htm). The additions assume dealing with public classes, however, many of the additions are also possible for local classes.
|
||||
|
||||
<table>
|
||||
|
||||
@@ -546,8 +546,7 @@ In the class declaration part, you specify three [visibility sections](https://h
|
||||
<tr>
|
||||
<td><pre>PROTECTED SECTION.</pre></td>
|
||||
<td>Components declared in this section can be
|
||||
accessed from within the class and <a href="https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensubclass_glosry.htm">subclasses</a> as well as <a href="https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfriend_glosry.htm">friends</a>
|
||||
- concepts related to <a href="https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninheritance_glosry.htm">inheritance</a>.</td>
|
||||
accessed from within the class and <a href="https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensubclass_glosry.htm">subclasses</a> as well as <a href="https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfriend_glosry.htm">friends</a>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><pre>PRIVATE SECTION.</pre></td>
|
||||
@@ -592,7 +591,7 @@ All components, i. e.
|
||||
objects),
|
||||
- methods (using `METHODS` and `CLASS-METHODS`),
|
||||
- events (using `EVENTS` and `CLASS-EVENTS`) as well as
|
||||
- interfaces,
|
||||
- interfaces (only in the public visibility section),
|
||||
|
||||
are declared in the declaration part of the class. There, they must be
|
||||
assigned to a visibility section.
|
||||
@@ -1641,8 +1640,8 @@ 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 (<code>oref->some_static_method( ).</code>).
|
||||
- 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.
|
||||
- You might also stumble on method calls with the older [`CALL METHOD`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcall_method_static.htm)
|
||||
statements. It is recommended to use the new syntax in new developments. Note that `CALL METHOD` statements are still required 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).
|
||||
|
||||
|
||||
@@ -6084,7 +6083,7 @@ ENDCLASS.
|
||||
### Additions Related to Interface Implementations
|
||||
|
||||
> **💡 Note**<br>
|
||||
> The code examples shows local classes and interfaces declared, for example, in the [CCIMP include](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenccimp_glosry.htm) of a class pool.
|
||||
> The code examples show local classes and interfaces declared, for example, in the [CCIMP include](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenccimp_glosry.htm) of a class pool.
|
||||
|
||||
<table>
|
||||
|
||||
|
||||
@@ -728,6 +728,7 @@ After the import of the repository, proceed as follows:
|
||||
- Run the program by choosing `F8`.
|
||||
|
||||
> **💡 Note**<br>
|
||||
> - The examples in the *main* branch of the ABAP cheat sheet repository are designed to be imported into the SAP BTP ABAP Environment. For Standard ABAP, you can find examples (such as `zdemo_abap_dynpro`) in the other branches of the repository.
|
||||
> - The executable example ...
|
||||
> - covers the following topics:
|
||||
> - Dynpro flow logic and related statements (`MODULE`, `FIELD`, `CHAIN`/`ENDCHAIN`, `LOOP`/`ENDLOOP`, `CALL SUBSCREEN`)
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
# Released ABAP Classes
|
||||
|
||||
- [Released ABAP Classes](#released-abap-classes)
|
||||
- [Excursion: Available Classes in ABAP for Cloud Development](#excursion-available-classes-in-abap-for-cloud-development)
|
||||
- [Excursions](#excursions)
|
||||
- [Available Classes in ABAP for Cloud Development](#available-classes-in-abap-for-cloud-development)
|
||||
- [Cloud Development Successors](#cloud-development-successors)
|
||||
- [Displaying Output in the ADT Console](#displaying-output-in-the-adt-console)
|
||||
- [Creating and Transforming UUIDs](#creating-and-transforming-uuids)
|
||||
- [XCO Representations of SY Components](#xco-representations-of-sy-components)
|
||||
@@ -52,7 +54,9 @@ This ABAP cheat sheet contains a selection of [released](https://help.sap.com/do
|
||||
> - You might find that different classes can achieve similar or the same results, especially with the Extension Components Library (XCO), a general-purpose development library designed specifically for ABAP for Cloud Development. Choose the classes that best meet your needs.
|
||||
> - [Disclaimer](./README.md#%EF%B8%8F-disclaimer)
|
||||
|
||||
## Excursion: Available Classes in ABAP for Cloud Development
|
||||
## Excursions
|
||||
|
||||
### Available Classes in ABAP for Cloud Development
|
||||
|
||||
If available to you, you have accessed an [SAP BTP ABAP Environment](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensap_btp_abap_env_glosry.htm) using the [ABAP development tools for Eclipse (ADT)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenadt_glosry.htm).
|
||||
Access to SAP-provided repository objects is restricted to objects that have been released for [ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_for_cloud_dev_glosry.htm) ([released APIs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreleased_api_glosry.htm)). You can find the released repository objects in the *Project Explorer* view in ADT under *Released Objects*. The classes are located in the *Source Code Library* folder:
|
||||
@@ -72,6 +76,26 @@ SELECT ReleasedObjectType, ReleasedObjectName, ReleaseState
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Cloud Development Successors
|
||||
|
||||
The `I_APIsWithCloudDevSuccessor` view provides information on objects that cannot or should no longer be used in ABAP for Cloud Development along with their successors that can be used.
|
||||
|
||||
```abap
|
||||
SELECT * FROM I_APIsWithCloudDevSuccessor
|
||||
INTO TABLE @DATA(successors_all).
|
||||
|
||||
SELECT * FROM I_APIsWithCloudDevSuccessor
|
||||
WHERE PredecessorObjectType = 'TABL'
|
||||
INTO TABLE @DATA(successors_tables).
|
||||
|
||||
SELECT SINGLE * FROM I_APIsWithCloudDevSuccessor
|
||||
WHERE PredecessorObjectName = 'TADIR'
|
||||
INTO @DATA(successor_tadir).
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
|
||||
## Displaying Output in the ADT Console
|
||||
|
||||
The table includes the <code>IF_OO_ADT_CLASSRUN</code> interface.
|
||||
@@ -237,7 +261,7 @@ ENDCLASS.
|
||||
<tr>
|
||||
<td> <code>CL_SYSTEM_UUID</code> </td>
|
||||
<td>
|
||||
Creating and and converting system UUIDs with various algorithms
|
||||
Creating and converting system UUIDs with various algorithms
|
||||
<br><br>
|
||||
|
||||
``` abap
|
||||
@@ -806,20 +830,68 @@ For calculations with integers of any size (e.g. to avoid the risk of an arithme
|
||||
<br><br>
|
||||
|
||||
``` abap
|
||||
"Creating an arbitrary precision integer from a variable of type i
|
||||
"and calculating the power; converting the result to string
|
||||
DATA(pow1) = cl_abap_bigint=>factory_from_int4( 10 )->pow( 10 )->to_string( ).
|
||||
"Comparison with integer value (the maximum value of type i; see the class above)
|
||||
DATA(compare_i) = cl_abap_bigint=>factory_from_int4( 10 )->pow( 10 )->compare_int4( cl_abap_math=>max_int4 ). "LARGER
|
||||
"Factories
|
||||
DATA(bigint_int4) = cl_abap_bigint=>factory_from_int4( 10 ).
|
||||
DATA(bigint_int4c) = cl_abap_bigint=>factory_from_string( `283469208407283452340` ).
|
||||
DATA(bigint_int4d) = cl_abap_bigint=>factory_from_int8( CONV int8( 1234567890123456 ) ).
|
||||
|
||||
"10000000000 (result)
|
||||
"2147483647 (maximum value for type i)
|
||||
DATA(a1) = cl_abap_bigint=>factory_from_int4( -10 )->to_external( ).
|
||||
DATA(a2) = cl_abap_bigint=>factory_from_int4( -10 )->to_external( iv_flg_minus_in_front = abap_true ).
|
||||
DATA(a3) = cl_abap_bigint=>factory_from_int4( 100 )->to_utf8( ).
|
||||
DATA(a4) = cl_abap_bigint=>factory_from_string( `123` )->to_df34( ).
|
||||
DATA(a5) = cl_abap_bigint=>factory_from_int4( -10 )->to_string( ).
|
||||
DATA(a6) = cl_abap_bigint=>factory_from_int4( 4 )->add( bigint_int4 )->to_string( ).
|
||||
DATA(a7) = cl_abap_bigint=>factory_from_int4( 7 )->add_int4( 2 )->to_string( ).
|
||||
DATA(a8) = cl_abap_bigint=>factory_from_int4( -10 )->abs( )->to_string( ).
|
||||
DATA(a9) = cl_abap_bigint=>factory_from_int4( 19 )->compare_int4( 20 ).
|
||||
DATA(a10) = cl_abap_bigint=>factory_from_int4( 100 )->compare( bigint_int4 ).
|
||||
DATA(a11) = cl_abap_bigint=>factory_from_int4( 20 )->div( bigint_int4 ).
|
||||
DATA(a12) = a11-quotient->to_string( ).
|
||||
DATA(a13) = a11-remainder->to_string( ).
|
||||
DATA(a14) = cl_abap_bigint=>factory_from_int4( 10 )->div_int4( 3 ).
|
||||
DATA(a15) = a14-quotient->to_string( ).
|
||||
DATA(a16) = a14-remainder.
|
||||
DATA(a17) = cl_abap_bigint=>factory_from_int4( 10 )->div_by_two_power( CONV int8( 2 ) )->to_string( ).
|
||||
DATA(a18) = cl_abap_bigint=>factory_from_int4( 5 )->div_to_df34( bigint_int4 ).
|
||||
DATA(a19) = cl_abap_bigint=>factory_from_int4( 50 )->gcd( bigint_int4 )->to_string( ).
|
||||
DATA(a20) = cl_abap_bigint=>factory_from_int4( 1000 )->get_number_of_bits( ).
|
||||
DATA(a21) = cl_abap_bigint=>factory_from_int4( 10 )->is_equal( bigint_int4 ).
|
||||
|
||||
"Comparison with the ipow function (here, an exception is raised)
|
||||
TRY.
|
||||
DATA(pow2) = ipow( base = 10 exp = 10 ).
|
||||
CATCH cx_sy_arithmetic_overflow.
|
||||
ENDTRY.
|
||||
cl_abap_bigint=>factory_from_string( `123` )->is_int4(
|
||||
IMPORTING
|
||||
ev_int4_value = DATA(a22)
|
||||
RECEIVING
|
||||
rv_flg_is_int4 = DATA(a23)
|
||||
).
|
||||
DATA(a24) = cl_abap_bigint=>factory_from_int4( 11 )->is_larger( bigint_int4 ).
|
||||
DATA(a25) = cl_abap_bigint=>factory_from_int4( 10 )->is_larger_or_equal( bigint_int4 ).
|
||||
DATA(a26) = cl_abap_bigint=>factory_from_int4( -10 )->is_negative( ).
|
||||
DATA(a27) = cl_abap_bigint=>factory_from_int4( 0 )->is_zero( ).
|
||||
DATA(a28) = cl_abap_bigint=>factory_from_int4( 123 )->mod( bigint_int4 )->to_string( ).
|
||||
DATA(a29) = cl_abap_bigint=>factory_from_int4( 10 )->mod_int4( 3 ).
|
||||
DATA(a30) = cl_abap_bigint=>factory_from_int4( 10 )->mul( bigint_int4 )->to_string( ).
|
||||
DATA(a31) = cl_abap_bigint=>factory_from_int4( 5 )->mul_by_two_power( 2 )->to_string( ).
|
||||
DATA(a32) = cl_abap_bigint=>factory_from_int4( 2 )->mul_int4( 5 )->to_string( ).
|
||||
DATA(a33) = cl_abap_bigint=>factory_from_int4( 8 )->pow( 2 )->to_string( ).
|
||||
DATA(a34) = cl_abap_bigint=>factory_from_int4( 9 )->sqrt( )->to_string( ).
|
||||
DATA(a35) = cl_abap_bigint=>factory_from_int4( 18 )->sub( bigint_int4 )->to_string( ).
|
||||
DATA(a36) = cl_abap_bigint=>factory_from_int4( 15 )->sub_int4( 9 )->to_string( ).
|
||||
"Cloning
|
||||
DATA(a37) = cl_abap_bigint=>factory_from_int4( 15 ).
|
||||
DATA(a38) = cl_abap_bigint=>factory_from_int4( 5 ).
|
||||
"Adding a number to another number to not get a new instance but the original instance
|
||||
DATA(a39) = a37->add( a38 ).
|
||||
ASSERT a39 = a37.
|
||||
DATA(a40) = a37->to_string( ).
|
||||
DATA(a41) = a39->to_string( ).
|
||||
DATA(a42) = cl_abap_bigint=>factory_from_int4( 15 ).
|
||||
DATA(a43) = cl_abap_bigint=>factory_from_int4( 5 ).
|
||||
|
||||
DATA(a44) = a42->clone( )->add( a43 ).
|
||||
ASSERT a44 <> a42.
|
||||
DATA(a45) = a42->to_string( ).
|
||||
DATA(a46) = a44->to_string( ).
|
||||
DATA(a47) = cl_abap_bigint=>factory_from_int4( 15 )->sub_int4( 9 )->clone( )->to_string( ).
|
||||
```
|
||||
|
||||
</td>
|
||||
@@ -832,12 +904,28 @@ For calculations with rational numbers without precision loss and rounding error
|
||||
|
||||
``` abap
|
||||
"Creating a rational number from a string
|
||||
DATA(rat_num) = cl_abap_rational=>factory_from_string(
|
||||
EXPORTING iv_value = `-1/3` ).
|
||||
DATA(rat_num) = cl_abap_rational=>factory_from_string( `-1/3` ).
|
||||
|
||||
"Performing an addition and converting the result to string
|
||||
DATA(addition_res) = rat_num->add( cl_abap_rational=>factory_from_string(
|
||||
EXPORTING iv_value = `3/2` ) )->to_string( ). "7/6
|
||||
"7/6
|
||||
DATA(addition_res) = rat_num->add( cl_abap_rational=>factory_from_string( `3/2` ) )->to_string( ).
|
||||
|
||||
"Factories
|
||||
DATA(r1) = cl_abap_rational=>factory_from_string( `-1/3` ).
|
||||
DATA(r2) = cl_abap_rational=>factory_from_bigint( cl_abap_bigint=>factory_from_int4( 11 ) ).
|
||||
|
||||
TYPES p_l16d5 TYPE p LENGTH 16 DECIMALS 5.
|
||||
DATA(r3) = cl_abap_rational=>factory_from_dec( CONV p_l16d5( '123456.789' ) ).
|
||||
DATA(r4) = cl_abap_rational=>factory_from_decimal_string( `1.234567890` ).
|
||||
DATA(r5) = cl_abap_rational=>factory_from_df34( `1.4` ).
|
||||
DATA(r6) = cl_abap_rational=>factory_from_int4( 100 ).
|
||||
DATA(r7) = cl_abap_rational=>factory_from_int8( CONV int8( 123 ) ).
|
||||
DATA(r8) = cl_abap_rational=>factory_from_string( `-2/3` )->add_int4( 1 )->to_df34( ).
|
||||
DATA(r9) = cl_abap_rational=>factory_from_string( `-2/3` )->add_int4( 1 )->to_string( ).
|
||||
DATA r10 TYPE p_l16d5.
|
||||
cl_abap_rational=>factory_from_string( `-2/3` )->add_int4( 1 )->to_dec( IMPORTING ev_decimal = r10 ).
|
||||
"Methods that include cl_abap_bigint instances
|
||||
DATA(r11) = cl_abap_rational=>factory_from_string( `-2/3` )->add_bigint( cl_abap_bigint=>factory_from_int4( 1 ) )->to_string( ).
|
||||
```
|
||||
|
||||
</td>
|
||||
@@ -2699,7 +2787,7 @@ DATA table_json_to_abap TYPE string_table.
|
||||
<td> Class </td> <td> Details/Code Snippet </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> <code>XCO_CP_ABAP</code><br><code>XCO_CP_ABAP_REPOSITORY</code> </td>
|
||||
<td> <code>XCO_CP_ABAP</code><br><code>XCO_CP_ABAP_REPOSITORY</code><br><code>XCO_CP_ABAP_DICTIONARY</code> </td>
|
||||
<td>
|
||||
|
||||
<ul>
|
||||
@@ -2777,41 +2865,231 @@ LOOP AT type_names INTO DATA(type_name).
|
||||
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 (->)
|
||||
"to the final parenthesis and checking the suggestions by ADT.
|
||||
"Database table
|
||||
DATA(handler_tabl) = xco_cp_abap_dictionary=>database_table( 'ZDEMO_ABAP_CARR' ).
|
||||
"Data element
|
||||
DATA(handler_dtel) = xco_cp_abap_dictionary=>data_element( 'MANDT' ).
|
||||
"Table type
|
||||
DATA(handler_table_type) = xco_cp_abap_dictionary=>table_type( 'STRING_TABLE' ).
|
||||
"CDS view entity
|
||||
DATA(handler_cds_ve) = xco_cp_cds=>view_entity( 'ZDEMO_ABAP_RAP_RO_M' ).
|
||||
"Interface
|
||||
DATA(handler_intf) = xco_cp_abap=>interface( 'ZDEMO_ABAP_OBJECTS_INTERFACE' ).
|
||||
"Getting information about where the interface is implemented
|
||||
DATA(where_is_intf_impl) = handler_intf->implementations->all->get_names( ).
|
||||
"Class
|
||||
DATA(handler_cl) = xco_cp_abap=>class( 'ZCL_DEMO_ABAP_UNIT_TEST' ).
|
||||
"Getting subclasses
|
||||
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(
|
||||
)->get_superclass( )->name.
|
||||
"The following code snippets demonstrate getting information about some
|
||||
"of the technical properties of different ABAP repository objects.
|
||||
"Using the handlers, you can explore more options, e.g., by adding the object
|
||||
"component selector (->) to the final parenthesis and checking the suggestions
|
||||
"by ADT. The options shown are not comprehensive. They show a selection.
|
||||
"The same information may be accessed in different ways via the various
|
||||
"methods available.
|
||||
|
||||
"Taking an XCO handler for a database table as an example, see some of the
|
||||
"details you can retrieve. The method names should be self-explanatory.
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Database table
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(handler_tabl) = xco_cp_abap_dictionary=>database_table( 'ZDEMO_ABAP_CARR' ).
|
||||
DATA(dbtab_exists) = handler_tabl->exists( ).
|
||||
DATA(dbtab_name) = handler_tabl->name.
|
||||
DATA(dbtab_descr) = handler_tabl->content( )->get_short_description( ).
|
||||
DATA(dbtab_del_cl) = handler_tabl->content( )->get_delivery_class( )->value.
|
||||
DATA(dbtab_syntax_check_msg) = handler_tabl->check_syntax( )->messages.
|
||||
DATA(dbtab_content) = handler_tabl->content( ).
|
||||
"Technical information
|
||||
DATA(dbtab_short_description) = dbtab_content->get_short_description( ).
|
||||
DATA(dbtab_delivery_class) = dbtab_content->get_delivery_class( )->value.
|
||||
DATA(dbtab_technical_settings) = dbtab_content->get_technical_settings( ).
|
||||
DATA(dbtab_data_maintenance) = dbtab_content->get_data_maintenance( )->value.
|
||||
DATA(dbtab_enhancement_category) = dbtab_content->get_enhancement_category( )->value.
|
||||
DATA(dbtab_includes) = dbtab_content->get_includes( ).
|
||||
"Same information accessed in other ways
|
||||
DATA(dbtab_get_content) = dbtab_content->get( ).
|
||||
DATA(dbtab_data_maint_alt) = dbtab_get_content-data_maintenance->value.
|
||||
DATA(dbtab_delivery_cl_alt) = dbtab_get_content-delivery_class->value.
|
||||
DATA(dbtab_enh_cat_alt) = dbtab_get_content-enhancement_category->value.
|
||||
DATA(dbtab_includes_alt) = dbtab_get_content-includes.
|
||||
"Table fields and keys
|
||||
DATA(dbtab_field_names) = handler_tabl->fields->all->get_names( ).
|
||||
DATA(dbtab_fields_built_in_types) = handler_tabl->fields->all->content( )->get_underlying_built_in_types( ).
|
||||
DATA(dbtab_keys) = handler_tabl->fields->key->get_names( ).
|
||||
DATA(dbtab_vis) = handler_tabl->get_api_state( )->get_visibilities( ). "Initial for the cheat sheet table
|
||||
DATA(dbtab_rel_state) = handler_tabl->get_api_state( )->get_release_state( )->value.
|
||||
DATA(dbtab_included_fields) = handler_tabl->fields->included->get_names( ).
|
||||
"Release state and visibilities
|
||||
DATA(dbtab_visibilities) = handler_tabl->get_api_state( )->get_visibilities( ).
|
||||
DATA(dbtab_release_state) = handler_tabl->get_api_state( )->get_release_state( )->value.
|
||||
|
||||
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Data element
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(handler_dtel) = xco_cp_abap_dictionary=>data_element( 'ABAP_BOOLEAN' ).
|
||||
DATA(dtel_exists) = handler_dtel->exists( ).
|
||||
DATA(dtel_name) = handler_dtel->name.
|
||||
DATA(dtel_syntax_check_msg) = handler_dtel->check_syntax( )->messages.
|
||||
DATA(dtel_content) = handler_dtel->content( ).
|
||||
"Labels
|
||||
DATA(dtel_heading_label) = dtel_content->get_heading_field_label( ).
|
||||
DATA(dtel_short_label) = dtel_content->get_short_field_label( ).
|
||||
DATA(dtel_long_label) = dtel_content->get_long_field_label( ).
|
||||
DATA(dtel_medium_label) = dtel_content->get_medium_field_label( ).
|
||||
DATA(dtel_description) = dtel_content->get_short_description( ).
|
||||
"Type information
|
||||
DATA(dtel_has_built_in_type) = dtel_content->has_underlying_built_in_type( ).
|
||||
IF dtel_has_built_in_type = abap_true.
|
||||
DATA(dtel_built_in_type) = dtel_content->get_underlying_built_in_type( ).
|
||||
DATA(dtel_built_in_type_length) = dtel_built_in_type->length.
|
||||
DATA(dtel_buift_in_type_type) = dtel_built_in_type->type.
|
||||
DATA(dtel_type_descriptor) = dtel_built_in_type->abap_type->get_type_descriptor( ).
|
||||
DATA(dtel_built_in_type_abs_name) = dtel_built_in_type->abap_type->get_type_descriptor( )->absolute_name.
|
||||
DATA(dtel_built_in_type_kind) = dtel_built_in_type->abap_type->get_type_descriptor( )->kind.
|
||||
ENDIF.
|
||||
"Domain information
|
||||
DATA(dtel_domain) = dtel_content->get_data_type( )->get_domain( ).
|
||||
IF dtel_domain IS NOT INITIAL.
|
||||
DATA(dtel_domain_name) = dtel_domain->name.
|
||||
DATA(dtel_domain_content) = dtel_domain->content( ).
|
||||
DATA(dtel_domain_built_in_type) = dtel_domain_content->get_format( )->get_built_in_type( ).
|
||||
DATA(dtel_domain_output_ch) = dtel_domain_content->get_output_characteristics( ).
|
||||
DATA(dtel_domain_description) = dtel_domain_content->get_short_description( ).
|
||||
DATA(dtel_domain_fixed_values) = dtel_domain->fixed_values->all->get( ).
|
||||
ENDIF.
|
||||
"Release state and visibilities
|
||||
DATA(dtel_release_state) = handler_dtel->get_api_state( )->get_release_state( )->value.
|
||||
DATA(dtel_visibilities) = handler_dtel->get_api_state( )->get_visibilities( ).
|
||||
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Table type
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(handler_table_type) = xco_cp_abap_dictionary=>table_type( 'ABP_BEHV_RESPONSE_TAB' ).
|
||||
DATA(table_type_exists) = handler_table_type->exists( ).
|
||||
DATA(table_type_name) = handler_table_type->name.
|
||||
DATA(table_type_syntax_check_msg) = handler_table_type->check_syntax( )->messages.
|
||||
DATA(table_type_content) = handler_table_type->content( ).
|
||||
DATA(table_type_access) = table_type_content->get_access( )->value.
|
||||
"Key information
|
||||
DATA(table_type_primary_key) = table_type_content->get_primary_key( ).
|
||||
DATA(table_type_key_category) = table_type_primary_key->key_category->value.
|
||||
DATA(table_type_key_components) = table_type_primary_key->key_components.
|
||||
DATA(table_type_key_definition) = table_type_primary_key->key_definition->value.
|
||||
DATA(table_type_secondary_keys) = table_type_content->get_secondary_keys( ).
|
||||
DATA(table_type_description) = table_type_content->get_short_description( ).
|
||||
"Row type information
|
||||
DATA(table_type_row_type) = table_type_content->get_row_type( ).
|
||||
DATA(table_type_structure) = table_type_row_type->get_structure( ).
|
||||
DATA(table_type_struct_name) = table_type_structure->name.
|
||||
DATA(table_type_struct_comp_names) = table_type_structure->components->all->get_names( ).
|
||||
DATA(table_type_struct_comps) = table_type_structure->components->all->get( ).
|
||||
DATA(table_type_content_get_alt) = table_type_content->get( ).
|
||||
DATA(table_type_pr_key_alt) = table_type_content_get_alt-primary_key->key_components.
|
||||
DATA(table_type_sec_key_alt) = table_type_content_get_alt-secondary_keys.
|
||||
"Release state and visibilities
|
||||
DATA(table_type_release_state) = handler_table_type->get_api_state( )->get_release_state( )->value.
|
||||
DATA(table_type_visibilities) = handler_table_type->get_api_state( )->get_visibilities( ).
|
||||
|
||||
*&---------------------------------------------------------------------*
|
||||
*& CDS view entity
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(handler_cds_ve) = xco_cp_cds=>view_entity( 'ZDEMO_ABAP_RAP_RO_M' ).
|
||||
DATA(cds_ve_exists) = handler_cds_ve->exists( ).
|
||||
DATA(cds_ve_name) = handler_cds_ve->name.
|
||||
DATA(cds_ve_associations) = handler_cds_ve->associations->all->get( ).
|
||||
DATA(cds_ve_compositions) = handler_cds_ve->compositions->all->get( ).
|
||||
DATA(cds_ve_field_names) = handler_cds_ve->fields->all->get_names( ).
|
||||
"Field information
|
||||
DATA(cds_ve_fields) = handler_cds_ve->fields->all->get( ).
|
||||
LOOP AT cds_ve_fields INTO DATA(ve).
|
||||
DATA(cds_ve_f_content) = ve->content( ).
|
||||
DATA(cds_ve_f_alias) = cds_ve_f_content->get_alias( ).
|
||||
DATA(cds_ve_f_assoc) = cds_ve_f_content->get_association( ).
|
||||
DATA(cds_ve_f_comp) = cds_ve_f_content->get_composition( ).
|
||||
DATA(cds_ve_f_key_indicator) = cds_ve_f_content->get_key_indicator( ).
|
||||
ENDLOOP.
|
||||
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Class
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(handler_cl) = xco_cp_abap=>class( 'CL_ABAP_TYPEDESCR' ).
|
||||
DATA(cl_exists) = handler_cl->exists( ).
|
||||
DATA(cl_name) = handler_cl->name.
|
||||
DATA(cl_syntax_check_msg) = handler_cl->check_syntax( )->messages.
|
||||
"Creation and change information
|
||||
DATA(cl_created_by) = handler_cl->get_created_by( ).
|
||||
DATA(cl_created_on) = handler_cl->get_created_on( ).
|
||||
DATA(cl_last_changed_by) = handler_cl->get_last_changed_by( ).
|
||||
DATA(cl_last_changed_on) = handler_cl->get_last_changed_on( ).
|
||||
"Subclasses
|
||||
DATA(cl_subclasses) = handler_cl->subclasses->all->get_names( ).
|
||||
"Information on the definition part
|
||||
DATA(cl_definition) = handler_cl->definition->content( ).
|
||||
DATA(cl_definition_get) = cl_definition->get( ).
|
||||
DATA(cl_final) = cl_definition->get_final_indicator( ).
|
||||
DATA(cl_abstract) = cl_definition->get_abstract_indicator( ).
|
||||
DATA(cl_friends) = cl_definition->get_global_friends( ).
|
||||
DATA(cl_interfaces) = cl_definition->get_interfaces( ).
|
||||
DATA(cl_definition_visibility) = cl_definition->get_visibility( )->value.
|
||||
"Superclass
|
||||
DATA(cl_superclass) = cl_definition->get_superclass( ).
|
||||
IF cl_superclass IS NOT INITIAL.
|
||||
DATA(cl_superclass_name) = cl_superclass->name.
|
||||
DATA(cl_superclass_content) = cl_superclass->content( ).
|
||||
ENDIF.
|
||||
"Associated behavior definition
|
||||
DATA(cl_for_behv) = cl_definition->get_for_behavior_of( ).
|
||||
IF cl_for_behv IS NOT INITIAL.
|
||||
DATA(cl_for_behv_name) = cl_for_behv->name.
|
||||
DATA(cl_for_behv_content) = cl_for_behv->content( ).
|
||||
ENDIF.
|
||||
"Information on components in the visibility sections
|
||||
DATA(cl_private_components) = handler_cl->definition->section-private->components.
|
||||
DATA(cl_protected_components) = handler_cl->definition->section-protected->components.
|
||||
DATA(cl_public_components) = handler_cl->definition->section-public->components.
|
||||
"Component information
|
||||
DATA(cl_all_public_inst_methods) = cl_public_components->method->all->get( ).
|
||||
DATA(cl_all_public_stat_methods) = cl_public_components->class_method->all->get( ).
|
||||
DATA(cl_all_public_inst_attr) = cl_public_components->data->all->get( ).
|
||||
DATA(cl_all_public_static_attr) = cl_public_components->class_data->all->get( ).
|
||||
DATA(cl_all_public_constants) = cl_public_components->constant->all->get( ).
|
||||
DATA(cl_all_public_alias_comps) = cl_public_components->alias->all->get( ).
|
||||
"More detailed information on components (the examples uses static methods of the class)
|
||||
LOOP AT cl_all_public_stat_methods INTO DATA(stat_meth).
|
||||
DATA(meth_name) = stat_meth->name.
|
||||
"Parameter information
|
||||
DATA(meth_importing_params) = stat_meth->importing_parameters->all->get( ).
|
||||
LOOP AT meth_importing_params INTO DATA(import).
|
||||
DATA(import_param_name) = import->name.
|
||||
DATA(import_param_content) = import->content( )->get( ).
|
||||
ENDLOOP.
|
||||
|
||||
DATA(meth_exporting_params) = stat_meth->exporting_parameters->all->get( ).
|
||||
DATA(meth_changing_params) = stat_meth->changing_parameters->all->get( ).
|
||||
DATA(meth_returning_params) = stat_meth->returning_parameters->all->get( ).
|
||||
DATA(meth_exceptions) = stat_meth->exceptions->all->get( ).
|
||||
DATA(meth_all_param_names) = stat_meth->parameters->all->get_names( ).
|
||||
|
||||
DATA(meth_get) = stat_meth->content( )->get( ).
|
||||
DATA(meth_abstract) = stat_meth->content( )->get_abstract_indicator( ).
|
||||
DATA(meth_amdp) = stat_meth->content( )->get_amdp( ).
|
||||
DATA(meth_final) = stat_meth->content( )->get_final_indicator( ).
|
||||
DATA(meth_redefinition) = stat_meth->content( )->get_redefinition_indicator( ).
|
||||
DATA(meth_description) = stat_meth->content( )->get_short_description( ).
|
||||
|
||||
"Source code of the method implementation
|
||||
DATA(meth_implementation) = handler_cl->implementation->method( meth_name )->content( )->get( )-source.
|
||||
ENDLOOP.
|
||||
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Interface
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(handler_intf) = xco_cp_abap=>interface( 'ZDEMO_ABAP_OBJECTS_INTERFACE' ).
|
||||
DATA(intf_exists) = handler_intf->exists( ).
|
||||
DATA(intf_name) = handler_intf->name.
|
||||
DATA(intf_syntax_check_msg) = handler_intf->check_syntax( )->messages.
|
||||
"Creation and change information
|
||||
DATA(intf_created_by) = handler_intf->get_created_by( ).
|
||||
DATA(intf_created_on) = handler_intf->get_created_on( ).
|
||||
DATA(intf_last_changed_by) = handler_intf->get_last_changed_by( ).
|
||||
DATA(intf_last_changed_on) = handler_intf->get_last_changed_on( ).
|
||||
"Interface content information
|
||||
DATA(intf_get) = handler_intf->content( )->get( ).
|
||||
DATA(intf_description) = handler_intf->content( )->get_short_description( ).
|
||||
"Component information
|
||||
DATA(intf_components) = handler_intf->components.
|
||||
"Getting information about where the interface is implemented
|
||||
DATA(intf_implementations_get) = handler_intf->implementations->all->get( ).
|
||||
DATA(intf_implementations_names) = handler_intf->implementations->all->get_names( ).
|
||||
"Note that methods are available as shown for classes
|
||||
DATA(intf_static_meths) = handler_intf->components->class_method->all->get( ).
|
||||
```
|
||||
|
||||
</td>
|
||||
@@ -3067,7 +3345,7 @@ DATA(sub_acc_id) = ten->get_subaccount_id( )->as_string( ).
|
||||
|
||||
Exception classes are special classes, usually starting with the name <code>CX_*</code>, that serve as the basis for <a href="https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencatchable_exception_glosry.htm">catchable exceptions</a>. When an exception is raised, an object of such an exception class is created. There are several predefined exception classes. Find more information in the [Exceptions and Runtime Errors](27_Exceptions.md) cheat sheet.
|
||||
|
||||
<br><br>
|
||||
<br>
|
||||
|
||||
``` abap
|
||||
TRY.
|
||||
|
||||
@@ -602,7 +602,7 @@ DATA(applies_to_data_cds_st) = tdo_cds_simple_type->applies_to_data( CONV c5( 'a
|
||||
- The value set can be used to validate allowed values, similar to fixed values in DDIC domains.
|
||||
- They can be used ...
|
||||
- in ABAP CDS to type elements or parameters, for casting, and in comparisons. More details and examples are available [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_use_enum_type.htm).
|
||||
- in ABAP for [enumerated variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenenumerated_variable_glosry.htm). An [enumerated structure](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenenumerated_structure_glosry.htm) with the CDS enumerated type name is automatically declared, functioning like [ABAP enumerated type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenenumerated_type_glosry.htm).
|
||||
- in ABAP for [enumerated variables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenenumerated_variable_glosry.htm). An [enumerated structure](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenenumerated_structure_glosry.htm) with the CDS enumerated type name is automatically declared, functioning like [ABAP enumerated types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenenumerated_type_glosry.htm).
|
||||
- To create the types, you ...
|
||||
- specify a list of enumerated constants that are assigned values as untyped literals. One component must be set as initial to establish the base type's initial value.
|
||||
- define a base type. Possible base types include `int1`, `int2`, `int4`, `char`, and `numc`, with the last two having a maximum length of 8.
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
- [Numeric Functions](#numeric-functions)
|
||||
- [Calculations with System Classes](#calculations-with-system-classes)
|
||||
- [Calculations with Date, Time and Time Stamp Values](#calculations-with-date-time-and-time-stamp-values)
|
||||
- [Arithmetic Expressions and Built-in Functions ABAP SQL and ABAP CDS](#arithmetic-expressions-and-built-in-functions-abap-sql-and-abap-cds)
|
||||
- [Arithmetic Expressions and Built-in Functions in ABAP SQL and ABAP CDS](#arithmetic-expressions-and-built-in-functions-in-abap-sql-and-abap-cds)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ This cheat sheet explores various aspects of numeric operations and calculations
|
||||
- Calculations use numeric data objects or those convertible to numeric types.
|
||||
- ABAP supports specific elementary numeric data types.
|
||||
- These types have distinct characteristics and value ranges, allowing the use for various purposes.
|
||||
- This cheat sheet covers only [built-in ABAP types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuiltin_abap_type_glosry.htm). [Built-in DDIC types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuiltin_ddic_type_glosry.htm) are also available for defining types in the [ABAP Dictionary DDIC)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_dictionary_glosry.htm) and ABAP CDS. These types cannot be used directly in ABAP programs except for typed literals. They map to built-in ABAP types; for example, the DDIC type `INT4` maps to type `i`, and `DECFLOAT16` maps to the built-in ABAP type `decfloat16`.
|
||||
- This cheat sheet covers only [built-in ABAP types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuiltin_abap_type_glosry.htm). [Built-in DDIC types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuiltin_ddic_type_glosry.htm) are also available for defining types in the [ABAP Dictionary DDIC)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_dictionary_glosry.htm) and ABAP CDS. These types cannot be used directly in ABAP programs except for typed literals. They are mapped to built-in ABAP types; for example, the DDIC type `INT4` is mapped to type `i`, and `DECFLOAT16` is mapped to the built-in ABAP type `decfloat16`.
|
||||
- Most types' values (except type `i`) cannot be directly specified in the program and must be represented by character literals interpretable as the respective type.
|
||||
|
||||
<table>
|
||||
@@ -52,7 +52,7 @@ This cheat sheet explores various aspects of numeric operations and calculations
|
||||
- The type `i` can hold 4-byte integers, typically used for counters or indexes (like `sy-index` or `sy-tabix`), quantities, and more.
|
||||
- `int8` holds 8-byte integers and offers a larger value range than `i`.
|
||||
- You can specify integer numbers with type `i` directly in ABAP programs as [numeric literals](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abennumeric_literal_glosry.htm).
|
||||
- You might encounter the types `b` (1-byte integers) and `s` (2-byte integers) for short integers. They cannot be directly specified in ABAP programs, but you can use the built-in DDIC types `INT1` and `INT2`.
|
||||
- You might encounter the types `b` (1-byte integers) and `s` (2-byte integers) for short integers. They cannot be directly specified in ABAP programs, but you can use the DDIC types `INT1` and `INT2`.
|
||||
- If these integer types do not meet your value range needs, consider using type `p` without decimal places or floating point types for larger ranges. However, calculations will be slower then.
|
||||
|
||||
</td>
|
||||
@@ -314,7 +314,7 @@ DATA(random_p_d14) = cl_abap_random_packed_dec14=>create( seed = cl_abap_random=
|
||||
|
||||
- Most numeric types (except type `i`) cannot be directly specified in the program. These values use character literals that can be interpreted as their respective types.
|
||||
- The following code snippet demonstrates mathematical, commercial, and scientific notations. Not all notations are possible for each numeric type.
|
||||
- In this context, also check the [Formatting Options in String Templates](07_String_Processing.md#formatting-options-in-string-templates) in the *String Processing* cheat sheet.
|
||||
- In this context, you can also check the [Formatting Options in String Templates](07_String_Processing.md#formatting-options-in-string-templates) in the *String Processing* cheat sheet.
|
||||
|
||||
```abap
|
||||
"Mathematical notations
|
||||
@@ -419,12 +419,12 @@ dec34_n = EXACT #( `.9E-3 ` ).
|
||||
- Data objects of numeric data types (named and unnamed data objects)
|
||||
- Data objects whose content can be converted to numeric data types
|
||||
- Numeric functions returning a numeric value
|
||||
- Functional methods calls returning a numeric value
|
||||
- Functional method calls returning a numeric value
|
||||
- ABAP supports these arithmetic operators: `+`, `-`, `*`, `/`, `DIV`, `MOD`, and `**`. Notes:
|
||||
- `DIV`: Returns the integer part of the division of the left operand by the right, with a positive remainder.
|
||||
- `MOD`: Returns a positive remainder of the division of the left operand by the right.
|
||||
- `**`: Raises the left operand to the power of the right (Note: Can produce type `f`; consider using the `ipow` function as an alternative if you want to avoid the type `f`.)
|
||||
- Parentheses in arithmetic expressions prioritize the calculations inside them.
|
||||
- Parentheses in arithmetic expressions prioritize the calculations inside them.
|
||||
- You can combine one or more operands to perform calculations.
|
||||
- You can prefix operands with `+` or `-` signs.
|
||||
- Note that calculations can trigger exceptions. If not caught, these result in runtime errors.
|
||||
@@ -433,7 +433,7 @@ dec34_n = EXACT #( `.9E-3 ` ).
|
||||
|
||||
|
||||
> **💡 Note**<br>
|
||||
> - A zero division if the first operand is also 0 does not raise an exception. The result is set to 0.
|
||||
> - If the first operand is also 0 in a zero division, an exception is not raised. Instead, the result is set to 0.
|
||||
> - For more information on the `DIV` and `MOD` operators, refer to [this blog](https://community.sap.com/t5/technology-blogs-by-sap/understanding-div-and-mod-in-abap-and-beyond/ba-p/14015181).
|
||||
|
||||
|
||||
@@ -1056,7 +1056,7 @@ int_calc /= 2. "25
|
||||
### Lossless Calculations
|
||||
|
||||
- You can use the `EXACT` operator to verify lossless assignments and calculations.
|
||||
- It works for assignments between incompatible data objects, meaning those without matching type specifications.
|
||||
- It is suitable for assignments between incompatible data objects, meaning those without matching type specifications.
|
||||
- After an assignment with `EXACT`, the target data object will hold a valid value; otherwise, it raises an exception.
|
||||
- Forced rounding during an assignment indicates it is not lossless. In the context of arithmetic expressions, a lossless calculation is performed.
|
||||
|
||||
@@ -1746,13 +1746,13 @@ DATA(tsc) = cl_abap_tstmp=>subtractsecs( tstmp = tsa
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Arithmetic Expressions and Built-in Functions ABAP SQL and ABAP CDS
|
||||
## Arithmetic Expressions and Built-in Functions in ABAP SQL and ABAP CDS
|
||||
|
||||
More information:
|
||||
- ABAP SQL: [Arithmetic expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABENSQL_ARITH.html), [Numeric functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABENSQL_ARITH_FUNC.html)
|
||||
- ABAP CDS: [Arithmetic expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABENCDS_ARITHMETIC_EXPRESSION_V2.html), [Numeric functions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABENCDS_SQL_FUNCTIONS_NUMERIC_V2.html)
|
||||
|
||||
The following example code snippet includes an ABAP SQL `SELECT` statement with a selection of arithmetic expressions and numeric functions. You can also check [Aggregate expressions](03_ABAP_SQL.md#aggregate-expressions) that perform calculations as described in the *ABAP SQL* cheat sheet.
|
||||
The following example code snippet includes an ABAP SQL `SELECT` statement with a selection of arithmetic expressions and numeric functions. You can also check [aggregate expressions](03_ABAP_SQL.md#aggregate-expressions) that perform calculations as described in the *ABAP SQL* cheat sheet.
|
||||
|
||||
```abap
|
||||
SELECT SINGLE
|
||||
|
||||
@@ -27,7 +27,7 @@ This ABAP cheat sheet provides references to detailed information on *Generative
|
||||
|
||||
## Using the ABAP AI SDK
|
||||
|
||||
- This section explores several released ABAP classes within the ABAP AI SDK for interacting with large language models (LLMs) in custom implementations.
|
||||
- This section explores released ABAP classes within the ABAP AI SDK for interacting with large language models (LLMs) in custom implementations.
|
||||
- Find more information in [Developing Your Own AI-Enabled Applications](https://help.sap.com/docs/ABAP_AI/c7f5ef43ab274d078baf22f995fd2161/27c5d27b480043f0a9fd8e46ae8275a2.html?locale=en-US).
|
||||
|
||||
> **💡 Note**<br>
|
||||
@@ -86,7 +86,7 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
out->write( |1) Creating an instance of the ISLM completion API\n| ).
|
||||
|
||||
TRY.
|
||||
DATA(ai_api) = cl_aic_islm_compl_api_factory=>get( )->create_instance( islm_scenario ).
|
||||
ai_api = cl_aic_islm_compl_api_factory=>get( )->create_instance( islm_scenario ).
|
||||
CATCH cx_aic_api_factory INTO error.
|
||||
error_text = error->get_text( ).
|
||||
out->write( error_text ).
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
|
||||
ABAP cheat sheets[^1] ...
|
||||
- provide a **collection of information on selected ABAP topics** in a nutshell for your reference.
|
||||
- focus on **ABAP syntax** in the restricted ABAP language version [ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_for_cloud_dev_glosry.htm).
|
||||
- focus on **ABAP syntax** in the restricted ABAP language version [ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_for_cloud_dev_glosry.htm), particularly in the [SAP BTP ABAP Environment](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensap_btp_abap_env_glosry.htm).
|
||||
- include **code snippets**.
|
||||
- are supported by easy-to-consume **demonstration examples** that you can import into your system using [abapGit](https://abapgit.org/) to run and check out ABAP syntax in action in simple contexts:
|
||||
| Environment | Branch | ABAP language version |
|
||||
| -------- | ------- | ------- |
|
||||
| [SAP BTP ABAP environment](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensap_btp_abap_env_glosry.htm) | *main* branch | [ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_for_cloud_dev_glosry.htm) |
|
||||
| [SAP BTP ABAP Environment](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensap_btp_abap_env_glosry.htm) | *main* branch | [ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_for_cloud_dev_glosry.htm) |
|
||||
| System that supports [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm) | The repository branches other than *main*. Check the available ABAP releases. |[Standard ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_abap_glosry.htm) |
|
||||
|
||||
- are enriched by links to glossary entries and chapters of the **ABAP Keyword Documentation** (the *F1 help*) and more for you to deep dive into the respective ABAP topics and get more comprehensive information.
|
||||
@@ -42,7 +42,7 @@ ABAP cheat sheets[^1] ...
|
||||
<br>
|
||||
|
||||
- Since the ABAP cheat sheets provide information in a nutshell, they do not claim to be fully comprehensive as far as the described syntax and concepts are concerned. If you need more details, you can always consult the ABAP Keyword Documentation, for example, by choosing *F1* on a keyword in your code, or by searching directly using the online or the system-internal version.
|
||||
- Unless otherwise stated in the cheat sheets, the content of this repository is relevant for these ABAP language versions, with a focus on ABAP for Cloud Development ⚠️:
|
||||
- Unless otherwise stated in the cheat sheets, the content of this repository is relevant for these ABAP language versions, with a focus on ABAP for Cloud Development, particularly in the SAP BTP ABAP Environment ⚠️:
|
||||
- [ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_for_sap_cloud_glosry.htm): Restricted ABAP language scope for [ABAP Cloud](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_cloud_glosry.htm) → [Online version of the documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm)
|
||||
- [Standard ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenstandard_abap_glosry.htm): Unrestricted ABAP language scope, for example, for [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm) → [Online version of the documentation (latest version)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap.htm)
|
||||
- Some of the embedded code snippets in the cheat sheets only display high-level code patterns, while others are fully functional and can be directly copied into an ABAP test program for exploration.
|
||||
|
||||
Reference in New Issue
Block a user