Update content
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
|
||||
- The name `itab` of the data object is determined at compile time and remains stable throughout the execution of the program.
|
||||
- However, there can also be use cases where the attributes of such a data object are not statically determined. This is where dynamic aspects enter the picture: Attributes, names, types etc. are not determined at compile time but rather at runtime.
|
||||
- There are ABAP statements that include these dynamic aspects in the syntax. Assume you have simple program and a UI that includes an input field storing the input in a data object named `dbtab`. As input, you expect the name of a database table to be provided. In the end, you want to retrieve all entries of the database table and store them in an internal table. This table should be displayed. So, there is random input at runtime and your program must be able to deal with it.
|
||||
- There are ABAP statements that include these dynamic aspects in the syntax. Assume you have a simple program and a UI that includes an input field storing the input in a data object named `dbtab`. As input, you expect the name of a database table to be provided. In the end, you want to retrieve all entries of the database table and store them in an internal table. This table should be displayed. So, there is random input at runtime and your program must be able to deal with it.
|
||||
- See the following `SELECT` statement. As also shown further down, the `FROM` clause does not include a statically defined table to be selected from. Instead, there is a pair of parentheses including a data object. Assume the data object holds the name of the database table. At runtime, the data retrieval happens from the database table that was inserted in the input field.
|
||||
|
||||
```abap
|
||||
@@ -106,12 +106,12 @@ Once the memory area is assigned, you can work with the content.
|
||||
``` abap
|
||||
"Some data object declarations to be used
|
||||
DATA: number TYPE i,
|
||||
struc TYPE sflight,
|
||||
struc TYPE zdemo_abap_fli, "Demo database table
|
||||
tab TYPE string_table.
|
||||
|
||||
"Declaring field symbols with complete types
|
||||
FIELD-SYMBOLS: <fs_i> TYPE i,
|
||||
<fs_struc> TYPE sflight,
|
||||
<fs_struc> TYPE zdemo_abap_fli,
|
||||
<fs_tab> TYPE string_table.
|
||||
|
||||
"Declaring field symbols with generic type
|
||||
@@ -168,7 +168,7 @@ ASSIGN chars TO <fs2> CASTING TYPE c_len_3.
|
||||
|
||||
``` abap
|
||||
"For example, in assignments
|
||||
DATA: number TYPE i VALUE 1.
|
||||
DATA number TYPE i VALUE 1.
|
||||
FIELD-SYMBOLS <fs_i> TYPE i.
|
||||
ASSIGN number TO <fs_i>.
|
||||
|
||||
@@ -321,7 +321,7 @@ Excursion: Static vs. dynamic type, upcasts and downcasts
|
||||
- For an assignment to work, the differentiation is particularly relevant since the following basic rule applies: The static type of the target reference variable must be more general than or the same as the dynamic type of the source reference variable.
|
||||
|
||||
- This is where the concepts of [upcast](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenup_cast_glosry.htm "Glossary Entry") and [downcast](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendown_cast_glosry.htm "Glossary Entry") enter the picture.
|
||||
- Up and and down? It originates from the idea of moving up or down in an [inheritance tree](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninheritance_tree_glosry.htm). In an assignment between reference variables, the target variable inherits the dynamic type of the source variable.
|
||||
- Up and down? This concept originates from the idea of moving up or down in an [inheritance tree](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninheritance_tree_glosry.htm). In an assignment between reference variables, the target variable inherits the dynamic type of the source variable.
|
||||
- Upcast: If the static type of the target variables is **less specific or the same** as the static type of the source variable, an assignment is possible. This includes, for example, assignments with the [assignment operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenassignment_operator_glosry.htm) `=`.
|
||||
- Downcast: If the static type of the target variable is **more specific** than the static type of the source variable, a check must be made at runtime before the assignment is done. If you indeed want to trigger such a downcast, you must do it explicitly in your code. You can do this, for example, using the
|
||||
[constructor operator](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_operator_glosry.htm "Glossary Entry")
|
||||
|
||||
@@ -341,9 +341,9 @@ the string function
|
||||
Syntax examples:
|
||||
``` abap
|
||||
"&& and string template
|
||||
s1 = `AB` && `AP`. "ABAP
|
||||
s2 = `ab` && `ap` && ` ` && s1. "abap ABAP
|
||||
s3 = |{ s1 }. { s2 }!|. "ABAP. abap ABAP!
|
||||
DATA(s1) = `AB` && `AP`. "ABAP
|
||||
DATA(s2) = `ab` && `ap` && ` ` && s1. "abap ABAP
|
||||
DATA(s3) = |{ s1 }. { s2 }!|. "ABAP. abap ABAP!
|
||||
|
||||
"CONCATENATE statements
|
||||
CONCATENATE s1 s2 INTO s3. "ABAPabap ABAP
|
||||
@@ -392,7 +392,10 @@ string function
|
||||
|
||||
Syntax examples:
|
||||
``` abap
|
||||
s1 = `Hallo,world,123`.
|
||||
DATA(s1) = `Hallo,world,123`.
|
||||
DATA: s2 TYPE string,
|
||||
s3 TYPE string,
|
||||
s4 TYPE string.
|
||||
|
||||
SPLIT s1 AT `,` INTO s2 s3 s4. "s2 = Hallo / s3 = world / s4 = 123
|
||||
|
||||
@@ -426,7 +429,7 @@ statements.
|
||||
Syntax examples:
|
||||
``` abap
|
||||
"String functions
|
||||
s1 = to_upper( `abap` ). "ABAP
|
||||
DATA(s1) = to_upper( `abap` ). "ABAP
|
||||
s1 = to_lower( `SOME_FILE.Txt` ). "some_file.txt
|
||||
|
||||
"TRANSLATE statements
|
||||
@@ -455,7 +458,7 @@ Syntax examples:
|
||||
``` abap
|
||||
"SHIFT statements
|
||||
"Note that all results below refer to s1 = `hallo`.
|
||||
s1 = `hallo`. "Type string
|
||||
DATA(s1) = `hallo`. "Type string
|
||||
|
||||
SHIFT s1. "No addition; string shifted one place to the left: allo
|
||||
SHIFT s1 BY 2 PLACES. "Without direction, left by default: llo
|
||||
@@ -472,15 +475,15 @@ SHIFT ch4 BY 3 PLACES LEFT CIRCULAR. "lohal
|
||||
SHIFT ch4 UP TO `ll`. "Shift characters up to a specific character set: llo
|
||||
|
||||
"Deleting leading and trailing characters
|
||||
s2 = ` hallo `.
|
||||
s3 = s2.
|
||||
DATA(s2) = ` hallo `.
|
||||
DATA(s3) = s2.
|
||||
|
||||
SHIFT s2 LEFT DELETING LEADING ` `. "'hallo '
|
||||
SHIFT s3 RIGHT DELETING TRAILING ` `. "' hallo' (length is kept)
|
||||
|
||||
"Removing trailing blanks in strings without leading blanks;
|
||||
"you can use the following sequence of statements
|
||||
s4 = `hallo `.
|
||||
DATA(s4) = `hallo `.
|
||||
SHIFT s4 RIGHT DELETING TRAILING ` `. "' hallo'
|
||||
SHIFT s4 LEFT DELETING LEADING ` `. "'hallo'
|
||||
|
||||
@@ -509,9 +512,9 @@ is that you can specify any character to remove, not just blanks.
|
||||
Syntax examples:
|
||||
``` abap
|
||||
"CONDENSE statements
|
||||
s1 = ` ab cd `.
|
||||
s2 = ` ef gh ij `.
|
||||
s3 = ` kl mn op `.
|
||||
DATA(s1) = ` ab cd `.
|
||||
DATA(s2) = ` ef gh ij `.
|
||||
DATA(s3) = ` kl mn op `.
|
||||
|
||||
CONDENSE s1. "Trailing and leading blanks are removed: 'ab cd'
|
||||
CONDENSE s2. "It also replaces sequences of multiple blanks with a single blank: 'ef gh ij'
|
||||
@@ -553,7 +556,7 @@ The string function
|
||||
reverses a string:
|
||||
``` abap
|
||||
"Result: 'abap'
|
||||
s1 = reverse( `paba` ).
|
||||
DATA(s1) = reverse( `paba` ).
|
||||
```
|
||||
|
||||
**Inserting Substrings into Strings**
|
||||
@@ -569,7 +572,7 @@ inserts a substring at any position within a given string. You can use various p
|
||||
Syntax examples:
|
||||
``` abap
|
||||
"Result: 'abcdefghi'
|
||||
s1 = insert( val = `abcghi` sub = `def` off = 3 ).
|
||||
DATA(s1) = insert( val = `abcghi` sub = `def` off = 3 ).
|
||||
|
||||
"Result: 'defabcghi'
|
||||
s1 = insert( val = `abcghi` sub = `def` ).
|
||||
@@ -588,7 +591,6 @@ DATA(cl_name) = 'CL_SOME_CLASS '.
|
||||
OVERLAY cl_name WITH incl.
|
||||
"cl_name: CL_SOME_CLASS=================CP
|
||||
|
||||
|
||||
DATA(txt1) = 'a.b.c.a.b.c.A'.
|
||||
DATA(txt2) = 'z.x.y.Z.x.y.z'.
|
||||
|
||||
@@ -634,12 +636,12 @@ which are covered below.
|
||||
|
||||
Syntax examples:
|
||||
``` abap
|
||||
s1 = `Lorem ipsum dolor sit amet`. "Type string
|
||||
DATA(s1) = `Lorem ipsum dolor sit amet`. "Type string
|
||||
|
||||
"Extracting substring starting at a specific position
|
||||
"'len' not specified means the rest of the remaining characters are
|
||||
"respected
|
||||
s2 = substring( val = s1 off = 6 ). "ipsum dolor sit amet
|
||||
DATA(s2) = substring( val = s1 off = 6 ). "ipsum dolor sit amet
|
||||
|
||||
"Extracting substring with a specific length
|
||||
"'off' is not specified and has the default value 0.
|
||||
@@ -754,7 +756,7 @@ expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.ht
|
||||
|
||||
Syntax examples:
|
||||
``` abap
|
||||
s1 = `cheers`.
|
||||
DATA(s1) = `cheers`.
|
||||
IF s1 CA `aeiou` ... "true, sy-fdpos = 2
|
||||
IF s1 NA `xyz`... "true, sy-fdpos = 6
|
||||
|
||||
@@ -819,9 +821,9 @@ statements to perform replacements directly on the source field.
|
||||
|
||||
Syntax examples:
|
||||
``` abap
|
||||
s1 = `___abc_def_____ghi_`.
|
||||
s2 = translate( val = s1 from = `hi_` to = `##` ). "abcdefg##
|
||||
s2 = translate( val = s1 from = `_` to = `##` ). "###abc#def#####ghi#
|
||||
DATA(s1) = `___abc_def_____ghi_`.
|
||||
DATA(s2) = translate( val = s1 from = `hi_` to = `##` ). "abcdefg##
|
||||
s2 = translate( val = s1 from = `_` to = `##` ). "###abc#def#####ghi#
|
||||
|
||||
"TRANSLATE statement. The value after USING is interpreted as a string composed of character pairs.
|
||||
"Starting with the first pair, a search is performed in text for the
|
||||
@@ -848,7 +850,7 @@ TRANSLATE s1 USING `_.a#g+`. "...#bc.def.....+hi.
|
||||
of the searched string.
|
||||
|
||||
``` abap
|
||||
s3 = `cheers`.
|
||||
DATA(s3) = `cheers`.
|
||||
|
||||
IF s3 CS `rs` ... "true, sy-fdpos = 4 (offset)
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ METHODS some_action FOR MODIFY
|
||||
of RAP BO instances as import parameter. Therefore, instance data
|
||||
must be handled via the transactional buffer when self-implementing
|
||||
the saver methods.
|
||||
- Saver methods are called when the RAP save sequence has been triggered a [`COMMIT
|
||||
- Saver methods are called when the RAP save sequence has been triggered by a [`COMMIT
|
||||
ENTITIES`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcommit_entities.htm)
|
||||
statement. Note that in natively supported RAP scenarios, for example, an SAP Fiori app using OData, the `COMMIT ENTITIES` call is performed implicitly and automatically by the [RAP runtime engine](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_runtime_engine_glosry.htm).
|
||||
- Find more information on RAP saver methods
|
||||
@@ -546,7 +546,7 @@ in [late
|
||||
numbering](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_late_numbering_glosry.htm "Glossary Entry")
|
||||
scenarios. The draft indicator
|
||||
[`%is_draft`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapderived_types_is_draft.htm)
|
||||
is only reelvant in the context of
|
||||
is only relevant in the context of
|
||||
[draft](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbdl_with_draft.htm).
|
||||
|
||||
Find more details on the available components in section [Components of
|
||||
@@ -642,7 +642,7 @@ DATA: cr_tab TYPE TABLE FOR CREATE root_ent, "input derived type
|
||||
"Input derived type for the EML statement is filled using the VALUE operator
|
||||
"Assumption: key_field is the key field having type i,
|
||||
"field1 and field2 are data fields with character-like data type.
|
||||
"Specify %cid even if not used or of interest; it must be unique within a RAP LUW
|
||||
"Specify %cid even if not used or of interest; it must be unique within a request
|
||||
|
||||
cr_tab = VALUE #(
|
||||
( %cid = 'cid1' key_field = 1
|
||||
|
||||
@@ -159,7 +159,7 @@ Use the standalone version of the abapGit report to import the demo examples of
|
||||
8. Choose the `Pull` button. The import of the artifacts is triggered. This may take several minutes.
|
||||
9. If the `Inactive Objects` popup is displayed, select all artifacts and choose `Continue` (✔️).
|
||||
10. When the cloning is complete, refresh your project tree. For example, in ADT, right-click on the package and choose `Refresh` or `F5`. The package should contain all artifacts from the GitHub repository.
|
||||
11. Make sure that all artifacts are active. To activate all inactive development objects, choose the `Activate all inactive ABAP development objects` button from the (or choose `CTRL+Shift+F3`).
|
||||
11. Make sure that all artifacts are active. To activate all inactive development objects, choose the `Activate all inactive ABAP development objects` button from the menu (or choose `CTRL+Shift+F3`).
|
||||
|
||||
</details>
|
||||
|
||||
@@ -174,7 +174,7 @@ Use the standalone version of the abapGit report to import the demo examples of
|
||||
|
||||
> **💡 Note**<br>
|
||||
>- Check the notes on the context and the ABAP syntax used that are included as comments in the class.
|
||||
>- Due to the amount of output in the console, the examples include numbers (e.g. 1) ..., 2) ..., 3) ...) that represent the header of each example code section. Also, in most cases, the variable name is displayed in the console. Therefore, to find the relevant output in the console more easily and quickly, simply search the console for the number (e.g. search for `3)` for the particular output) or variable name (`CTRL+F` in the console), or use breakpoints in the code to check variables in the debugger.
|
||||
>- Due to the amount of output in the console, the examples include numbers (e.g. 1) ..., 2) ..., 3) ...) that represent the headers of each example code section. Also, in most cases, the variable name is displayed in the console. Therefore, to find the relevant output in the console more easily and quickly, simply search the console for the number (e.g. search for `3)` for the particular output) or variable name (`CTRL+F` in the console), or use breakpoints in the code to check variables in the debugger.
|
||||
>- You may want to clear the console by right-clicking in the console and choosing `Clear` before running another demo class to avoid confusing the output of multiple classes.
|
||||
</details>
|
||||
|
||||
@@ -182,7 +182,7 @@ Use the standalone version of the abapGit report to import the demo examples of
|
||||
|
||||
## ⚡ Known Issues
|
||||
- Only one user on the system can import this repository because all object names must be globally unique. If you get an error that the objects already exist when you try to import, search the system for classes named `ZCL_DEMO_ABAP*`. Someone has already imported the content into the system and you can simply check out that imported version.
|
||||
- Since the repository contains self-contained examples, i.e. they work with demo database tables included in the repository (note that these tables are populated during method executions), all demo artifacts must be imported for all examples to work.
|
||||
- Since the repository contains self-contained examples, i.e. some of them work with demo database tables included in the repository (note that these tables are populated during method executions), all demo artifacts must be imported for all examples to work.
|
||||
- When importing into an on-premise system, note the following: The demos cover ABAP syntax regardless of the ABAP release to avoid scattering information and to get the information in one go. Therefore, there may be syntax that is not yet available in the ABAP version of your on-premise system. In this case, you may want to comment out the affected code sections and/or ignore the affected artifacts if an activation fails. Note that the RAP examples in particular require at least ABAP version 7.56.
|
||||
- Regarding possible code check warnings, e.g. for the many strings in the code, not using an `ORDER BY` clause, or messages regarding using `SELECT *`, the code deliberately avoids pragmas and pseudo comments in order to keep the code simple and to focus on the available ABAP syntax. See also the [Disclaimer](#%EF%B8%8F-disclaimer).
|
||||
|
||||
@@ -204,7 +204,7 @@ The code examples presented in this repository are only syntax examples and are
|
||||
SAP does not guarantee either the correctness or the completeness of the code. In addition, SAP takes no legal responsibility or liability for possible errors or their consequences, which occur through the use of the example programs.
|
||||
|
||||
## 📟 How to Obtain Support
|
||||
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, 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.
|
||||
|
||||
## 📜 License
|
||||
Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSE) file.
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
"In this example, multiple test classes are created in the test include.
|
||||
"Because private attributes are not accessible in local test classes,
|
||||
"the local test classes are declared as local friends of the global class.
|
||||
"in the example, a combined friendship declaration for all test classes is placed
|
||||
"In the example, a combined friendship declaration for all test classes is placed
|
||||
"at the top of the test include. Prepending the friendship declaration with
|
||||
"test class definitions and the DEFERRED addition makes the the test classes
|
||||
"'known' at this stage and can thus be specified as local friends there.
|
||||
|
||||
Reference in New Issue
Block a user