This commit is contained in:
danrega
2024-08-15 17:02:26 +02:00
parent 492b801c6a
commit 839a48e86d
6 changed files with 109 additions and 19 deletions

View File

@@ -41,6 +41,7 @@
- [Operations with Internal Tables Using ABAP SQL SELECT Statements](#operations-with-internal-tables-using-abap-sql-select-statements)
- [Internal Tables as Target Data Objects in SELECT Queries](#internal-tables-as-target-data-objects-in-select-queries)
- [SELECT Queries with Internal Tables as Data Sources](#select-queries-with-internal-tables-as-data-sources)
- [Excursion: Restrictions Regarding Selecting from Internal Tables](#excursion-restrictions-regarding-selecting-from-internal-tables)
- [Sorting Internal Tables](#sorting-internal-tables)
- [Modifying Internal Table Content](#modifying-internal-table-content)
- [Deleting Internal Table Content](#deleting-internal-table-content)
@@ -1499,12 +1500,13 @@ ENDDO.
#### BINARY SEARCH Addition: Optimized Read Access When Specifying Free Keys
Find information and an example in the expandable section below
You may stumble on the `BINARY SEARCH` addition to `READ TABLE` statements for an optimized access. However, it is recommended to use sorted tables or secondary table keys for an optimized access. Find information and an example in the expandable section below.
```abap
READ TABLE itab WITH KEY ... BINARY SEARCH ...
```
<details>
<summary>Expand to view more information and a code snippet</summary>
<!-- -->
@@ -2551,7 +2553,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"SELECT query with an internal table as data source
"The example uses an aggregate expression. It is statically
"detected that the query cannot be processed by the ABAP SQL
"enginge. The data must be passed to the database. Consequently,
"engine. The data must be passed to the database. Consequently,
"a syntax warning is displayed. It can be suppressed by a pragma.
SELECT MAX( table_line ) AS max_val
FROM @itab_a AS it
@@ -2684,6 +2686,78 @@ ENDCLASS.
<p align="right"><a href="#top">⬆️ back to top</a></p>
#### Excursion: Restrictions Regarding Selecting from Internal Tables
- This excursion is intended to underscore the restricitions mentioned above and in the [documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_engine_restr.htm) in more detail when selecting from internal tables.
- Components having deep types, such as strings, cannot be included, for example, in the `SELECT` list or `WHERE` clause.
- Note that only those fields are checked (and sent to the database) that are actually used (as shown in the example below).
- However, the type string is allowed if it is declared using the built-in dictionary type `sstring` (for example, a component typed with a [data element](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_element_glosry.htm) or a [CDS simple type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_simple_type_glosry.htm) that uses `sstring`).
The following example demonstrates various `SELECT` statements. A demo internal table has a component that is typed with a CDS simple type, which can be created as follows:
- In ADT, right-click your pacakage, and choose *New -> Other Repository Object*
- Insert *type* and select *Type* under *Core Data Services*.
- Choose *Next* and provide a name (e.g. `zdemo_abap_string`) and a description.
- Choose *Finish*.
- Find more information on CDS simple types [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_simple_types.htm).
The code of the CDS simple type may look as follows:
```abap
@EndUserText.label: 'String type'
define type zdemo_abap_string: abap.sstring( 1333 );
```
Commented code example:
```abap
"------ Internal table having a component of type string ------
"Creating and populating an internal table that includes a component that is
"typed with type string
TYPES: BEGIN OF s1,
comp1 TYPE i,
comp2 TYPE c LENGTH 3,
comp3 TYPE string,
END OF s1,
tab_type_1 TYPE TABLE OF s1 WITH EMPTY KEY.
DATA(itab1) = VALUE tab_type_1( ( comp1 = 1 comp2 = 'aaa' comp3 = `ABAP` ) ).
"Columns of type string cannot be used in SELECT statements that
"select from internal tables (* selects all fields). Therefore, the
"following statements are commented out.
"SELECT SINGLE * FROM @itab1 AS it WHERE comp1 = 1 INTO @DATA(res1).
"SELECT SINGLE comp1 FROM @itab1 AS it where comp3 = `ABAP` INTO @DATA(res2).
"SELECT SINGLE comp3 FROM @itab1 AS it where comp1 = 1 INTO @DATA(res3).
"However, the following statements work. No component of type string is involved.
SELECT SINGLE comp1 FROM @itab1 AS it WHERE comp2 = 'aaa' INTO @DATA(res4).
SELECT SINGLE comp1, comp2 FROM @itab1 AS it INTO @DATA(res5).
"--- Internal table having a component typed with a CDS simple type (sstring) ---
"Creating and populating an internal table that includes a component that is typed
"with a CDS simple type (sstring). Note: Built-in DDIC types such as sstring cannot
"directly be used in ABAP statements, except for typed literals.
TYPES: BEGIN OF s2,
comp1 TYPE i,
comp2 TYPE c LENGTH 3,
comp3 TYPE zdemo_abap_string,
END OF s2,
tab_type_2 TYPE TABLE OF s2 WITH EMPTY KEY.
DATA(itab2) = VALUE tab_type_2( ( comp1 = 1 comp2 = 'aaa' comp3 = `ABAP` ) ).
"Unlike above, the following SELECT statements are possible
SELECT SINGLE * FROM @itab2 AS it WHERE comp1 = 1 INTO @DATA(res6).
SELECT SINGLE comp1 FROM @itab2 AS it WHERE comp3 = `ABAP` INTO @DATA(res7).
SELECT SINGLE comp1, comp3 FROM @itab2 AS it WHERE comp2 = 'aaa' AND comp3 = `ABAP` INTO @DATA(res8).
"Note: `ABAP` represents a literal of type string. When specifying it here
"like it is specified above, there is an implicit conversion. The following
"example uses a typed literal.
SELECT SINGLE comp1, comp2, comp3 FROM @itab2 AS it WHERE comp3 = sstring`ABAP` INTO @DATA(res9).
```
<p align="right"><a href="#top">⬆️ back to top</a></p>
## Sorting Internal Tables
- Sorted tables are stored in the memory in an automatically sorted

View File

@@ -1996,8 +1996,30 @@ UPDATE dbtab FROM TABLE @itab.
UPDATE dbtab FROM TABLE @( VALUE #( ( comp1 = ... comp2 = ... )
( comp1 = ... comp2 = ... ) ) ).
"INDICATORS addition: Changing content of specific fields without overwriting
"existing values of other fields
"-------------------------- SET addition --------------------------
"Changing values of specific fields without overwriting other, non-specified
"fields
"Changing values of specific fields in all table rows
"There are mutliple options for the value assignment. E.g. you can use
"a literal, host variable/expression, SQL function, and so on.
"The following statement does not use a WHERE clause. Therefore,
"the comp2 values of all database table entries are changed.
UPDATE dbtab SET comp2 = 'X'.
"Changing values of specific fields in all found entries by restricting
"the data sets to be changed using a WHERE clause
"Use a comma-separated list for the components after SET
UPDATE dbtab SET comp2 = 'X', comp3 = 'Y' WHERE comp4 > 100.
"Changing values of specific fields in a single database table entry
"Assume the entry can be uniquely identified by specifying key values
"in the WHERE clause
UPDATE dbtab SET comp2 = 'X' WHERE key1 = 'Y'.
"--------------- INDICATORS ... SET STRUCTURE addition ---------------
"Similar to SET, using the INDICATORS ... addition, you can change content
"of specific fields without overwriting existing values of other fields by
"specifying set indicators.
"Example:
"- Structured type is created with WITH INDICATORS addition
"- Internal table from which to update dbtab is created;
@@ -2017,11 +2039,6 @@ UPDATE dbtab FROM TABLE @ind_tab INDICATORS SET STRUCTURE comp_ind.
"In the following example, the logic is reversed using NOT.
UPDATE dbtab FROM TABLE @ind_tab INDICATORS NOT SET STRUCTURE comp_ind.
"SET addition: Changing values of specific fields in all table rows
"There are mutliple options for the value assignment. E.g. you can use
"a literal, host variable/expression, SQL function, and so on.
UPDATE dbtab SET comp2 = ... .
```
<p align="right"><a href="#top">⬆️ back to top</a></p>

View File

@@ -278,8 +278,8 @@ The following concepts are related to the SAP LUW to ensure transactional consis
## The SAP LUW in ABAP Cloud and RAP
A limited set of ABAP language features is available in ABAP Cloud ([restricted ABAP language version](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenrestricted_version_glosry.htm)).
The limitations include the fact that the above bundling techniques are not available. Note that the local update is enabled by default in ABAP Cloud. Find more information in this [blog](https://blogs.sap.com/2022/12/05/the-sap-luw-in-abap-cloud/).
A limited set of ABAP language features is available in ABAP for Cloud Development ([restricted ABAP language version](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenrestricted_version_glosry.htm)).
The limitations include the fact that the above bundling techniques are not available. Note that the local update is enabled by default in ABAP Cloud.
In fact, RAP is the transactional programming model for ABAP Cloud.
And RAP comes with a well-defined transactional model and follows the rules of the SAP LUW. At the end of an SAP LUW in RAP, database modification operations should be performed in a final step in the [RAP late save phase](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenlate_rap_save_phase_glosry.htm) by persisting the consistent data in the [RAP transactional buffer](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentransactional_buffer_glosry.htm) to the database.
@@ -358,7 +358,6 @@ MODIFY zdemo_abap_carr FROM TABLE @( VALUE #(
## More Information
- [The RAP Transactional Model and the SAP LUW](https://help.sap.com/docs/SAP_S4HANA_CLOUD/e5522a8a7b174979913c99268bc03f1a/ccda1094b0f845e28b88f9f50a68dfc4.html) (Development guide for the ABAP RESTful Application Programming Model)
- [The SAP LUW in ABAP Cloud](https://blogs.sap.com/2022/12/05/the-sap-luw-in-abap-cloud/) (blog)
- [SAP LUW in the ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensap_luw.htm)
- [Controlled SAP LUW](https://help.sap.com/docs/abap-cloud/abap-concepts/controlled-sap-luw) as an enhancement of the SAP LUW concept

View File

@@ -734,7 +734,7 @@ After the import of the repository, proceed as follows:
> - Modifying static attributes (`LOOP AT SCREEN`, `MODIFY SCREEN`),
> - Statements related to the GUI status and title (`GET`/`SET PF-STATUS`, `SET TITLEBAR`)
> - Controls (table and tabstrip controls)
> - does not claim to include meaningful dynpros with meaningful dynpro sequences (branching to new dynpro sequences occur through using appropriate statements).
> - does not claim to include meaningful dynpros with meaningful dynpro sequences (the branching to new dynpro sequences occurs through using appropriate statements).
> - is not intended to be a role model for proper dynpro design.
> - is not intended to solve concrete programming tasks. You should always work out your own solution for each individual case.
> - is only intended to demonstrate a selection of keywords and visualize dynpro-related syntax in action on a high level.

View File

@@ -1059,7 +1059,7 @@ CLASS zcl_some_class IMPLEMENTATION.
"---------------- Deserializing: No equivalent ABAP type available ----------------
"The example assumes that there is no equivalent ABAP type available for JSON data
"that is to be deserialized. You can use of the 'generate' method that has a
"that is to be deserialized. You can use the 'generate' method that has a
"returning parameter of the generic type 'ref to data'.
DATA(json) = `[{"CARRIER_ID":"AA","CONNECTION_ID":17,"CITY_FROM":"New York","CITY_TO":"San Francisco"},` &&
`{"CARRIER_ID":"AZ","CONNECTION_ID":789,"CITY_FROM":"Tokyo","CITY_TO":"Rome"}]`.

View File

@@ -18,7 +18,7 @@
- [Dynamic Programming](#dynamic-programming)
- [Context Information](#context-information)
- [XML/JSON](#xmljson)
- [ABAP Repository Information](#abap-repository-information)
- [ABAP Repository Object Information](#abap-repository-object-information)
- [Call Stack](#call-stack)
- [Sending Emails](#sending-emails)
- [Tenant Information](#tenant-information)
@@ -1616,10 +1616,10 @@ xco_cp_json=>data->from_string( json_created_xco )->apply( VALUE #(
```abap
DATA(some_table) = VALUE string_table( ( `aaa` ) ( `bbb` ) ( `ddd` ) ).
"--------- ABAP -> Json ---------
"--------- ABAP -> JSON ---------
DATA(abap_to_json) = /ui2/cl_json=>serialize( data = some_table ).
"--------- Json -> ABAP ---------
"--------- JSON -> ABAP ---------
DATA table_json_to_abap TYPE string_table.
/ui2/cl_json=>deserialize( EXPORTING json = abap_to_json
CHANGING data = table_json_to_abap ).
@@ -1631,7 +1631,7 @@ DATA table_json_to_abap TYPE string_table.
<p align="right"><a href="#top">⬆️ back to top</a></p>
## ABAP Repository Information
## ABAP Repository Object Information
<table>
<tr>
@@ -2375,7 +2375,7 @@ CLASS zcl_some_class DEFINITION PUBLIC FINAL CREATE PUBLIC.
file_name TYPE string,
title TYPE string,
code_snippets TYPE string_table,
error TYPE abap_bool,
error TYPE abap_boolean,
END OF s.
DATA tab TYPE TABLE OF s WITH EMPTY KEY.
DATA snippets TYPE string_table.