This commit is contained in:
danrega
2024-01-10 17:02:33 +01:00
parent 01e87ce987
commit e4d3095824
8 changed files with 74 additions and 36 deletions

View File

@@ -11,6 +11,7 @@
- [Excursions with Internal Tables](#excursions-with-internal-tables)
- [Reading from Internal Tables](#reading-from-internal-tables)
- [Processing Multiple Internal Table Lines Sequentially](#processing-multiple-internal-table-lines-sequentially)
- [Iteration Expressions](#iteration-expressions)
- [Sorting Internal Tables](#sorting-internal-tables)
- [Modifying Internal Table Content](#modifying-internal-table-content)
- [Deleting Internal Table Content](#deleting-internal-table-content)
@@ -1218,25 +1219,15 @@ LOOP AT it INTO wa FROM 6 TO 3 STEP -2.
ENDLOOP.
```
*Iterations with* `FOR`
### Iteration Expressions
Iteration expressions with [`FOR`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfor.htm) as part of certain constructor expressions allow you to create content of an internal table by evaluating one or more source tables.
The following examples show iterations with `FOR` within a constructor expression with `VALUE`. A new table is created and
values for two fields are inserted into the new table, which has the internal table type of the source table. `ls` represents an iteration
variable that holds the data as the table is looped over. The components, and thus the table line to be returned, are
specified within the pair of parentheses before the closing parenthesis. Both examples set specific values for the components. The second example also includes a `WHERE` clause to restrict the lines to be copied.
The expressions are covered in the cheat sheet [Constructor Expressions](05_Constructor_Expressions.md):
- [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)
Unlike `LOOP` statements, this sequential processing cannot be debugged.
``` abap
"Internal table type
TYPES ttype like it.
DATA(tab1) = VALUE ttype( FOR ls IN it ( a = ls-a b = 9 ) ).
DATA(tab2) = VALUE ttype( FOR ls IN it WHERE ( a < 7 )
( a = ls-a b = ls-b + 5 ) ).
```
<p align="right"><a href="#top">⬆️ back to top</a></p>

View File

@@ -454,7 +454,7 @@ DATA dref4 TYPE REF TO string_table.
dref4 = NEW #( VALUE string_table( ( `a` ) ( `b` ) ) ).
"Structured type; named arguments within the parentheses
DATA(dref5) = NEW scarr( carrid = 'AA' carrname = 'American Airlines' ).
DATA(dref5) = NEW zdemo_abap_carr( carrid = 'AA' carrname = 'American Airlines' ).
"Object references
"Declaring object reference variables

View File

@@ -295,6 +295,7 @@ ASSIGN s-tab_std TO <data>.
ASSIGN s-xstr TO <any>.
ASSIGN s-pl4d2 TO <any>.
ASSIGN s-date TO <any>.
ASSIGN s TO <any>.
"----- Character-like types -----
ASSIGN s-c3 TO <c>.
@@ -370,9 +371,6 @@ ASSIGN s-xl1 TO <simple>.
ASSIGN s-oref TO <object>.
s-oref = NEW zcl_demo_abap_objects( ).
ASSIGN s-oref TO <object>.
s-oref = cl_abap_random_int=>create( ).
ASSIGN s-oref TO <object>.
```
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -1560,6 +1558,8 @@ CALL METHOD (class)=>meth.
"Class and method dynamically specified
CALL METHOD (class)=>(meth).
"The following examples assume that there are parameters defined
"for the method.
"Assigning actual parameters to the formal parameters statically
CALL METHOD class=>(meth) EXPORTING p1 = a1 p2 = a2 ...
IMPORTING p1 = a1 p2 = a2 ...

View File

@@ -25,6 +25,9 @@
- [Searching Using Regular Expressions](#searching-using-regular-expressions)
- [Excursion: System Classes for Regular Expressions](#excursion-system-classes-for-regular-expressions)
- [Replacing Using Regular Expressions](#replacing-using-regular-expressions)
- [More String Functions](#more-string-functions)
- [Checking the Similarity of Strings](#checking-the-similarity-of-strings)
- [Repeating Strings](#repeating-strings)
- [Executable Example](#executable-example)
@@ -1664,7 +1667,6 @@ FIND FIRST OCCURRENCE OF PCRE `\bt.` IN TABLE itab
##### Excursion: System Classes for Regular Expressions
- You can create an object-oriented representation of regular expressions using the `CL_ABAP_REGEX` system class.
- For example, the `CREATE_PCRE` method creates instances of regular expressions with PCRE syntax.
- The instances can be used, for example, with the `CL_ABAP_MATCHER` class, which applies the regular expressions.
@@ -1747,6 +1749,48 @@ REPLACE PCRE `(.*?)PP(.*)` IN s1 WITH `$2#$1` IGNORING CASE. "pc app#ab a
<p align="right"><a href="#top">⬆️ back to top</a></p>
## More String Functions
### Checking the Similarity of Strings
- [`distance`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendistance_functions.htm) returns the Levenshtein distance between two strings, which reflects their similarity.
- Unlike other string functions, the return value has the type `i`.
- Optional addition `max`: Positive integer. The calculation of the Levenshtein distance will stop if the calculated value is greater than this integer.
```abap
DATA(str_to_check) = `abap`.
DATA(dist1) = distance( val1 = str_to_check val2 = `abap` ). "0
DATA(dist2) = distance( val1 = str_to_check val2 = `axbap` ). "1
DATA(dist3) = distance( val1 = str_to_check val2 = `yabyyapy` ). "4
DATA(dist4) = distance( val1 = str_to_check val2 = `zabapzzzzzzzzzzzz` max = 5 ). "5
"If the value of max is 0 or less, an exception is raised.
TRY.
DATA(dist5) = distance( val1 = str_to_check val2 = `zabapzzzzzzzzzzzz` max = 0 ).
CATCH cx_sy_strg_par_val.
...
ENDTRY.
```
### Repeating Strings
- [`repeat`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrepeat_functions.htm) returns a string that contains the content of a specified string for parameter `val` as many times as specified in the parameter `occ`.
- An empty string is returned when `occ` has the value 0 or `val` is empty.
```abap
DATA(repeat1) = repeat( val = `abap` occ = 5 ). "abapabapabapabapabap
DATA(repeat2) = |#{ repeat( val = ` ` occ = 10 ) }#|. "# #
DATA(repeat3) = COND #( WHEN repeat( val = `a` occ = 0 ) = `` THEN `Y` ELSE `Z` ). "Y (initial value returned)
"If occ has a negative value, an exception is raised.
TRY.
DATA(repeat4) = repeat( val = `X` occ = -3 ).
CATCH cx_sy_strg_par_val.
...
ENDTRY.
```
<p align="right"><a href="#top">⬆️ back to top</a></p>
## Executable Example
[zcl_demo_abap_string_proc](./src/zcl_demo_abap_string_proc.clas.abap)

View File

@@ -95,8 +95,7 @@ The following points cover RAP-related terms such as *RAP business objects* and
- This data includes [RAP BO
instances](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_bo_instance_glosry.htm "Glossary Entry")
(i. e. concrete data sets of an entity). This is where EML
enters the picture: EML is used to access this data in the
transactional buffer.
enters the picture: EML is used, among others, to access this data in the transactional buffer.
- Currently, there are two kinds of RAP BOs:
[managed](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenmanaged_rap_bo_glosry.htm "Glossary Entry")
and [unmanaged RAP
@@ -201,7 +200,7 @@ focus on).
- As mentioned in the RAP terms and as the name implies, a RAP behavior definition describes a RAP business object (RAP BO) by defining its behavior for all of its RAP BO entities.
- BDL source code is used in a BDEF.
- Once you have created ...
- the CDS root view entity of a RAP BO, ADT helps you create the skeleton of a BDEF (e.g., right-click on the CDS root view entity and choose *New Behavior Definition* from the pop-up).
- the CDS root entity of a RAP BO, ADT helps you create the skeleton of a BDEF (e.g., right-click on the CDS root entity and choose *New Behavior Definition* from the pop-up).
- the BDEF, ADT helps you create the skeleton of an ABAP behavior pool, as well as RAP handler and saver method declarations and the skeleton of implementations via ADT quick fixes.
- More information (see also the subtopics there):
- [Structure of a RAP behavior definition](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_bdef.htm)
@@ -211,10 +210,11 @@ focus on).
The following example shows a commented BDEF.
Note that there is a wide variety of possible specifications and options. The example shows only a selection. For full details, refer to the ABAP Keyword Documentation.
Some of the syntax examples are commented out, just for the sake of showing more syntax options.
```js
//Possible implementation types: managed, unmanaged, abstract, projection, interface
//(with restrict/enable further specifications)
//(which restrict/enable further specifications)
//You can specifiy one or more implementation classes (behavior pools/ABPs -> bp...)
//for the RAP BO (in some contexts, specifying no ABP is possible).
//Specifying unique is mandatory (each operation can only implemented once).
@@ -287,6 +287,8 @@ authorization master ( instance )
//As is true for various specifications, a comma-separated list of specifications is possible.
delete( precheck );
//Note: It is not possible to specify operations multiple times. The following specifications
//just demonstrate syntax options. Anyway, the compiler helps you not to specify wrong notations.
//Applying feature control
//delete( features: global );
@@ -374,7 +376,8 @@ authorization master ( instance )
//Read-only during update (especially key fields created during create operations)
field ( readonly : update ) key_field;
//It is mandatory to specify values for the fields before persisting them to the database
//The mandatory specification denotes that values must be provided for the fields before persisting
//them to the database.
//Comma-separated list possible for the field characteristics in general;
//mutliple characteristics can also be specified in a comma-separated list in the parentheses
field ( mandatory ) field2, field3;
@@ -386,16 +389,16 @@ authorization master ( instance )
//Checking the consitency of instances; validations are triggered based on conditions
//Conditions (one or more are possible) can be specified for create, update, delete operations
//and modified fields; note: not available for unmanaged, non-draft RAP BOs.
validation val1 on save { create; field field1; }
validation val on save { create; field field1; }
//Determinations
//Modifying instances based on trigger conditions;
//As above, conditions (one or more are possible) can be specified for create, update, delete
//operations and modified fields. The triggering is possible for 'on modify' and 'on save'.
determination det1 on modify { update; delete; field field1, field2; }
determination det2 on save { create; field field3, field4; }
determination det1 on modify { update; delete; field field5, field6; }
determination det2 on save { create; field field7, field8; }
//RAP business event (derived events with the specification 'managed evt ...' is also possible)
//RAP business event (derived events with the specification 'managed evt ...' are also possible)
event evt;
//RAP side effects, to trigger a reload of affected properties on the UI
@@ -819,9 +822,9 @@ Bullet points on selected `%` components:
draft scenario. In doing so, you can avoid lots of adaptations
in your code by manually adding the indicator.
- [`%control`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapderived_types_control.htm)
- Component group that, in certain contexts and for example (it depends on the context what it contains), contains the names of all key
- Component group that contains the names of all key
and data fields of a RAP BO instance which indicate flags.
- The use depends on the context. For example, it is used to get information on which fields are provided or set a
- For example, it is used to get information on which fields are provided or set a
flag for which fields are requested by RAP BO providers or RAP
BO consumers respectively during the current EML request.
- For this purpose, the value of each field in the

View File

@@ -386,6 +386,7 @@ ASSIGN s-tab_std TO <data>.
ASSIGN s-xstr TO <any>.
ASSIGN s-pl4d2 TO <any>.
ASSIGN s-date TO <any>.
ASSIGN s TO <any>.
"----- Character-like types -----
ASSIGN s-c3 TO <c>.
@@ -461,9 +462,6 @@ ASSIGN s-xl1 TO <simple>.
ASSIGN s-oref TO <object>.
s-oref = NEW zcl_demo_abap_objects( ).
ASSIGN s-oref TO <object>.
s-oref = cl_abap_random_int=>create( ).
ASSIGN s-oref TO <object>.
```
<p align="right"><a href="#top">⬆️ back to top</a></p>

View File

@@ -502,12 +502,13 @@ SET SCREEN 0.
## Modifying Static Attributes of Screen Elements
- For each screen element, you can define various static attributes that control, for example, its appearance or status.
- For each screen element, you can define various static attributes that control, for example, its appearance (i.e. you can hide screen elements) or status.
- The static attributes of the screen elements can be overwritten from within the ABAP program during the PBO processing of the dynpro.
- To do this, use the ABAP statements [`LOOP AT SCREEN`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abaploop_at_screen.htm) and [`MODIFY SCREEN`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapmodify_screen.htm).
- `LOOP AT SCREEN`:
- Defines a loop over all screen elements of the current dynpro to which a dynpro field is assigned.
- A work area of type `SCREEN` should be declared.
- Note: Check the ABAP Keyword Documentation for the different components. You can also check the F2 information for the work area in the `LOOP` statement below.
- After the `LOOP AT SCREEN` statement, the work area contains the properties of the corresponding screen element.
- `MODIFY SCREEN`:
- Can only be used in the statement block after `LOOP AT SCREEN` and only makes sense during PBO processing.

View File

@@ -29,7 +29,7 @@ ABAP cheat sheets[^1] ...
- provide a **collection of information on selected ABAP topics** in a nutshell for your reference.
- focus on **ABAP syntax**.
- include **code snippets**.
- are supported by easy-to-consume **demonstration examples** that you can import into your [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) or on-premise ABAP system ([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*) using [abapGit](https://abapgit.org/) to run and check out ABAP syntax in action in simple contexts.
- are supported by easy-to-consume **demonstration examples** that you can import into your [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 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)) or on-premise ABAP system ([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*) using [abapGit](https://abapgit.org/) to run and check out ABAP syntax in action in simple contexts.
- 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.
<details>
@@ -44,6 +44,7 @@ ABAP cheat sheets[^1] ...
- The cheat sheets provide links to glossary entries and topics in the ABAP Keyword Documentation. Note that unlike the classic ABAP-only cheat sheets, in most cases these links refer to ABAP for Cloud Development.
- [Here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrestricted_abap_elements.htm) is an overview of the different ABAP language elements in the different ABAP versions, i.e. what is allowed in ABAP Cloud and what is not. See also the released APIs [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreleased_apis.htm).
- In order to have all ABAP cheat sheet documents in one place, the *main* branch (for ABAP Cloud examples) also contains the ABAP cheat sheet documents that are only relevant for classic ABAP.
- The example classes contained in the branches for classic ABAP mostly use syntax that is also available in ABAP for Cloud Development. Only the `TEST_ABAP_CHEAT_SHEETS_CLASSIC` subpackage contains syntax relevant to Standard ABAP and that is not available in ABAP for Cloud Development, such as dynpro-related ABAP keywords.
</details>
<br>
@@ -230,7 +231,7 @@ There is no guarantee for either the correctness or the completeness of the code
<br>
## 📟 Support
This is not intended to be a contribution repository, so please do not create pull requests. If you like to address issues or suggestions, please create an issue. However, this project is provided "as-is": there is no guarantee that raised issues will be answered or addressed in future releases.
This is not intended to be a contribution repository, so please do not create pull requests. If you like to address issues or suggestions regarding additional syntax to be covered, please create an issue. However, this project is provided "as-is": there is no guarantee that raised issues will be answered or addressed in future releases.
<br>