Update content
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
# Internal Tables
|
||||
|
||||
- [Internal Tables](#internal-tables)
|
||||
- [Internal Tables ...](#internal-tables-)
|
||||
- [Introduction](#introduction)
|
||||
- [Basic Properties of Internal Tables](#basic-properties-of-internal-tables)
|
||||
- [Excursion: Table Keys in Internal Tables (Primary, Secondary, Standard, Empty)](#excursion-table-keys-in-internal-tables-primary-secondary-standard-empty)
|
||||
- [Creating Internal Tables and Types](#creating-internal-tables-and-types)
|
||||
@@ -18,7 +18,9 @@
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
|
||||
## Internal Tables ...
|
||||
## Introduction
|
||||
|
||||
Internal Tables ...
|
||||
|
||||
- are [dynamic data objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendynamic_data_object_glosry.htm), i.e. all properties except the [ABAP memory](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_memory_glosry.htm) consumption are determined statically by the [data type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_type_glosry.htm).
|
||||
- consist of a variable sequence of lines of the same data type.
|
||||
@@ -56,7 +58,7 @@
|
||||
| Category | Internally managed by | Access | Primary table key | When to use | Hints |
|
||||
|---|---|---|---|---|---|
|
||||
|`STANDARD`|Primary table index (that's why these tables are called [index tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenindex_table_glosry.htm))|<ul><li>Table index</li><li>Table key</li></ul>|<ul><li>Always non-unique, i.e. duplicate entries are always allowed</li><li>Definition of an empty key is possible if the key is not relevant(`WITH EMPTY KEY`)</li></ul>|<ul><li>If you primarily access the table content for sequential processing or via the table index.</li><li>Response time for accessing the table using the primary key: This kind of table access is optimized only for sorted and hashed tables. For standard tables, primary key access uses a linear search across all lines. That means that large standard tables (more than 100 lines) are not ideal if the you primarily access the table using the table key.</></ul>|<ul><li>There is no particular sort order, but the tables can be sorted using `SORT`.</li><li>Filling this kind of table: Lines are either appended at the end of the table or inserted at a specific position.</li><li>[Secondary table keys](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensecondary_table_key_glosry.htm) can be defined to make key access to standard tables more efficient.</li><li>Standard and sorted tables have the least [administration costs (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenadmin_costs_dyn_mem_obj_guidl.htm).</li></ul>|
|
||||
|`SORTED`|Primary table index (that's why these tables are called [index tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenindex_table_glosry.htm))|<ul><li>Table index</li><li>Table key</li></ul>|<ul><li>Non-unique</li><li>Unique</li><br>... used to sort the table in ascending order.</ul>|<ul><li>Enables an optimized access to table content using table key and index.</li><li>If access via table key is the main access method, but no unqiue key can be defined.</li></ul>|<ul><li>Sorting is done automatically when lines are inserted or deleted. As a consequnce, the table index must usually be reorganized. </li><li>The response time for accessing the table using the primary key depends logarithmically on the number of table entries, since a binary search is used.</li><li>Standard and sorted tables have the least administration costs.</li></ul>|
|
||||
|`SORTED`|Primary table index (that's why these tables are called [index tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenindex_table_glosry.htm))|<ul><li>Table index</li><li>Table key</li></ul>|<ul><li>Non-unique</li><li>Unique</li><br>... used to sort the table in ascending order.</ul>|<ul><li>Enables an optimized access to table content using table key and index.</li><li>If access via table key is the main access method, but no unique key can be defined.</li></ul>|<ul><li>Sorting is done automatically when lines are inserted or deleted. As a consequnce, the table index must usually be reorganized. </li><li>The response time for accessing the table using the primary key depends logarithmically on the number of table entries, since a binary search is used.</li><li>Standard and sorted tables have the least administration costs.</li></ul>|
|
||||
|`HASHED`|Hash algorithm |<ul><li>Table key</li><li>[Secondary table index](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensecondary_table_index_glosry.htm)</li></ul>|Always unique|<ul><li>For large internal tables.</li><li>Optimized for key access. Access to table content via table key is the main access method and a unique key can be defined.</li></ul>|<ul><li>The response time for primary key access is constant and independent of the number of entries in the table.</li><li>Hashed tables have the highest administration costs.</li></ul>|
|
||||
|
||||
|
||||
@@ -115,7 +117,7 @@
|
||||
- Sorting of a table can produce unexpected results.
|
||||
- Since the standard key can consist of many fields, it affects the performance when accessing the internal table via the keys.
|
||||
- The key fields of the primary table key of sorted and hashed tables are always read-only, i.e. using the standard key with these table categories and then (unintentionally) modifying fields can cause unexpected runtime errors.
|
||||
- Explicit specifying keys has the advantage of making your code more readable, and of preventing the standard key from being set by mistake.
|
||||
- Specifying keys explicitly has the advantage of making the code more readable and preventing the standard key from being set by mistake.
|
||||
|
||||
**Empty key**
|
||||
- The primary table key of a standard table can be empty, i.e. it does not contain any key fields.
|
||||
@@ -141,8 +143,8 @@
|
||||
- Use cases:
|
||||
- To improve read performance.
|
||||
- For very large internal tables (that are filled once and changed very often)
|
||||
- Standard tables, whose primary table keys cannot be unique, can be provided with a means of ensuring that unqiue table entries are read.
|
||||
- Note that defining secondary table keys involves additional administration costs (additional memory consumption). Therefore, the use of secondary table keys should be reserved for cases where the benefits outweigh the extra cost.
|
||||
- Standard tables, whose primary table keys cannot be unique, can be provided with a means of ensuring that unique table entries are read.
|
||||
- Note that defining secondary table keys involves additional administration costs (additional memory consumption). Therefore, the use of secondary table keys should be reserved for cases where the benefits outweigh the extra costs.
|
||||
- For more details, see the programming guidelines for secondary keys: [Secondary
|
||||
Key (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensecondary_key_guidl.htm "Guideline").
|
||||
|
||||
@@ -156,7 +158,7 @@
|
||||
|
||||
## Creating Internal Tables and Types
|
||||
|
||||
You can declare internal tables and internal table types in [ABAP programs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_program_glosry.htm) using the [`TYPES`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaptypes.htm) and [`DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdata.htm) statements. The relevant syntactic elements for internal tables are `TABLE OF` in combination
|
||||
You can declare internal tables and internal table types in [ABAP programs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_program_glosry.htm) using the [`TYPES`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaptypes.htm) and [`DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdata.htm) statements. The relevant syntax elements for internal tables are `TABLE OF` in combination
|
||||
with the additions [`TYPE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdata_simple.htm)
|
||||
or [`LIKE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdata_referring.htm).
|
||||
|
||||
@@ -166,8 +168,8 @@ TYPES itab_type2 LIKE SORTED TABLE OF data_object ... "Sorted table type
|
||||
|
||||
DATA itab1 TYPE TABLE OF data_type ... "Standard table by default
|
||||
DATA itab2 TYPE HASHED TABLE OF data_type ... "Hashed table
|
||||
DATA itab3 TYPE table_type ... "Based on an existing internal table type
|
||||
DATA itab4 LIKE tab ... "Based on an existing internal table
|
||||
DATA itab3 TYPE itab_type1 ... "Based on an existing internal table type
|
||||
DATA itab4 LIKE itab1 ... "Based on an existing internal table
|
||||
```
|
||||
|
||||
> **💡 Note**<br>
|
||||
@@ -544,15 +546,21 @@ itab = VALUE #( ( comp1 = a comp2 = b ...)
|
||||
( LINES OF itab2 )
|
||||
... ).
|
||||
```
|
||||
A simple assignment without a constructor expression that **copies the content of another internal table** (note that the existing content in `itab` are deleted). The example below assumes that the source and target table have compatible line types. Otherwise, assignment rules must be considered.
|
||||
A simple assignment without a constructor expression that **copies the content of another internal table** (note that the existing content in `itab` are deleted). The example below assumes that the source and target table have compatible line types.
|
||||
``` abap
|
||||
itab = itab2.
|
||||
```
|
||||
> **💡 Note**<br>
|
||||
> - Internal tables can only be assigned to internal tables.
|
||||
> - Internal tables can be assigned to each other if their line types are [compatible](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencompatible_glosry.htm) or [convertible](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconvertible_glosry.htm).
|
||||
> - An assignment can trigger an uncatchable exception if, for example, the target table is assigned a duplicate of a unique primary table key or secondary table.
|
||||
> More information: [Conversion Rules for Internal Tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconversion_itab.htm)
|
||||
|
||||
**Copying the content of another internal table** using the
|
||||
[`CORRESPONDING`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expr_corresponding.htm) operator.
|
||||
- Note that the existing content are deleted.
|
||||
- As an alternative to the `CORRESPONDING` operator, you can use [`MOVE-CORRESPONDING`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmove-corresponding.htm) statements.
|
||||
- The example assumes that the line types of the source and target table are not compatible. However, if the line types are the same, the syntax will also work.
|
||||
- The example assumes that the line types of the source and target table are not compatible. However, if the line types are compatible, the syntax will also work.
|
||||
|
||||
``` abap
|
||||
itab = CORRESPONDING #( itab3 ).
|
||||
@@ -842,9 +850,7 @@ The following code snippets include [`READ TABLE`](https://help.sap.com/doc/abap
|
||||
|
||||
- Reading a line into a [data reference
|
||||
variable](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_reference_variable_glosry.htm "Glossary Entry")
|
||||
using `REFERENCE INTO`. In this case, no copying takes place. You cannot modify the table using the [data
|
||||
reference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_reference_glosry.htm "Glossary Entry"),
|
||||
and you cannot use the addition `TRANSPORTING`.
|
||||
using `REFERENCE INTO`. In this case, no copying takes place. If you want to address the line, you must first [dereference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendereferencing_operat_glosry.htm) the data reference. You cannot use the addition `TRANSPORTING`.
|
||||
|
||||
``` abap
|
||||
READ TABLE itab REFERNCE INTO dref ...
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Structures
|
||||
|
||||
- [Structures](#structures)
|
||||
- [Structures ...](#structures-)
|
||||
- [Introduction](#introduction)
|
||||
- [Creating Structures and Structured Types](#creating-structures-and-structured-types)
|
||||
- [Variants of Structures](#variants-of-structures)
|
||||
- [Accessing (Components of) Structures](#accessing-components-of-structures)
|
||||
@@ -13,7 +13,8 @@
|
||||
- [Excursion: Including Structures](#excursion-including-structures)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
## Structures ...
|
||||
## Introduction
|
||||
Structures ...
|
||||
|
||||
- are [data objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_object_glosry.htm "Glossary Entry")
|
||||
with [structured data types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstructured_type_glosry.htm "Glossary Entry") (which is a [complex data type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencomplex_data_type_glosry.htm "Glossary Entry") because it is composed of other data types).
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<a name="top"></a>
|
||||
|
||||
# ABAP SQL in Use
|
||||
# ABAP SQL
|
||||
|
||||
- [ABAP SQL in Use](#abap-sql-in-use)
|
||||
- [ABAP SQL Intro](#abap-sql-intro)
|
||||
- [ABAP SQL](#abap-sql)
|
||||
- [Introduction](#introduction)
|
||||
- [Reading Data Using SELECT](#reading-data-using-select)
|
||||
- [Basic Syntax](#basic-syntax)
|
||||
- [Using SELECT for Multiple Purposes](#using-select-for-multiple-purposes)
|
||||
@@ -28,7 +28,7 @@
|
||||
- [More Information](#more-information)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
## ABAP SQL Intro
|
||||
## Introduction
|
||||
|
||||
- [ABAP SQL](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_glosry.htm) is a subset of [SQL](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abensql_glosry.htm "Glossary Entry")
|
||||
which is the standardized language for accessing databases.
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
- [Excursion: Factory Methods and Singletons as Design Patterns](#excursion-factory-methods-and-singletons-as-design-patterns)
|
||||
- [More Information](#more-information)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
## Classes and Objects
|
||||
|
||||
Object-oriented programming in ABAP means dealing with
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Dynamic Programming
|
||||
|
||||
- [Dynamic Programming](#dynamic-programming)
|
||||
- [Notes on Dynamic Programming](#notes-on-dynamic-programming)
|
||||
- [Introduction](#introduction)
|
||||
- [Excursion: Field Symbols and Data References](#excursion-field-symbols-and-data-references)
|
||||
- [Field Symbols](#field-symbols)
|
||||
- [Data References](#data-references)
|
||||
@@ -15,7 +15,7 @@
|
||||
- [More Information](#more-information)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
## Notes on Dynamic Programming
|
||||
## Introduction
|
||||
|
||||
- Regarding "dynamic" in contrast to "static" aspects, [ABAP programs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_program_glosry.htm) can include both dynamic and static parts.
|
||||
- Consider a [data object](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_object_glosry.htm "Glossary Entry") in your program:
|
||||
@@ -614,12 +614,12 @@ world. Recommended read: [Accessing Data Objects Dynamically (F1 docu for standa
|
||||
As already mentioned above, there are ABAP statements that support the dynamic specification of syntax elements.
|
||||
In this context, you can usually use elementary, character-like data objects - the content is usually provided in capital letters - specified within a pair of parentheses.
|
||||
``` abap
|
||||
"Named, character-like data object specified within parenteses
|
||||
"Named, character-like data object specified within parentheses
|
||||
"used by an ABAP statement
|
||||
DATA(field_name) = 'CARRNAME'.
|
||||
SORT itab BY (field_name).
|
||||
|
||||
"Unnamed, character-like data object specified within parenteses
|
||||
"Unnamed, character-like data object specified within parentheses
|
||||
SORT itab BY ('CURRCODE').
|
||||
```
|
||||
|
||||
@@ -759,7 +759,7 @@ Note that dynamically specifying syntax elements has downsides, too. Consider so
|
||||
|
||||
"Note: As covered further down and in the executable example,
|
||||
"CREATE DATA/OBJECT and ASSIGN statements have the HANDLE addition
|
||||
"after which dynmically created types can be specified. A type
|
||||
"after which dynamically created types can be specified. A type
|
||||
"description object is expected.
|
||||
CREATE DATA dref TYPE HANDLE type_descr_obj.
|
||||
CREATE OBJECT oref TYPE HANDLE type_descr_obj.
|
||||
@@ -1226,7 +1226,7 @@ As shown above, anonymous data objects can be dynamically created using `CREATE
|
||||
- dynamically: `CREATE DATA dref TYPE (some_type).`
|
||||
|
||||
Another way to dynamically create data objects with dynamic type specification is to use types created at runtime with RTTC methods.
|
||||
The `CREATE DATA` statement provides the [`TYPE HANDLE`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcreate_data_handle.htm) addition after which you can specify type description objects.
|
||||
The `CREATE DATA` statement provides the [`TYPE HANDLE`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcreate_data_handle.htm) addition after which you can specify type description objects. A reference variable of the static type of class `CL_ABAP_DATADESCR` or its subclasses that points to a type description object can be specified after `TYPE HANDLE`.
|
||||
|
||||
``` abap
|
||||
DATA dref_cr TYPE REF TO data.
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
- [EML Syntax](#eml-syntax)
|
||||
- [EML Syntax for Modifying Operations](#eml-syntax-for-modifying-operations)
|
||||
- [EML Syntax for Reading Operations](#eml-syntax-for-reading-operations)
|
||||
- [Dynamic Forms of EML Statements](#dynamic-forms-of-eml-statements)
|
||||
- [Persisting to the Database](#persisting-to-the-database)
|
||||
- [EML Statements in ABAP Behavior Pools](#eml-statements-in-abap-behavior-pools)
|
||||
- [RAP Excursions](#rap-excursions)
|
||||
@@ -887,6 +888,103 @@ READ ENTITIES OF root_ent
|
||||
```
|
||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||
|
||||
#### Dynamic Forms of EML Statements
|
||||
|
||||
In addition to the short and long forms described above, various ABAP EML statements also have dynamic forms.
|
||||
Taking EML read operations as an example, the following code snippet shows a dynamic EML [`READ ENTITIES`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapread_entities_operations.htm) statement. The relevant syntax element is the `OPERATIONS` addition.
|
||||
The dynamic form allows the collection of read operations for multiple RAP BOs in one EML statement.
|
||||
For more information, see the ABAP keyword documentation and the comments in the snippet.
|
||||
|
||||
```abap
|
||||
"The statement is taken from the executable example. The example has a
|
||||
"root entity and a child entity. For both entities, RAP BO instances
|
||||
"are to be read (read and read-by-association operation).
|
||||
|
||||
DATA:
|
||||
"The following data object is the operand of the dynamic EML statement
|
||||
"It is an internal table and has a special, RAP-specific type.
|
||||
op_tab TYPE abp_behv_retrievals_tab,
|
||||
|
||||
"More data object declarations (internal tables typed with BDEF
|
||||
"derived types) that are relevant for the EML statement.
|
||||
"For both entities (root and child), RAP BO instances are to be
|
||||
"read. The internal tables are used for components of the internal
|
||||
"table op_tab further down.
|
||||
read_dyn TYPE TABLE FOR READ IMPORT zdemo_abap_rap_ro_m,
|
||||
read_dyn_result TYPE TABLE FOR READ RESULT zdemo_abap_rap_ro_m,
|
||||
rba_dyn TYPE TABLE FOR READ IMPORT zdemo_abap_rap_ro_m\_child,
|
||||
rba_dyn_result TYPE TABLE FOR READ RESULT zdemo_abap_rap_ro_m\_child,
|
||||
rba_dyn_link TYPE TABLE FOR READ LINK zdemo_abap_rap_ro_m\_child.
|
||||
|
||||
"Filling the internal tables, i.e. which instances are to be read
|
||||
"Root entity
|
||||
"Example:
|
||||
"- The key is comprised of the field 'key_field'. It is of type i.
|
||||
"- The %control structure is filled, flagging those fields that
|
||||
" are to be read. Flagging the key field is not required.
|
||||
read_dyn = VALUE #(
|
||||
( %key-key_field = 1
|
||||
%control = VALUE #(
|
||||
field1 = if_abap_behv=>mk-on
|
||||
field2 = if_abap_behv=>mk-on
|
||||
field3 = if_abap_behv=>mk-on
|
||||
field4 = if_abap_behv=>mk-on ) )
|
||||
( %key-key_field = 2
|
||||
%control = VALUE #(
|
||||
field1 = if_abap_behv=>mk-on
|
||||
field2 = if_abap_behv=>mk-on
|
||||
field3 = if_abap_behv=>mk-on
|
||||
field4 = if_abap_behv=>mk-on ) ) ).
|
||||
|
||||
"Child entity
|
||||
"Instances to be read for a read-by-association operation
|
||||
"The shared key is 'key_field'.
|
||||
rba_dyn = VALUE #(
|
||||
( %key-key_field = 1
|
||||
%control = VALUE #(
|
||||
key_ch = if_abap_behv=>mk-on
|
||||
field_ch1 = if_abap_behv=>mk-on
|
||||
field_ch2 = if_abap_behv=>mk-on ) )
|
||||
( %key-key_field = 2
|
||||
%control = VALUE #(
|
||||
key_ch = if_abap_behv=>mk-on
|
||||
field_ch1 = if_abap_behv=>mk-on
|
||||
field_ch2 = if_abap_behv=>mk-on ) ) ).
|
||||
|
||||
"Filling the internal table that is the operand of the
|
||||
"dynamic EML statement
|
||||
"This table has optional and mandatory components.
|
||||
op_tab = VALUE #(
|
||||
( "op: Specifies the operation to be executed; is mandatory;
|
||||
" can be set with the predefined constants, e.g. OP-R-READ
|
||||
" etc., of interface IF_ABAP_BEHV
|
||||
op = if_abap_behv=>op-r-read
|
||||
"entity_name: Specifies the name of the RAP BO entity for which
|
||||
" the operation is executed; is mandatory
|
||||
entity_name = 'ZDEMO_ABAP_RAP_RO_M'
|
||||
"instances: Specifies a reference to an internal table holding
|
||||
" the input keys; must be appropriately typed; is mandatory
|
||||
instances = REF #( read_dyn )
|
||||
"results: Specifies a reference to an internal table with the required
|
||||
" BDEF derived type for the read results; is mandatory
|
||||
results = REF #( read_dyn_result ) )
|
||||
( op = if_abap_behv=>op-r-read_ba
|
||||
entity_name = 'ZDEMO_ABAP_RAP_RO_M'
|
||||
"sub_name: Only relevant for specifying association names in
|
||||
" read-by-association operations; in that context, it is mandatory
|
||||
sub_name = '_CHILD'
|
||||
"full: Optional flag; specifies if all target instances are to be retrieved
|
||||
full = abap_true
|
||||
instances = REF #( rba_dyn )
|
||||
results = REF #( rba_dyn_result )
|
||||
"links: Reference to internal table holding the key pairs of the source and
|
||||
" target
|
||||
links = REF #( rba_dyn_link ) ) ).
|
||||
|
||||
READ ENTITIES OPERATIONS op_tab.
|
||||
```
|
||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||
|
||||
### Persisting to the Database
|
||||
|
||||
- A [`COMMIT
|
||||
@@ -1059,11 +1157,27 @@ instances](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?
|
||||
instances.
|
||||
- **Note:** A further component group to refer to the keys is available: [`%pky`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapderived_types_pky.htm). `%pky` contains `%pid` and `%key` in late numbering scenarios. In non-late numbering scenarios, it just contains `%key`. `%pky` itself is contained in `%tky`. There are contexts, for example, particular actions, where `%tky` is not available but `%pky` is. This way, there is still the option to summarize `%pid` and `%key` in one component group in the absence of `%tky`.
|
||||
|
||||
**General rule**: A RAP BO instance must always be uniquely
|
||||
**General rule**: A RAP BO instance must - where available - always be uniquely
|
||||
identifiable by its transactional key (`%tky`) for internal
|
||||
processing during the RAP interaction phase. `%tky` always
|
||||
contains all relevant components for the chosen scenario.
|
||||
|
||||
> **💡 Note**<br>
|
||||
> Assignment of Key Component Groups
|
||||
>
|
||||
> As a general best practice, you should use a RAP BO instance key component group when referring to the entire key, rather than listing the individual key fields. It is recommended that you use `%tky` whenever possible.
|
||||
> In the following cases, type compatibility cannot be guaranteed in component group assignments:
|
||||
> - Mixing key component groups when they refer to the same RAP BO entity, e.g. `wa-%tky = wa-%key`. Such an assignment should also be avoided when both component groups have an identical scope in terms of components (e.g. `%tky` and `%key` in non-late-numbering and non-draft scenarios).
|
||||
> - Mixing the same key component groups when referring to two different RAP BO entities, for example, `wa_root-%tky = wa_child-%tky`. In this case, adding more components later may cause syntax errors for an assignment that worked previously.
|
||||
> - Defining structured types that have the same components as key component groups, and then assigning data objects of that type to those of the respective, original key component group.
|
||||
> In the above cases, the `CORRESPONDING` operator can be used to ensure type compatibility in assignments to key component groups:
|
||||
> ```abap
|
||||
>... %tky = CORRESPONDING #( wa-%tky ) ...
|
||||
>... %key = CORRESPONDING #( wa-%key ) ...
|
||||
>... %pky = CORRESPONDING #( wa-%pky ) ...
|
||||
>```
|
||||
> In cases where different data objects of key component groups of a BDEF derived type are to be assigned to the same key component group of the same entity, a direct assignment works without a syntax warning because the content is identical. A direct assignment is recommended (`...wa1_root-%tky = wa2_root-%tky ...`). The use of the `CORRESPONDING` operator is unnecessary and less performant. This is true, for example, for key component group assignments in the context of RAP response parameters failed and reported.
|
||||
|
||||
</details>
|
||||
|
||||
### RAP Concepts
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# ABAP Managed Database Procedures (AMDP)
|
||||
|
||||
- [ABAP Managed Database Procedures (AMDP)](#abap-managed-database-procedures-amdp)
|
||||
- [About AMDP](#about-amdp)
|
||||
- [Introduction](#introduction)
|
||||
- [AMDP Classes](#amdp-classes)
|
||||
- [AMDP Methods](#amdp-methods)
|
||||
- [AMDP Procedures](#amdp-procedures)
|
||||
@@ -20,7 +20,7 @@ Find more details
|
||||
[here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenamdp.htm)
|
||||
in the ABAP Keyword Documentation.
|
||||
|
||||
## About AMDP
|
||||
## Introduction
|
||||
|
||||
- AMDP are a class-based framework for managing and calling
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Program Flow Logic
|
||||
|
||||
- [Program Flow Logic](#program-flow-logic)
|
||||
- [Intro](#intro)
|
||||
- [Introduction](#introduction)
|
||||
- [Expressions and Functions for Conditions](#expressions-and-functions-for-conditions)
|
||||
- [Control Structures](#control-structures)
|
||||
- [`IF` Statements](#if-statements)
|
||||
@@ -27,7 +27,7 @@ This cheat sheet gathers information on program flow logic. Find more details
|
||||
[here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_flow_logic.htm)
|
||||
in the ABAP Keyword Documentation.
|
||||
|
||||
## Intro
|
||||
## Introduction
|
||||
|
||||
In ABAP, the flow of a program is controlled by [control structures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencontrol_structure_glosry.htm), [procedure](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenprocedure_glosry.htm) calls and the raising or handling of [exceptions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenexception_glosry.htm).
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ ENDCLASS.
|
||||
> - `SHORT`: execution time of only a few seconds is expected
|
||||
> - `MEDIUM`: execution time of about one minute is expected
|
||||
> - `LONG`: execution time of more than one minute is expected
|
||||
> - To create a class in ADT, type "test" in the "Test Class" tab and choose `CTRL` and `SPACE` to display the templates suggestions. You can then choose "testClass – Test class (ABAP Unit)". The skeleton of a test class is automatically generated.
|
||||
> - To create a class in ADT, type "test" in the "Test Classes" tab and choose `CTRL` and `SPACE` to display the templates suggestions. You can then choose "testClass – Test class (ABAP Unit)". The skeleton of a test class is automatically generated.
|
||||
|
||||
To test protected or private methods, you must declare [friendship](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfriend_glosry.htm) with the class to be tested (class under test).
|
||||
Example:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
# Data Types and Data Objects
|
||||
|
||||
- [Data Types and Data Objects](#data-types-and-data-objects)
|
||||
- [Introduction](#introduction)
|
||||
- [Data Types and Objects: Definition](#data-types-and-objects-definition)
|
||||
- [ABAP Data Types](#abap-data-types)
|
||||
- [Elementary Data Types](#elementary-data-types)
|
||||
@@ -17,12 +18,14 @@
|
||||
- [Creating Anonymous Data Objects](#creating-anonymous-data-objects)
|
||||
- [Constants and Immutable Variables](#constants-and-immutable-variables)
|
||||
- [Type Conversion](#type-conversion)
|
||||
- [Glossary Terms in a Nutshell](#glossary-terms-in-a-nutshell)
|
||||
- [Terms Related to Types and Data Objects in a Nutshell](#terms-related-to-types-and-data-objects-in-a-nutshell)
|
||||
- [Notes on the Declaration Context](#notes-on-the-declaration-context)
|
||||
- [Excursion: Enumerated Types and Objects](#excursion-enumerated-types-and-objects)
|
||||
- [Excursions](#excursions)
|
||||
- [Enumerated Types and Objects](#enumerated-types-and-objects)
|
||||
- [Getting Type Information and Creating Types at Runtime](#getting-type-information-and-creating-types-at-runtime)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
|
||||
## Introduction
|
||||
[ABAP statements](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_statement_glosry.htm) usually work with [data objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_object_glosry.htm), that is, with transient data that occupies memory space while the [data type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_type_glosry.htm) defines the technical properties of the data objects.
|
||||
Since data types and data objects are closely related, this cheat sheet covers both topics.
|
||||
Note that the topics covered here are also partly covered in other ABAP cheat sheets. The purpose of this cheat sheet is to summarize the basics.
|
||||
@@ -35,7 +38,7 @@ Data types
|
||||
- Can occur in [ABAP programs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_program_glosry.htm) as [bound data types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbound_data_type_glosry.htm), that is, the type is a property of a data object, or as a [standalone data type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstand-alone_data_type_glosry.htm), that is, the data type is defined independently.
|
||||
- Can be defined locally in an ABAP program or globally in classes, interfaces and in the [ABAP Dictionary (DDIC)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_dictionary_glosry.htm).
|
||||
> **💡 Note**<br>
|
||||
> - Note: Data types in the ABAP Dictionary are either created directly as [repository objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrepository_object_glosry.htm) ([DDIC data elements](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_element_glosry.htm)) or in a type pool (only in [Standard ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_abap_glosry.htm)). [Database table](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendatabase_table_glosry.htm), [CDS entities](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_glosry.htm) and their components can also be used as data types in ABAP programs.
|
||||
> - Note: Data types in the ABAP Dictionary are either created directly as [repository objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrepository_object_glosry.htm) ([DDIC data elements](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_element_glosry.htm)) or in a type pool (only in [Standard ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_abap_glosry.htm)). [Database tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendatabase_table_glosry.htm), [CDS entities](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_glosry.htm) and their components can also be used as data types in ABAP programs.
|
||||
> - Their existence and visibility depends on the declaration context.
|
||||
|
||||
Data objects:
|
||||
@@ -110,8 +113,8 @@ For an overview, see the [ABAP Type Hierarchy](https://help.sap.com/doc/abapdocu
|
||||
- The typical syntax element is `... REF TO ...`.
|
||||
|
||||
> **💡 Note**<br>
|
||||
> There are [generic ABAP types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abengeneric_abap_type_glosry.htm). Generic data types are types that do not define all of the properties of a data object. They can only be used for the typing [formal parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenformal_parameter_glosry.htm) and [field symbols](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm).
|
||||
The only generic types that can be used after `TYPE REF TO` are `data`, for the generic typing of data references, and `object`, for the generic typing of object references.
|
||||
> There are [generic ABAP types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abengeneric_abap_type_glosry.htm). Generic data types are types that do not define all of the properties of a data object. They can only be used for the typing of [formal parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenformal_parameter_glosry.htm) and [field symbols](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfield_symbol_glosry.htm).
|
||||
The only generic types that can be used after `TYPE REF TO` are `data` for the generic typing of data references, and `object`, for the generic typing of object references.
|
||||
|
||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||
|
||||
@@ -473,10 +476,11 @@ DATA dref_tab_str LIKE TABLE OF REF TO do_some_string.
|
||||
An assignment passes the contents of a source to a target data object.
|
||||
|
||||
> **💡 Note**<br>
|
||||
> - There are conversion rules when assigning a source to a target data object that have different types. See below.
|
||||
> - In old ABAP code, you may see `MOVE ... TO ...` statements for value assignments. These statements are obsolete. They are not to be confused with `MOVE-CORRESPONDING` statements for complex types. These are not obsolete.
|
||||
> - There are conversion rules when assigning a source to a target data object that have different types. For more information, see the topic [Assignment and Conversion Rules](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconversion_rules.htm) in the ABAP Keyword Documentation, especially for complex types, since elementary types are usually demonstrated in the cheat sheet.
|
||||
> - There are many ways to assigning values to data objects in ABAP. Assignments with the assignment operator `=` are mostly used here.
|
||||
> - In older ABAP code, you may see `MOVE ... TO ...` statements for value assignments. These statements are obsolete. They are not to be confused with `MOVE-CORRESPONDING` statements for complex types. These are not obsolete.
|
||||
|
||||
The following code snippet shows various ways of assigning values to data objects.
|
||||
The following code snippet shows several ways to assign values to data objects.
|
||||
|
||||
```abap
|
||||
"As mentioned, a start value can be directly assigned when declaring a data object.
|
||||
@@ -924,7 +928,7 @@ See the conversion rules for the different data types here: [Assignment and Conv
|
||||
> - Typically, assignements are made using the assignment operator `=`. If necessary and applicable, the type is converted implicitly. However, you can also use the conversion operator [`CONV`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_conv.htm) to convert types explicitly.
|
||||
> - For [lossless assignments](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenlossless_assignment_glosry.htm), the lossless operator [`EXACT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_exact.htm) can be used to perform checks before the conversion is performed to ensure that only valid values are assigned and that no values are lost in assignments.
|
||||
> - In general, no checks are performed on assignments between compatible data objects. If a data object already contains an invalid value, for example, an invalid date or time in a date or time field, it is passed a valid value when the assignment is made to a compatible data object.
|
||||
> - The `applies_to_data` method of the [RTTI](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm) class `cl_abap_datadescr` can be used to check type compatibility. See the executable example.
|
||||
> - The `applies_to_data` method of the [RTTI](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm) class `cl_abap_datadescr` can be used to check type compatibility. See the executable example.
|
||||
|
||||
|
||||
```abap
|
||||
@@ -953,12 +957,13 @@ DATA(i2str) = CONV string( -10 ).
|
||||
|
||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||
|
||||
## Glossary Terms in a Nutshell
|
||||
## Terms Related to Types and Data Objects in a Nutshell
|
||||
|
||||
```abap
|
||||
"Standalone and bound data types
|
||||
"Standalone: Data type that is defined using the statement TYPES in an ABAP program, as a data type
|
||||
" of the ABAP Dictionary or as an CDS entity.
|
||||
"Standalone: Data type that is defined using the statement TYPES in an
|
||||
" ABAP program, as a data type of the ABAP Dictionary or as
|
||||
" an CDS entity.
|
||||
"Bound: Data type that only exists as a property of a data object.
|
||||
|
||||
"Standalone data type
|
||||
@@ -972,8 +977,10 @@ TYPES te_b_like LIKE do_a_c20.
|
||||
**********************************************************************
|
||||
|
||||
"Complex and elementary data type/object
|
||||
"Elementary: Data type of fixed or variable length that is neither structured, nor a table type or a reference type.
|
||||
"Complex: Made up of other data types, for example structured data type/objects, a table type/internal tables
|
||||
"Elementary: Data type of fixed or variable length that is neither
|
||||
" structured, nor a table type or a reference type.
|
||||
"Complex: Made up of other data types, for example structured data
|
||||
" type/objects, a table type/internal tables
|
||||
|
||||
"Elementary
|
||||
DATA do_c_i TYPE i.
|
||||
@@ -993,8 +1000,8 @@ DATA: BEGIN OF struc_a,
|
||||
"Complete: Non-generic data type
|
||||
"Generic:
|
||||
"- Data type that does not set all properties of a data object.
|
||||
"- Can only be used for the typing of formal parameters and field symbols, except for
|
||||
" data reference variables using the generic type 'data'.
|
||||
"- Can only be used for the typing of formal parameters and field symbols,
|
||||
" except for data reference variables using the generic type 'data'.
|
||||
|
||||
"Complete data type
|
||||
DATA do_d_i TYPE i.
|
||||
@@ -1022,7 +1029,8 @@ ASSIGN itab_a TO <fs_b>.
|
||||
**********************************************************************
|
||||
|
||||
"Variable and constant data objects
|
||||
"Variable: Named data object whose value can be changed during the runtime of an ABAP program.
|
||||
"Variable: Named data object whose value can be changed during the runtime
|
||||
" of an ABAP program.
|
||||
"Constant: Named data object whose value cannot be changed at runtime.
|
||||
|
||||
"Variable
|
||||
@@ -1037,12 +1045,15 @@ CONSTANTS con_a_i TYPE i VALUE 789.
|
||||
|
||||
"Static and dynamic data objects
|
||||
"Static:
|
||||
"- Data object for which all attributes, including memory use, are specified statically by the data type.
|
||||
"- Data object for which all attributes, including memory use, are specified
|
||||
" statically by the data type.
|
||||
"- Apart from reference variables, all static data objects are flat.
|
||||
"Dynamic:
|
||||
"- Data object for which all properties apart from the memory consumption are statically determined by the data type.
|
||||
"- Dynamic data objects are strings and internal tables. They belong to the deep data objects. Structures that contain
|
||||
" dynamic components are also dynamic data objects.
|
||||
"- Data object for which all properties apart from the memory consumption are
|
||||
" statically determined by the data type.
|
||||
"- Dynamic data objects are strings and internal tables. They belong to the
|
||||
" deep data objects. Structures that contain dynamic components are also
|
||||
" dynamic data objects.
|
||||
|
||||
"Static data object
|
||||
DATA do_h_c5 TYPE c LENGTH 3.
|
||||
@@ -1061,12 +1072,12 @@ do_i_str = `efghijklmnopqrstuvwxyz`.
|
||||
**********************************************************************
|
||||
|
||||
"Static type and dynamic type
|
||||
"Both are data types of a reference variable (reference type) that determine the objects
|
||||
"a reference variable can point to.
|
||||
"Static type: For data reference variables, the static type is a data type that is
|
||||
" always more general than or the same as the dynamic type.
|
||||
"Dynamic type: For a reference variable, the dynamic type is always more special than
|
||||
" or equal to the static type.
|
||||
"Both are data types of a reference variable (reference type) that determine
|
||||
"the objects a reference variable can point to.
|
||||
"Static type: For data reference variables, the static type is a data type
|
||||
" that is always more general than or the same as the dynamic type.
|
||||
"Dynamic type: For a reference variable, the dynamic type is always more special
|
||||
" than or equal to the static type.
|
||||
|
||||
"Static type
|
||||
DATA dref_a_i TYPE REF TO i. "Static type is i
|
||||
@@ -1079,7 +1090,8 @@ DATA do_k_str TYPE string VALUE `hallo`.
|
||||
"Dynamic types
|
||||
dref_a_i = REF #( do_j_i ). "Only type i possible; the dynamic type is the same
|
||||
|
||||
"The dynamic type is more special than the static type (which is the generic type data in this case)
|
||||
"The dynamic type is more special than the static type (which is the generic
|
||||
"type data in this case)
|
||||
dref_b_data = REF #( do_j_i ).
|
||||
dref_b_data = REF #( do_k_str ).
|
||||
dref_b_data = REF #( dref_a_i ).
|
||||
@@ -1088,15 +1100,16 @@ dref_b_data = REF #( dref_a_i ).
|
||||
|
||||
"Flat and deep data objects
|
||||
"Flat:
|
||||
"- Property of a data type, where the content of its data objects represents the actual work data.
|
||||
"- Property of a data type, where the content of its data objects represents
|
||||
" the actual work data.
|
||||
"- All elementary data types except string and xstring are flat
|
||||
"Deep:
|
||||
"- Dynamic data objects and reference variables are deep, and they contain references that refer
|
||||
" to the actual content.
|
||||
"- The handling of references is implicit for dynamic data objects (strings and internal tables),
|
||||
" and explicit for reference variables.
|
||||
"- Structures that do not contain any deep components are flat structures. Structures that contain
|
||||
" at least one deep component are deep structures.
|
||||
"- Dynamic data objects and reference variables are deep, and they contain
|
||||
" references that refer to the actual content.
|
||||
"- The handling of references is implicit for dynamic data objects (strings
|
||||
" and internal tables), and explicit for reference variables.
|
||||
"- Structures that do not contain any deep components are flat structures.
|
||||
" Structures that contain at least one deep component are deep structures.
|
||||
|
||||
"Flat elementary data object
|
||||
DATA do_l_i TYPE i.
|
||||
@@ -1122,8 +1135,8 @@ DATA: BEGIN OF struc_c_deep,
|
||||
|
||||
"Named and unnamed data object
|
||||
"Named: Data object that can be identified via a name.
|
||||
"Unnamed: Data object that cannot be addressed by a name. Unnamed data objects are literals
|
||||
" and anonymous data objects.
|
||||
"Unnamed: Data object that cannot be addressed by a name. Unnamed data
|
||||
" objects are literals and anonymous data objects.
|
||||
|
||||
"Named data objects
|
||||
DATA do_n_i TYPE i.
|
||||
@@ -1138,11 +1151,45 @@ output->display( `I'm a literal...` ).
|
||||
|
||||
DATA(dref_c_str) = NEW string( `hi` ).
|
||||
|
||||
"Anonymous data object created inline using the NEW addition to the INTO clause of a SELECT statement
|
||||
"Anonymous data object created inline using the NEW addition to the INTO
|
||||
"clause of a SELECT statement
|
||||
SELECT *
|
||||
FROM zdemo_abap_carr
|
||||
INTO TABLE NEW @DATA(dref_d_tab)
|
||||
UP TO 3 ROWS.
|
||||
|
||||
**********************************************************************
|
||||
|
||||
"Source and target data objectsCompatibility, convertibility and
|
||||
"conversion
|
||||
"1. Source and target are compatible, all technical type properties
|
||||
" match
|
||||
DATA some_dobj TYPE c LENGTH 1 VALUE 'A'.
|
||||
DATA flag TYPE abap_bool VALUE 'X'.
|
||||
|
||||
"Assignment of compatible types; content transferred without
|
||||
"conversion
|
||||
some_dobj = flag.
|
||||
|
||||
"2. Source and target are not compatible but can be converted.
|
||||
" Content of source is converted according to conversion rules
|
||||
" and then transferred to the target. Two data types are
|
||||
" convertible if a conversion rule exists for them.
|
||||
DATA another_char TYPE c LENGTH 3 VALUE 'abc'.
|
||||
DATA some_str TYPE string VALUE `defghij`.
|
||||
|
||||
another_char = some_str.
|
||||
|
||||
"3. Data objects are neither compatible nor convertible. No
|
||||
" assignment possible. If recognized by the syntax check, a
|
||||
" syntax error is raised, otherwise an uncatchable exception
|
||||
" is raised when the program is executed.
|
||||
DATA some_number TYPE i VALUE 123.
|
||||
DATA itab_str TYPE string_table.
|
||||
|
||||
"Type conversion not possible
|
||||
"itab_str = some_number.
|
||||
"some_number = itab_str.
|
||||
```
|
||||
|
||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||
@@ -1166,7 +1213,8 @@ The declaration context of data types (and objects) determines the validity and
|
||||
|
||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||
|
||||
## Excursion: Enumerated Types and Objects
|
||||
## Excursions
|
||||
### Enumerated Types and Objects
|
||||
- ABAP supports the concept of enumerations.
|
||||
- Enumerations are a mixture of types and constants.
|
||||
- An [enumerated type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenenum_type_glosry.htm) specifies a value set in addition to the actual type properties.
|
||||
@@ -1223,6 +1271,13 @@ Find more information on enumerated types in the (commented code of the) cheat s
|
||||
|
||||
<p align="right">(<a href="#top">back to top</a>)</p>
|
||||
|
||||
### Getting Type Information and Creating Types at Runtime
|
||||
Using [Runtime Type Identification (RTTI)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm "Glossary Entry"), you can get type information on data objects, data types or [instances](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninstance_glosry.htm "Glossary Entry") at runtime ([Runtime Type Identification (RTTI)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_identific_glosry.htm "Glossary Entry")).
|
||||
Using [Runtime Type Creation (RTTC)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_creation_glosry.htm "Glossary Entry"), you an define and create new data types as [type description objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentype_object_glosry.htm) at runtime.
|
||||
|
||||
Find more information in the [cheat sheet about dynamic programming](06_Dynamic_Programming.md#runtime-type-services-rtts).
|
||||
|
||||
|
||||
## Executable Example
|
||||
[zcl_demo_abap_dtype_dobj](./src/zcl_demo_abap_dtype_dobj.clas.abap)
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ ABAP cheat sheets[^1] ...
|
||||
|[Data Types and Data Objects](16_Data_Types_and_Objects.md)| Contains basic information about data types and data objects in ABAP | [zcl_demo_abap_dtype_dobj](./src/zcl_demo_abap_dtype_dobj.clas.abap) |
|
||||
|[Internal Tables](01_Internal_Tables.md)| Creating, filling, reading from, sorting, modifying internal tables | [zcl_demo_abap_internal_tables](./src/zcl_demo_abap_internal_tables.clas.abap) |
|
||||
|[Structures](02_Structures.md)| Some basics when working with structures | [zcl_demo_abap_structures](./src/zcl_demo_abap_structures.clas.abap) |
|
||||
|[ABAP SQL in Use](03_ABAP_SQL.md)| Reading from database tables using `SELECT`, changing data in database tables using `INSERT`, `UPDATE`, `MODIFY` and `DELETE` | [zcl_demo_abap_sql](./src/zcl_demo_abap_sql.clas.abap) |
|
||||
|[ABAP SQL](03_ABAP_SQL.md)| Reading from database tables using `SELECT`, changing data in database tables using `INSERT`, `UPDATE`, `MODIFY` and `DELETE` | [zcl_demo_abap_sql](./src/zcl_demo_abap_sql.clas.abap) |
|
||||
|[ABAP Object Orientation](04_ABAP_Object_Orientation.md)| Working with objects and components, concepts like inheritance, interfaces, and more | [zcl_demo_abap_objects](./src/zcl_demo_abap_objects.clas.abap) |
|
||||
|[Constructor Expressions](05_Constructor_Expressions.md)| Covers constructor expressions with operators such as `VALUE`, `CORRESPONDING`, `NEW`, `CONV`, `EXACT`, `REF`, `CAST`, `COND`, `SWITCH`, `FILTER`, `REDUCE`, iteration expressions with `FOR`, `LET` expressions | [zcl_demo_abap_constructor_expr](./src/zcl_demo_abap_constructor_expr.clas.abap) |
|
||||
|[Dynamic Programming](06_Dynamic_Programming.md)| Covers field symbols and data references as supporting elements for dynamic programming, dynamic ABAP syntax components, runtime type services (RTTS), i. e. runtime type identification (RTTI) and runtime type creation (RTTC) | [zcl_demo_abap_dynamic_prog](./src/zcl_demo_abap_dynamic_prog.clas.abap) |
|
||||
|
||||
@@ -510,7 +510,7 @@ CLASS lhc_root IMPLEMENTATION.
|
||||
"Filling the table for the RESULT parameter based on the FULL parameter
|
||||
"Note: If the FULL parameter is initial, only the LINK parameter should be provided
|
||||
IF result_requested = abap_true.
|
||||
APPEND VALUE #( %tky = <rba>-%tky
|
||||
APPEND VALUE #( %tky = CORRESPONDING #( <rba>-%tky )
|
||||
key_ch = COND #( WHEN <rba>-%control-key_ch NE if_abap_behv=>mk-off
|
||||
THEN <ch>-instance-key_ch )
|
||||
field_ch1 = COND #( WHEN <rba>-%control-field_ch1 NE if_abap_behv=>mk-off
|
||||
@@ -967,7 +967,7 @@ CLASS lhc_child IMPLEMENTATION.
|
||||
AND line_exists( lcl_buffer=>child_buffer[ instance-key_field = <rba>-key_field instance-key_ch = <rba>-key_ch ] ).
|
||||
|
||||
"Filling the LINK parameter
|
||||
INSERT VALUE #( target-%tky = <rba>-%tky
|
||||
INSERT VALUE #( target-%tky = CORRESPONDING #( <rba>-%tky )
|
||||
source-%tky = VALUE #( key_field = <rba>-key_field
|
||||
key_ch = <rba>-key_ch )
|
||||
) INTO TABLE association_links.
|
||||
@@ -979,7 +979,7 @@ CLASS lhc_child IMPLEMENTATION.
|
||||
|
||||
IF sy-subrc = 0.
|
||||
|
||||
APPEND VALUE #( %tky = <rba>-%tky
|
||||
APPEND VALUE #( %tky = CORRESPONDING #( <rba>-%tky )
|
||||
field1 = COND #( WHEN <rba>-%control-field1 NE if_abap_behv=>mk-off
|
||||
THEN <fs_rp>-instance-field1 )
|
||||
field2 = COND #( WHEN <rba>-%control-field2 NE if_abap_behv=>mk-off
|
||||
|
||||
@@ -194,7 +194,7 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
|
||||
|
||||
CATCH cx_amdp_execution_error INTO DATA(error1).
|
||||
|
||||
out->write( error1->get_text( ) ).
|
||||
output->display( error1->get_text( ) ).
|
||||
|
||||
ENDTRY.
|
||||
|
||||
|
||||
@@ -370,7 +370,7 @@ CLASS lcl_det_at_runtime IMPLEMENTATION.
|
||||
syntax_elements-rows = cl_abap_random_int=>create(
|
||||
seed = cl_abap_random=>seed( )
|
||||
min = 2
|
||||
max = 6 )->get_next( ).
|
||||
max = 5 )->get_next( ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
@@ -898,8 +898,8 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION.
|
||||
|
||||
**********************************************************************
|
||||
*
|
||||
* Excursion: Read and read-by-association operation using dynamic
|
||||
* EML statements
|
||||
* Excursion: Read and read-by-association operation using a dynamic
|
||||
* EML statement
|
||||
*
|
||||
**********************************************************************
|
||||
|
||||
@@ -932,14 +932,12 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION.
|
||||
* rba_dyn = VALUE #(
|
||||
* ( %key-key_field = 1
|
||||
* %control = VALUE #(
|
||||
* key_field = if_abap_behv=>mk-on
|
||||
* key_ch = if_abap_behv=>mk-on
|
||||
* field_ch1 = if_abap_behv=>mk-on
|
||||
* field_ch2 = if_abap_behv=>mk-on ) )
|
||||
* ( %key-key_field = 2
|
||||
* %control = VALUE #(
|
||||
* key_field = if_abap_behv=>mk-on
|
||||
* key_ch = if_abap_behv=>mk-on
|
||||
* key_ch = if_abap_behv=>mk-on
|
||||
* field_ch1 = if_abap_behv=>mk-on
|
||||
* field_ch2 = if_abap_behv=>mk-on ) ) ).
|
||||
*
|
||||
|
||||
@@ -1020,13 +1020,11 @@ CLASS zcl_demo_abap_rap_ext_num_u IMPLEMENTATION.
|
||||
* rba_dyn = VALUE #(
|
||||
* ( %key-key_field = 1
|
||||
* %control = VALUE #(
|
||||
* key_field = if_abap_behv=>mk-on
|
||||
* key_ch = if_abap_behv=>mk-on
|
||||
* field_ch1 = if_abap_behv=>mk-on
|
||||
* field_ch2 = if_abap_behv=>mk-on ) )
|
||||
* ( %key-key_field = 2
|
||||
* %control = VALUE #(
|
||||
* key_field = if_abap_behv=>mk-on
|
||||
* key_ch = if_abap_behv=>mk-on
|
||||
* field_ch1 = if_abap_behv=>mk-on
|
||||
* field_ch2 = if_abap_behv=>mk-on ) ) ).
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
***********************************************************************
|
||||
*
|
||||
* ABAP cheat sheet: ABAP SQL in Use
|
||||
* ABAP cheat sheet: ABAP SQL
|
||||
*
|
||||
* -------------------------- PURPOSE ----------------------------------
|
||||
* - Example to demonstrate various syntactical options for working with
|
||||
@@ -72,7 +72,7 @@ CLASS zcl_demo_abap_sql IMPLEMENTATION.
|
||||
|
||||
DATA(output) = NEW zcl_demo_abap_display( out ).
|
||||
|
||||
output->display( `ABAP Cheat Sheet Example: ABAP SQL in Use` ).
|
||||
output->display( `ABAP Cheat Sheet Example: ABAP SQL` ).
|
||||
output->display( `Using SELECT for multiple purposes` ).
|
||||
output->display( `1) Reading a single row from database table ` &&
|
||||
`into a structure` ).
|
||||
|
||||
@@ -22,6 +22,10 @@ late numbering
|
||||
determination det_modify on modify { field num1, num2, arithm_op; }
|
||||
draft action Resume;
|
||||
draft action Edit;
|
||||
//As of release 2308: Draft action "Activate" should be defined as "optimized"
|
||||
//to enable optimized execution of determinations and validations.
|
||||
//Comment in the following notation, comment out the one below.
|
||||
//draft action Activate optimized;
|
||||
draft action Activate;
|
||||
draft action Discard;
|
||||
draft determine action Prepare
|
||||
|
||||
Reference in New Issue
Block a user