This commit is contained in:
danrega
2024-09-30 17:27:20 +02:00
parent 239b041f62
commit 0d1ba58ac7
7 changed files with 506 additions and 168 deletions

View File

@@ -9,7 +9,7 @@
- [Creating Internal Tables and Types](#creating-internal-tables-and-types)
- [Specifying Keys in Internal Table Declarations](#specifying-keys-in-internal-table-declarations)
- [Internal Tables Based on Locally Created Line/Table Types](#internal-tables-based-on-locally-created-linetable-types)
- [Line Type Options of Internal Tables](#line-type-options-of-internal-tables)
- [Line/Table Type Options of Internal Tables](#linetable-type-options-of-internal-tables)
- [Creating Internal Tables By Inline Declaration](#creating-internal-tables-by-inline-declaration)
- [Creating Internal Tables Dynamically](#creating-internal-tables-dynamically)
- [Populating Internal Tables](#populating-internal-tables)
@@ -53,6 +53,7 @@
- [Deleting Adjacent Duplicate Lines](#deleting-adjacent-duplicate-lines)
- [Deleting the Entire Internal Table Content](#deleting-the-entire-internal-table-content)
- [Grouping Internal Tables](#grouping-internal-tables)
- [Collecting Calues](#collecting-calues)
- [Excursions](#excursions)
- [Improving Read Performance with Secondary Table Keys](#improving-read-performance-with-secondary-table-keys)
- [Example: Exploring Read Access Performance with Internal Tables](#example-exploring-read-access-performance-with-internal-tables)
@@ -439,13 +440,18 @@ DATA it27 LIKE TABLE OF it25.
<p align="right"><a href="#top">⬆️ back to top</a></p>
### Line Type Options of Internal Tables
### Line/Table Type Options of Internal Tables
This section explores various line type options when declaring internal tables.Apart from the (globally available) line types of database tables, you can also use other line/table types. Among them, for example:
- globally available line type of DDIC structures and CDS entities
- globally available table types declared in the DDIC
- locally declared line and table types (as shown above)
- line and table types declared in the public visibility section of classes/interfaces that are gloablly visibile
This section explores various line (i.e. structured) and table type options when declaring internal tables. Various examples have already been covered in the previous sections. Among the options are, for example:
- Elementary line types based on elementary built-in ABAP types, locally declared elementary types, globally available elementary types such as DDIC data elements
- Line types based on both locally declared and globally available structured types
- Among the globally available line types are, for example, DDIC structures, database tables and CDS objects such as CDS view entities
- Note that internal tables can be created as [deep tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendeep_table_glosry.htm). That is, internal tables can contain [deep](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendeep_glosry.htm) components (references, internal tables or strings). Structures can also be components of internal tables. For more information, see the [Variants of Structures](02_Structures.md#variants-of-structures) in the *Structures* cheat sheet.
- Table types based on both locally declared and globally available table types
- References
> **💡 Note**<br>
> Types declared in the public visibility section of classes/interfaces are also globally visible and can be used for the creation.
<table>
<tr>
@@ -458,21 +464,43 @@ This section explores various line type options when declaring internal tables.A
``` abap
"The whole table line is the standard table key.
"The following examples use built-in ABAP types. Besides these types,
"you can also use locally declared elementary types, globally declared
"elementary types such as DDIC data elements, CDS simple types, types
"that are declared in the public visibility section of classes/interfaces,
"etc.. As shown further down, there are released table types with elementary
"line types.
DATA it28 TYPE TABLE OF i.
DATA it29 TYPE TABLE OF string WITH EMPTY KEY.
DATA it30 TYPE TABLE OF xstring WITH EMPTY KEY.
DATA it31 TYPE TABLE OF utclong WITH EMPTY KEY.
"------ Internal tables declared using elementary line types ------
"Note: In this case, the whole table line is the standard table key.
"Elementary built-in ABAP types
DATA it_elem_1 TYPE TABLE OF i.
DATA it_elem_2 TYPE TABLE OF string WITH EMPTY KEY.
DATA it_elem_3 TYPE TABLE OF xstring WITH EMPTY KEY.
DATA it_elem_4 TYPE TABLE OF utclong WITH EMPTY KEY.
"Note: As described above, the table key can consist of components of the
"line type or of the entire line using the pseudo component table_line. In
"case of elementary line types, table_line is the only option to refer to the
"component/entire line.
DATA it_elem_5 TYPE SORTED TABLE OF string WITH NON-UNIQUE KEY table_line.
"Locally declared elementary types
TYPES ty_c3 TYPE c LENGTH 3.
DATA it_elem_6 TYPE TABLE OF ty_c3 WITH EMPTY KEY.
"Apart from the globally available elementary built-in ABAP types, you can
"also use elementary types from the DDIC such as data elements that are
"visible anywhere. You can also refer to CDS simple types that
"constitute elemenary data types.
DATA it_elem_7 TYPE TABLE OF timestamp WITH EMPTY KEY.
DATA it_elem_8 TYPE TABLE OF timestampl WITH EMPTY KEY.
"Globally available elementary types in the public visibility section of
"classes/interfaces
"Elementary type declared in an interface
DATA it32 TYPE TABLE OF zdemo_abap_get_data_itf=>occ_rate WITH EMPTY KEY.
"Using a DDIC data element
DATA it_dtel TYPE TABLE OF timestamp WITH EMPTY KEY.
DATA it_elem_9 TYPE TABLE OF zdemo_abap_get_data_itf=>occ_rate WITH EMPTY KEY.
"Note the syntax options when referring to components. In the following
"example, a database table field is referred to using the database table name,
"the component selector and the name of a field having an elementary data type.
DATA it_elem_10 TYPE TABLE OF zdemo_abap_fli-carrid WITH EMPTY KEY.
"CDS view entity component
DATA it_elem_11 TYPE TABLE OF zdemo_abap_carr_ve-url WITH EMPTY KEY.
```
</td>
@@ -484,16 +512,32 @@ DATA it_dtel TYPE TABLE OF timestamp WITH EMPTY KEY.
``` abap
"Apart from the line type of a database table, these types can also
"be local structured types (as shown below), local structured types declared
"in the public visibility section of classes/interfaces, DDIC structures, CDS
"entities, etc.
"------ Internal tables declared using structured types ------
"CDS view entity
DATA it33 TYPE TABLE OF zdemo_abap_carr_ve WITH EMPTY KEY.
"Locally declared structured type
TYPES: BEGIN OF local_struct,
comp1 TYPE i,
comp2 TYPE string,
comp3 TYPE c LENGTH 3,
END OF local_struct.
DATA it_struc_1 TYPE SORTED TABLE OF local_struct WITH UNIQUE KEY comp1.
"Globally available structured types
"E.g. DDIC database tables
DATA it_struc_2 TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY.
"CDS objects such as ...
"CDS view entity component
DATA it_struc_3 TYPE TABLE OF zdemo_abap_carr_ve WITH EMPTY KEY.
"CDS abstract entity
DATA it34 TYPE TABLE OF zdemo_abap_abstract_ent WITH EMPTY KEY.
DATA it_struc_4 TYPE TABLE OF zdemo_abap_abstract_ent WITH EMPTY KEY.
"CDS table function
DATA it_struc_5 TYPE TABLE OF zdemo_abap_table_function WITH EMPTY KEY.
"Globally available structured types in the public visibility section of
"classes/interfaces
DATA it_struc_6 TYPE TABLE OF zcl_demo_abap_amdp=>fli_struc WITH EMPTY KEY.
```
</td>
@@ -504,41 +548,54 @@ DATA it34 TYPE TABLE OF zdemo_abap_abstract_ent WITH EMPTY KEY.
``` abap
"As shown above, the table types can be locally declared.
DATA it35 TYPE TABLE OF zdemo_abap_get_data_itf=>carr_tab.
"Global table type declared in an interface
DATA it36 TYPE zdemo_abap_get_data_itf=>carr_tab.
"------ Internal tables declared using table types ------
"The following examples use globally available and released table
"types with elementary lines types.
DATA it37 TYPE string_table.
DATA it38 TYPE string_hashed_table.
DATA it39 TYPE xstring_table.
```
"Locally declared table type (based on a locally declared structured type)
TYPES: BEGIN OF loc_struct,
comp1 TYPE i,
comp2 TYPE string,
comp3 TYPE c LENGTH 3,
END OF loc_struct,
ty_tab_1 TYPE TABLE OF loc_struct WITH EMPTY KEY.
</td>
</tr>
<tr>
<td> Deep internal tables </td>
<td>
DATA it_tab_1 TYPE ty_tab_1.
"Locally declared table type (based on a globally available structured type)
TYPES ty_tab_2 TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY.
DATA it_tab_2 TYPE ty_tab_2.
``` abap
"The previous examples mostly demonstrate flat line types.
"Globally available table types
"The following examples show released table types. They have an
"elementary line type.
DATA it_tab_3 TYPE string_table.
DATA it_tab_4 TYPE string_hashed_table.
DATA it_tab_5 TYPE xstring_table.
"Globally available table types in the public visibility section of
"classes/interfaces
DATA it_tab_6 TYPE zdemo_abap_get_data_itf=>carr_tab.
DATA it_tab_7 TYPE zcl_demo_abap_amdp=>flsch_tab.
"Excursion
"Creating an internal table based on the table type of an existing
"internal table
DATA it_tab_8 LIKE it_tab_7.
"Many of the previous examples demonstrate flat line types.
"Deep line types are also possible, that is, the line type
"can include components such as strings, references, structures,
"and internal tables.
TYPES: BEGIN OF ls_deep,
key_field TYPE i,
char TYPE c LENGTH 10,
str TYPE string,
dref TYPE REF TO i,
struct TYPE zdemo_abap_flsch,
str_tab TYPE string_table,
tab TYPE TABLE OF zdemo_abap_flsch WITH EMPTY KEY,
END OF ls_deep.
"can include components such as strings, references, and internal
"tables.
TYPES: BEGIN OF loc_deep_struct,
key_field TYPE i,
char TYPE c LENGTH 10,
str TYPE string,
dref TYPE REF TO i,
struct TYPE zdemo_abap_flsch,
str_tab TYPE string_table,
tab TYPE TABLE OF zdemo_abap_flsch WITH EMPTY KEY,
END OF loc_deep_struct.
DATA it40 TYPE TABLE OF ls_deep WITH EMPTY KEY.
DATA it_tab_9 TYPE TABLE OF loc_deep_struct WITH EMPTY KEY.
```
</td>
@@ -549,7 +606,20 @@ DATA it40 TYPE TABLE OF ls_deep WITH EMPTY KEY.
``` abap
DATA it_ref TYPE TABLE OF REF TO i.
DATA it_ref_1 TYPE TABLE OF REF TO i.
DATA it_ref_2 TYPE TABLE OF REF TO string.
"Generic type data
DATA it_ref_3 TYPE TABLE OF REF TO data.
"Such a table can hold any data type
"For more details on generic types, see the Data Types and Data Objects
"and Dynamic Programming cheat sheets.
it_ref_3 = VALUE #( ( NEW i( 3 ) ) "Elementary type
( NEW string( `hello` ) ) "Elementary type
( NEW zdemo_abap_flsch( carrid = 'XY' connid = '1234' ) ) "Structured type
( NEW string_table( ( `a` ) ( `b` ) ( `c` ) ) ) "Table type
).
```
</td>
@@ -623,6 +693,9 @@ TYPES: BEGIN OF demo_struc,
"Internal table with structured line type and empty key.
CREATE DATA dataref TYPE TABLE OF ('DEMO_STRUC') WITH EMPTY KEY.
"Using a globally available table type
CREATE DATA dataref TYPE ('STRING_TABLE').
```
<p align="right"><a href="#top">⬆️ back to top</a></p>
@@ -1517,10 +1590,10 @@ the `TRANSPORTING` addition to restrict the fields to be copied).
<table>
<tr>
<td> Subject </td> <td> Details/Code Snippet </td>
<td> Statement </td> <td> Details/Code Snippet </td>
</tr>
<tr>
<td> Using <code>READ TABLE</code> statements </td>
<td> <code>READ TABLE</code> </td>
<td>
The following example shows `READ TABLE` statements to read a single line from an internal table by specifying the index. You can use the addition `USING KEY` to specify a table key and thus explicitly determine the table index to use. If the table has a sorted secondary
@@ -1548,7 +1621,7 @@ READ TABLE itab INTO wa INDEX i USING KEY sec_key.
</tr>
<tr>
<td> Using table expressions </td>
<td> Table expressions </td>
<td>
Using [table
@@ -1612,7 +1685,17 @@ DATA(line3) = VALUE #( itab[ 8 ] DEFAULT VALUE #( ) ).
### Reading Single Lines Using Table Keys
Lines can be read by explicitly specifying the table keys or the alias names, if any.
```abap
<table>
<tr>
<td> Statement </td> <td> Details/Code Snippet </td>
</tr>
<tr>
<td> <code>READ TABLE</code> </td>
<td>
``` abap
"Example internal table with primary and secondary table key and alias names
"Assumption: All components are of type i
@@ -1620,24 +1703,6 @@ DATA it TYPE SORTED TABLE OF struc
WITH NON-UNIQUE KEY primary_key ALIAS pk COMPONENTS a b
WITH NON-UNIQUE SORTED KEY sec_key ALIAS sk COMPONENTS c d.
"Table expressions
"Key must be fully specified
line = it[ KEY primary_key COMPONENTS a = 1 b = 2 ].
"The addition COMPONENTS is optional; same as above
line = it[ KEY primary_key a = 1 b = 2 ].
"Primary key alias
line = it[ KEY pk a = 1 b = 2 ].
"Secondary table key
line = it[ KEY sec_key c = 3 d = 4 ].
"Secondary table key alias
line = it[ KEY sk c = 3 d = 4 ].
"READ TABLE statements
"Primary table key
READ TABLE it INTO wa WITH TABLE KEY primary_key COMPONENTS a = 1 b = 2.
@@ -1669,19 +1734,77 @@ READ TABLE it FROM sec_keys USING KEY sec_key INTO wa.
READ TABLE it FROM sec_keys USING KEY sk INTO wa.
```
</td>
</tr>
<tr>
<td> Table expressions </td>
<td>
``` abap
"Key must be fully specified
line = it[ KEY primary_key COMPONENTS a = 1 b = 2 ].
"The addition COMPONENTS is optional; same as above
line = it[ KEY primary_key a = 1 b = 2 ].
"Primary key alias
line = it[ KEY pk a = 1 b = 2 ].
"Secondary table key
line = it[ KEY sec_key c = 3 d = 4 ].
"Secondary table key alias
line = it[ KEY sk c = 3 d = 4 ].
```
</td>
</tr>
</table>
<p align="right"><a href="#top">⬆️ back to top</a></p>
### Reading Single Lines Using a Free Key
The specified components used as keys need not be part of a table key.
``` abap
line = it[ b = 2 ].
<table>
<tr>
<td> Statement </td> <td> Details/Code Snippet </td>
</tr>
<tr>
<td> <code>READ TABLE</code> </td>
<td>
``` abap
"Note: Table keys are specified with the ... WITH TABLE KEY ... addition,
"free keys with ... WITH KEY ....
READ TABLE it INTO wa WITH KEY b = 2.
```
</td>
</tr>
<tr>
<td> Table expressions </td>
<td>
``` abap
line = it[ b = 2 ].
```
</td>
</tr>
</table>
<p align="right"><a href="#top">⬆️ back to top</a></p>
### Examples of Addressing Individual Components of Read Lines
@@ -3264,46 +3387,117 @@ As mentioned above, you can modify the content of internal table lines directly
The following examples demonstrate direct modification of recently read table lines:
``` abap
"Table declarations
"Declaring and populating demo internal tables
TYPES: BEGIN OF ty_struc,
comp1 TYPE i,
comp2 TYPE string,
comp3 TYPE c LENGTH 3,
END OF ty_struc.
DATA it_st TYPE TABLE OF struc WITH NON-UNIQUE KEY a.
DATA it_st TYPE TABLE OF ty_struc WITH NON-UNIQUE KEY comp1.
DATA it_so TYPE SORTED TABLE OF ty_struc WITH UNIQUE KEY comp1.
DATA it_ha TYPE HASHED TABLE OF ty_struc WITH UNIQUE KEY comp1.
DATA it_so TYPE SORTED TABLE OF struc WITH UNIQUE KEY a.
it_st = VALUE #( ( comp1 = 1 comp2 = `AAAAAA` comp3 = 'bbb' )
( comp1 = 2 comp2 = `CCCCCC` comp3 = 'ddd' )
( comp1 = 3 comp2 = `EEEEEE` comp3 = 'fff' )
( comp1 = 4 comp2 = `GGGGGG` comp3 = 'hhh' )
).
"Reading table line into target area
it_so = it_st.
it_ha = it_st.
READ TABLE it_st ASSIGNING FIELD-SYMBOL(<fs>) INDEX 1.
"---- Modifying internal table content by changing the ----
"---- content of READ TABLE statement target areas --------
"Reading table line into a target area
READ TABLE it_st INTO DATA(wa) INDEX 1.
READ TABLE it_so ASSIGNING FIELD-SYMBOL(<fs>) INDEX 2.
READ TABLE it_ha REFERENCE INTO DATA(dref) WITH TABLE KEY comp1 = 3. "No reading by index in case of hashed tables
READ TABLE it_so REFERENCE INTO DATA(dref) INDEX 2.
"------ Modification examples -------
"Modifying all non-key components using the VALUE operator and
"the BASE addition
<fs> = VALUE #( BASE <fs> comp2 = `IIIIII` comp3 = 'jjj' ).
"Modification examples
"Modifying the entire table line while keeping the values of other components;
"this way is not possible for it_so because of key value change.
"In the following example, the key value is assigned a new
"value. Key values are protected against change in case of key tables.
"A runtime error occurs.
"<fs> = VALUE #( comp1 = 5 comp2 = `IIIIII` comp3 = 'jjj' ).
<fs> = VALUE #( BASE <fs> a = 1 b = 2 ).
dref->* = VALUE #( BASE dref->* comp2 = `KKKKKK` comp3 = 'lll' ).
"Modifying a single component via field symbol
"Same as above. Key values cannot be changed in this case.
"dref->* = VALUE #( comp1 = 5 comp2 = `MMMMMM` comp3 = 'nnn' ).
<fs>-c = 3.
"Using a MODIFY statement outlined below for changing internal
"table content based on a read line in a work area
MODIFY TABLE it_st FROM VALUE #( BASE wa comp2 = `OOOOOO` comp3 = 'ppp' ).
"Modification via dereferencing
"Modifying individual components
READ TABLE it_st INTO wa INDEX 2.
READ TABLE it_so ASSIGNING <fs> INDEX 3.
READ TABLE it_ha REFERENCE INTO dref WITH TABLE KEY comp1 = 4.
dref->b = 4.
"Using VALUE/BASE
<fs> = VALUE #( BASE <fs> comp2 = `QQQQQQ` ).
dref->* = VALUE #( BASE dref->* comp2 = `RRRRRR` ).
MODIFY TABLE it_st FROM VALUE #( BASE wa comp2 = `SSSSSS` ).
"Table expressions
"Using the component selector
<fs>-comp3 = 'ttt'.
it_st[ 1 ] = VALUE #( a = 1 b = 2 ).
READ TABLE it_st INTO wa INDEX 3.
wa-comp3 = 'uuu'.
MODIFY TABLE it_st FROM wa.
it_st[ 2 ]-c = 3.
"Object component selector in case of dereferencing ...
dref->comp2 = `VVVVVV`.
"... which is a more comfortable option compared to using the
"dereferencing and component selector operators in the following way.
dref->*-comp3 = 'www'.
"Sorted table: no key field change
"---- Modifying internal table content using table expressions -----
it_so[ 2 ]-d = 4.
"Changing the entire table line of a standard table
"In standard tables, the key value change is allowed.
it_st[ 3 ] = VALUE #( comp1 = 9 comp2 = `XXXXXX` comp3 = 'yyy' ).
"As above, the sorted table is a key table having a unique key,
"therefore a write cannot be performed on the entire entry. Runtime
"errors can occur.
"it_so[ 3 ] = VALUE #( comp2 = `XXXXXX` comp3 = 'yyy' ).
"The same applies to hashed tables.
"it_ha[ comp2 = `OOOOOO` ] = VALUE #( comp2 = `XXXXXX` comp3 = 'yyy' ).
"Changing individual components
it_st[ 3 ]-comp2 = `ZZZZZZ`.
it_so[ 3 ]-comp3 = 'A1'.
it_ha[ comp2 = `CCCCCC` ]-comp2 = `B2`.
"As above, no key field change in key tables. Allowed in standard
"tables.
"it_so[ 3 ]-comp1 = 10.
"it_ha[ comp2 = `AAAAAA` ]-comp1 = `C3`.
it_st[ 1 ]-comp1 = 99.
"---- Modifying table content in all table rows in a loop ----
"For more syntax options regarding loops, check the section above.
"Target area: field symbol
LOOP AT it_st ASSIGNING FIELD-SYMBOL(<lo>).
<lo>-comp2 = sy-tabix.
ENDLOOP.
"---- Modifying table content restricting the rows that are looped across ----
"Target area: data reference variable
LOOP AT it_st reference into data(lo) FROM 2 TO 3.
lo->comp3 = sy-tabix.
ENDLOOP.
"Target area: work area
LOOP AT it_so into data(wa_lo) where comp1 < 4.
wa_lo-comp2 = sy-tabix.
MODIFY TABLE it_so FROM wa_lo.
ENDLOOP.
```
> **💡 Note**<br>
> If you want to modify recently read lines in a work area, for example, within a loop (`LOOP AT INTO dobj`), you can modify the line and then use a `MODIFY` statement to modify the internal table based on this line.
[`MODIFY`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmodify_itab.htm)
statements provide multiple ways of changing the content of single and multiple table lines by specifying the table key or a table index,
without first reading the lines into a target area.
@@ -3706,6 +3900,51 @@ ENDCLASS.
<p align="right"><a href="#top">⬆️ back to top</a></p>
## Collecting Calues
- You can use `COLLECT` statements, for example, to add the values of numeric components to the corresponding values in an internal table.
- It is recommended that you use it mainly for internal tables with a unique primary key, especially hashed tables.
- Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcollect.htm)
``` abap
"This example demonstrates how to insert data from a database table
"into an internal table in a compressed way. Within a SELECT loop,
"a COLLECT statement is used to consolidate lines with identical
"primary key components (carrid and connid) by summing the number
"of occupied seats in the numeric component (seatsocc).
"Additionally, an internal table is filled by adding all read lines.
"This table is looped across to simulate the effect of the COLLECT
"statement.
DATA: BEGIN OF seats,
carrid TYPE zdemo_abap_fli-carrid,
connid TYPE zdemo_abap_fli-connid,
seatsocc TYPE zdemo_abap_fli-seatsocc,
END OF seats,
seats_tab_col LIKE HASHED TABLE OF seats WITH UNIQUE KEY carrid connid,
seats_tab_all LIKE TABLE OF seats WITH EMPTY KEY,
seats_tab_loop_grp LIKE seats_tab_col.
SELECT carrid, connid, seatsocc
FROM zdemo_abap_fli
INTO @seats.
COLLECT seats INTO seats_tab_col.
APPEND seats TO seats_tab_all.
ENDSELECT.
LOOP AT seats_tab_all INTO DATA(wa) GROUP BY ( key1 = wa-carrid key2 = wa-connid ).
INSERT VALUE #( carrid = wa-carrid connid = wa-connid ) INTO TABLE seats_tab_loop_grp ASSIGNING FIELD-SYMBOL(<fs>).
LOOP AT GROUP wa INTO DATA(member).
<fs>-seatsocc = <fs>-seatsocc + member-seatsocc.
ENDLOOP.
ENDLOOP.
ASSERT seats_tab_loop_grp = seats_tab_col.
```
<p align="right"><a href="#top">⬆️ back to top</a></p>
## Excursions
### Improving Read Performance with Secondary Table Keys

View File

@@ -4,7 +4,13 @@
- [Structures](#structures)
- [Introduction](#introduction)
- [Globally Available Structures and Structured Types](#globally-available-structures-and-structured-types)
- [Creating Structures and Structured Types](#creating-structures-and-structured-types)
- [Creating Structured Types](#creating-structured-types)
- [Creating Structures](#creating-structures)
- [Creating Structures Using Existing Structured Types](#creating-structures-using-existing-structured-types)
- [Creating Structures by Inline Declaration](#creating-structures-by-inline-declaration)
- [Creating Anonymous Structures](#creating-anonymous-structures)
- [Variants of Structures](#variants-of-structures)
- [Accessing (Components of) Structures](#accessing-components-of-structures)
- [Populating Structures](#populating-structures)
@@ -25,22 +31,48 @@ Structures ...
- consist of a sequence of [components](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencomponent_glosry.htm "Glossary Entry") of any data type, that is, the components of a structure can be, for example, [elementary data objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenelementary_data_object_glosry.htm), structures themselves, [internal tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninternal_table_glosry.htm "Glossary Entry") or [references](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreference_glosry.htm).
- are used to combine different data objects that belong together. A typical example is an address. It has several components, such as name, street, city, and so on, that belong together.
- play an important role in the context of internal tables and [database tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendatabase_table_glosry.htm "Glossary Entry"). Structured types serve as [line types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrow_type_glosry.htm) for these tables. Most internal tables across [ABAP programs](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_program_glosry.htm) may have structured line types. For database tables, there is no alternative to structured line types.
- can be created locally in an ABAP program. You can also create them as global [DDIC structures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_structure_glosry.htm) in the [ABAP Dictionary](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_dictionary_glosry.htm). Such a DDIC structure defines a globally available structured type ([DDIC type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_type_glosry.htm)).
- Note: There are other structured types available globally, which may be the structured types most commonly used in ABAP programs:
- [Database tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_db_table_glosry.htm) defined in the ABAP Dictionary can be used as data types just like DDIC structures in an ABAP program. This means that when you create a structure in your ABAP program, for example, you can simply use the name of a database table to address the line type of the table. The structure you created will then have the same structured type as the database table. Typically, you use the database tables to create structures of such a type, or internal tables of such a structured line type, to process data read from the database table in structures or internal tables.
- A [CDS entity](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_glosry.htm) such as a [CDS view](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_view_glosry.htm) also represents a structured data type and can be used as such in ABAP programs (but not in the ABAP Dictionary). The same applies to [DDIC views](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_view_glosry.htm) that are only available in [Standard ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_abap_glosry.htm).
- Structures and structured data types can also be defined in the public [visibility section](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenvisibility_section_glosry.htm) of [global classes](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenglobal_class_glosry.htm) or in [global interfaces](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenglobal_interface_glosry.htm) and then used globally.
- can be created locally in an ABAP program and globally. This cheat sheet focuses on locally defined structures and structured types.
<p align="right"><a href="#top">⬆️ back to top</a></p>
## Globally Available Structures and Structured Types
- Apart from the local declaration of a structured type, you can create such a type, for example, as global [DDIC structure](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_structure_glosry.htm) in the [ABAP Dictionary](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_dictionary_glosry.htm). Such a DDIC structure defines a globally available structured type ([DDIC type](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_type_glosry.htm)).
- There are other structured types available globally, which may be the structured types most commonly used in ABAP programs:
- [Database tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_db_table_glosry.htm) defined in the ABAP Dictionary can be used as data types just like DDIC structures in an ABAP program. This means that when you create a structure in your ABAP program, for example, you can simply use the name of a database table to address the line type of the table. The structure you created will then have the same structured type as the database table. Typically, you use the database tables to create structures of such a type, or internal tables of such a structured line type, to process data read from the database table in structures or internal tables.
- Various [CDS entities](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_entity_glosry.htm) are globally available structured types. For example, a [CDS view entity](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_v2_view_glosry.htm) represents a structured data type and can be used as such in ABAP programs (but not in the ABAP Dictionary).
- Structures and structured data types can be defined in the public [visibility section](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenvisibility_section_glosry.htm) of [global classes](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenglobal_class_glosry.htm) or in [global interfaces](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenglobal_interface_glosry.htm) and then used globally.
```abap
"Creating structures based on globally available structured types
"Database table
DATA struc_from_dbtab TYPE zdemo_abap_fli.
"CDS view entity
DATA struc_from_cds_ve TYPE zdemo_abap_fli.
"CDS abstract entity
DATA struc_from_cds_abs TYPE zdemo_abap_abstract_ent.
"CDS table function
DATA struc_from_cds_tab_func TYPE zdemo_abap_table_function.
"Globally available structured type in the public visibility section of
"classes/interfaces
DATA struc_from_struc_type_in_cl TYPE zcl_demo_abap_amdp=>fli_struc.
"Creating structured types based on globally available structured types
TYPES ty_struc_from_dbtab TYPE zdemo_abap_fli.
TYPES ty_struc_from_cds_ve TYPE zdemo_abap_fli.
```
> **💡 Note**<br>
> - This cheat sheet focuses on locally defined structures and structured types.
> - Classic [DDIC views](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_view_glosry.htm) are not available in [ABAP Cloud](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_cloud_glosry.htm). They can only be used as structured types in [classic ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclassic_abap_glosry.htm).
## Creating Structures and Structured Types
The typical language elements for creating structures and structured types locally in an ABAP program are [`BEGIN OF ... END OF ...`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaptypes_struc.htm). They are used in combination with the [`TYPES`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abaptypes.htm) keyword to create a structured type and the [`DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdata.htm) keyword to create a structure.
> **💡 Note**<br>
> This cheat sheet focuses on locally defined structures and structured types.
**Creating structured types**
### Creating Structured Types
- The following statement defines a structured type introduced by `TYPES`. The type name is preceded by `BEGIN OF` (which marks the beginning of the structured type definition) and `END OF` (the end of the definition).
- The components - at least one must be defined - are listed in between.
@@ -95,9 +127,9 @@ TYPES: BEGIN OF struc_type,
> Outside of classes, you can also refer to DDIC types using `LIKE` (`... comp11 LIKE ddic_type, ...`). If you actually want to refer to an existing data object, but due to typing errors you inadvertently specify a name that exists as DDIC type, errors may be unavoidable.
**Creating structures**
### Creating Structures
- To create a structure in an ABAP program, you can use the `DATA` keyword.
- To create a structure (i.e. a structured data object) in an ABAP program, you can use the `DATA` keyword.
- It works in the same way as the `TYPES` statement above.
- Unlike the `TYPES` statement, you can use the [`VALUE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapdata_options.htm) addition to set default values.
@@ -127,7 +159,7 @@ DATA END OF struc.
>- The keywords [`CLASS-DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapclass-data.htm) and [`CONSTANTS`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapconstants.htm) can also be used to create structures. In principle, they represent special cases of the general statement shown above. See the ABAP Keyword Documentation for more information.
>- Structures can also be created [inline](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninline_declaration_glosry.htm) using [`DATA(...)`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abendata_inline.htm) or [`FINAL(...)`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfinal_inline.htm), as shown below.
**Creating structures using existing structured types**
### Creating Structures Using Existing Structured Types
``` abap
"Local structured type
@@ -156,7 +188,7 @@ DATA: struc_6 LIKE struc_1,
```
**Creating structures by inline declaration**
### Creating Structures by Inline Declaration
- This is particularly useful for declaring data objects at the [operand positions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenoperand_position_glosry.htm) where you actually need them.
- In this way, you can avoid an extra declaration of the structure in different contexts.
@@ -214,7 +246,7 @@ LOOP AT itab INTO DATA(wa_2).
ENDLOOP.
```
**Anonymous Structures**
### Creating Anonymous Structures
Using the instance operator [`NEW`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expression_new.htm) and [`CREATE DATA`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcreate_data.htm) statements, you can create [anonymous data objects](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenanonymous_data_object_glosry.htm "Glossary Entry"), such as anonymous structures.
The `NEW` addition of the `INTO` clause of an ABAP SQL `SELECT` statement also creates an anonymous data object.

View File

@@ -74,7 +74,7 @@
- In general, dynamic programming also comes with some downsides. For example:
- The ABAP compiler cannot check the dynamic programming feature like the `SELECT` statement mentioned above. There is no syntax warning or suchlike.
- The checks are performed only at runtime, which has an impact on the performance.
- The testing of [procedure](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenprocedure_glosry.htm "Glossary Entry") that include dynamic programming features may be difficult.
- The testing of [procedures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenprocedure_glosry.htm "Glossary Entry") that include dynamic programming features may be difficult.
- Including external input in dynamic ABAP SQL statements without an appropriate handling, there can be potential security risks. You can, for example, use the `CL_ABAP_DYN_PRG` class to manage security risks.
@@ -182,7 +182,7 @@ ASSIGN num TO FIELD-SYMBOL(<fs_inl>).
"symbol when assigning memory areas
TYPES c_len_3 TYPE c LENGTH 3.
DATA(chars) = 'abcdefg'.
table_linebetween
FIELD-SYMBOLS <fs1> TYPE c_len_3.
"Implicit casting

View File

@@ -10,6 +10,7 @@
- [RAP Saver Class and Saver Methods](#rap-saver-class-and-saver-methods)
- [BDEF Derived Types](#bdef-derived-types)
- [Components of BDEF Derived Types](#components-of-bdef-derived-types)
- [Constants for BDEF Derived Type Components](#constants-for-bdef-derived-type-components)
- [Secondary Table Keys of BDEF Derived Types](#secondary-table-keys-of-bdef-derived-types)
- [Type Mapping for RAP](#type-mapping-for-rap)
- [RAP-Specific Additions to the CORRESPONDING Operator](#rap-specific-additions-to-the-corresponding-operator)
@@ -865,6 +866,22 @@ Bullet points on selected `%` components:
`if_abap_behv=>mk-off`, the values of these fields
are not returned in the result.
<p align="right"><a href="#top">⬆️ back to top</a></p>
### Constants for BDEF Derived Type Components
Several BDEF derived types contain `%` components, which have a specific type and represent flags. The mentioned `%control` structure of type `ABP_BEHV_FLAG` is such a component. When assigning values to these components, ensure you use appropriate values. The `IF_ABAP_BEHV` interface provides a range of structured constants for this purpose. Although these constants are technically identical, it is recommended that you use them in the right context.
| Type | Structured Constant | Details |
| -------- | ------- | ------- |
| ABP_BEHV_FLAG | IF_ABAP_BEHV=>MK | Marks and unmarks fields in ABAP EML modify and read operations, such as in %control and %element. |
| ABP_BEHV_FIELD_PERM | IF_ABAP_BEHV=>PERM-F | Used in the context of field permission results, such as a field marked as mandatory or read-only. |
| ABP_BEHV_OP_PERM | IF_ABAP_BEHV=>PERM-O | For operation permission results, such as a delete operation that is marked as enabled. |
| ABP_BEHV_FIELD_CTRL | IF_ABAP_BEHV=>FC-F | For field feature control results, such as a field marked with no restrictions. |
| ABP_BEHV_OP_CTRL | IF_ABAP_BEHV=>FC-O | For operation feature control results, such as a disabled update operation. |
| ABP_BEHV_AUTH | IF_ABAP_BEHV=>AUTH | For authorization results, such as an unauthorized operation. |
<p align="right"><a href="#top">⬆️ back to top</a></p>
### Secondary Table Keys of BDEF Derived Types
@@ -875,7 +892,8 @@ Bullet points on selected `%` components:
- `entity`: Includes `%key`
- `cid`: Includes `%cid` or `%cid_ref`, and can - depending on the type - also include `%key` and `%pid`
- `draft`: Available in draft scenarios; includes `%is_draft`; can also include `%key` and `%pid`
- `pid` (alias name `id`): Available in late numbering scenarios; includes `%pid`; can also include `%tmp` and `%key`
- `pid`: Available in late numbering scenarios; includes `%pid`; can also include `%tmp` and `%key`
- The [alias name](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenalias_glosry.htm) `id` is available for either `entity`, `draft`, or `pid` depending on the context. Check the F2 information in ADT for the respective types.
```abap
DATA itab_cr TYPE TABLE FOR CREATE zdemo_abap_rap_ro_m.

View File

@@ -57,15 +57,7 @@ It provides references to more detailed information on the topic.
![Release contract](./files/release_contract.png)
For deprecated and invalid syntax in ABAP for Cloud Development, refer to the following example code. You can create a demo class and insert the code below (adjust the class name if necessary). Several syntax errors and warnings will be displayed:
- ABAP SQL statements
- The first two ABAP SQL statements select from demo database tables. The first one is a demo table provided by SAP, but it cannot be accessed directly in the case of ABAP for Cloud Development like in the case of Standard ABAP. Therefore, it cannot be used as a data source for selection.
- The second one is a database table from the ABAP cheat sheet GitHub repository. If you have imported the repository into the system, you can use it as a data source.
- The CDS view is released and can be accessed in the restricted ABAP language scope.
- Although the source code provides an invalid data source, the dynamic ABAP SQL statement does not produce a syntax error during compilation. However, it would result in a runtime error because you cannot select from that data source. You can check the validity of dynamic specifications using the `cl_abap_dyn_prg` class, which supports dynamic programming.
- The addition `USING CLIENT` for client handling is not allowed in the restricted ABAP language scope.
- When using APIs and types like `string_table`, ensure that they are released. The `IF_OO_ADT_CLASSRUN` interface is released, and you can implement it to run an ABAP class. In ADT, you can do this by choosing *F9*. However, the example class will not run because the class cannot be activated due to the syntax errors. To output the content of data objects, you can use `out->write( ... )` in the `main` method.
- The example includes a selection of deprecated and invalid syntax in ABAP for Cloud Development. It includes the invalid statement `MOVE ... TO` and others that are added for demonstration purposes (some alternatives are provided). Certain system fields should not be accessed. The pointless `WRITE` statement within the method implementation represents invalid classic ABAP UI-related statements. Executable programs (*reports*) are not allowed in the restricted ABAP language scope. To set breakpoints in ADT, double-click the area to the left of the code line number.
For deprecated and invalid syntax in ABAP for Cloud Development, refer to the following (nonsensical) example code. You can create a demo class and insert the code below (adjust the class name if necessary). Several syntax errors and warnings will be displayed:
```abap
CLASS zcl_some_class DEFINITION
@@ -79,39 +71,87 @@ It provides references to more detailed information on the topic.
CLASS zcl_some_class IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
"ABAP SQL statements
"Using database tables and CDS views as data sources
SELECT carrid, connid FROM spfli WHERE carrid = 'LH' INTO TABLE @DATA(it1).
SELECT carrid, connid FROM zdemo_abap_fli WHERE carrid = 'LH' INTO TABLE @DATA(it2).
SELECT SINGLE * FROM i_timezone WHERE TimeZoneID = 'EST' INTO @DATA(tz_info).
"Dynamic ABAP SQL statements
SELECT SINGLE carrid, connid FROM ('SPFLI') WHERE carrid = 'LH' INTO NEW @DATA(ref_a).
SELECT SINGLE carrid, connid FROM ('ZDEMO_ABAP_FLI') WHERE carrid = 'LH' INTO NEW @DATA(ref_b).
"ABAP SQL Statement involving client handling
DATA(clnt) = sy-mandt.
SELECT carrid, connid FROM zdemo_abap_fli USING CLIENT @clnt WHERE carrid = 'LH' INTO TABLE @DATA(it3).
"Example that demonstrates (not) released APIs, deprecated and
"invalid syntax in ABAP for Cloud Development
"(Not) released APIs
"Released API: Getting a random integer
"Released DDIC data elements
DATA dobj1 TYPE timestampl.
DATA dobj2 TYPE land1.
"Attributes of the accessible type pool ABAP
DATA flag TYPE abap_boolean.
flag = abap_true.
"Released table types
DATA it1 TYPE string_table.
DATA it2 TYPE string_hashed_table.
DATA it3 TYPE xstring_table.
"Released CDS object
DATA s1 TYPE i_timezone.
"Released interface
"The if_oo_adt_classrun interface is released, and you can implement it to run an ABAP class.
"In ADT, you can do this by choosing F9. To output the content of data objects, you can use
"out->write( ... ). in the main method.
DATA ref_classrun TYPE REF TO if_oo_adt_classrun.
"Not released DDIC database table
DATA s2 TYPE scarr.
"Classes
"(Not) Released classes
DATA(ixml1) = cl_ixml_core=>create( ).
"Not released (API for classic ABAP)
DATA(ixml2) = cl_ixml=>create( ).
"Getting a random integer
DATA(random_num) = cl_abap_random_int=>create( seed = cl_abap_random=>seed( )
min = 1
max = 100 )->get_next( ).
min = 1
max = 100 )->get_next( ).
"Released APIs from the XCO library
"Retrieving the current user date
DATA(user_date) = xco_cp=>sy->date( xco_cp_time=>time_zone->user
)->as( xco_cp_time=>format->iso_8601_extended
)->value.
DATA(user_date) = xco_cp=>sy->date( xco_cp_time=>time_zone->user
)->as( xco_cp_time=>format->iso_8601_extended
)->value.
"Retrieving the current user time
DATA(user_time) = xco_cp=>sy->time( xco_cp_time=>time_zone->user
)->as( xco_cp_time=>format->iso_8601_extended
)->value.
)->as( xco_cp_time=>format->iso_8601_extended
)->value.
"Not released API: Querying whether the current database supports AMDP methods
DATA(amdp_allowed) = xsdbool( cl_abap_dbfeatures=>use_features(
EXPORTING requested_features = VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ) ).
"Examples for deprecated and invalid syntax in ABAP for Cloud Development
"ABAP SQL statements
"Selecting from a
"... not released database table
SELECT carrid, connid FROM spfli WHERE carrid = 'LH' INTO TABLE @DATA(spfli_tab).
"... released CDS view
SELECT SINGLE * FROM i_timezone WHERE TimeZoneID = 'EST' INTO @DATA(tz_info).
"... not released database table using a dynamic ABAP SQL statement
"Although the source code provides an invalid data source, the dynamic ABAP SQL statement
"does not produce a syntax error during compilation. However, it would result in a runtime
"error because you cannot select from that data source. You can check the validity of dynamic
"specifications using the `cl_abap_dyn_prg` class, which supports dynamic programming.
SELECT SINGLE carrid, connid FROM ('SPFLI') WHERE carrid = 'LH' INTO NEW @DATA(ref_spfli_tab).
"ABAP SQL Statement involving client handling; using a cheat sheet database table
"The addition `USING CLIENT` for client handling is not allowed in the restricted ABAP language scope.
DATA(clnt) = sy-mandt.
SELECT carrid, connid FROM ('ZDEMO_ABAP_FLI') USING CLIENT @clnt WHERE carrid = 'LH' INTO TABLE NEW @DATA(ref_demo_tab).
"The example includes a selection of deprecated and invalid syntax in ABAP for Cloud Development. They are added
"for demonstration purposes. For example, classic UI technology-related (such as dynpro) syntax is not allowed.
"The pointless WRITE statement within the method implementation represents invalid classic list-related statements.
"Executable programs (reports) are not allowed in the restricted ABAP language scope. To set breakpoints in ADT,
"double-click the area to the left of the code line number.
"Assignments
DATA(num1) = 1.
DATA(num2) = 1.
DATA(num3) = 2.
@@ -120,26 +160,37 @@ It provides references to more detailed information on the topic.
"Using the assignment operator
num2 = num3.
DATA(it4) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ).
"Invalid statement for determining the number of lines in an internal table
DESCRIBE TABLE it4 LINES DATA(num_lines1).
DATA(num_lines2) = lines( it4 ).
"Determining the number of lines in an internal table
DATA(str_table) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ).
DATA(num_lines1) = lines( str_table ).
"Invalid statement
DESCRIBE TABLE str_table LINES DATA(num_lines2).
"Getting references
DATA: ref1 TYPE REF TO i,
ref2 TYPE REF TO i.
"Deprecated statement for references
GET REFERENCE OF num1 INTO ref1.
"Using the REF operator instead
ref2 = REF #( num1 ).
ref1 = REF #( num1 ).
"Deprecated statement
GET REFERENCE OF num1 INTO ref2.
"Classic ABAP-related statements and syntax
"Various sy components should not be used in ABAP for Cloud Development
DATA(current_time) = sy-uzeit.
DATA(current_date) = sy-datum.
DATA(current_as_abap_time) = sy-uzeit.
DATA(current_as_abap_date) = sy-datum.
DATA(current_local_time) = sy-timlo.
DATA str_itab TYPE string_table.
"Various invalid statements
READ REPORT 'ZCL_DEMO_ABAP_UNIT_TEST=======CCAU' INTO str_itab.
"Various invalid statements
DATA scarr_tab TYPE TABLE OF scarr WITH EMPTY KEY.
TRY.
cl_salv_table=>factory( IMPORTING r_salv_table = DATA(alv)
CHANGING t_table = scarr_tab ).
"The exception class is not released, too.
CATCH cx_salv_msg.
ENDTRY.
DATA code TYPE string_table.
READ REPORT 'ZCL_DEMO_ABAP_UNIT_TEST=======CCAU' INTO code.
WRITE 'hi'.
BREAK-POINT.
ENDMETHOD.
@@ -156,7 +207,7 @@ It provides references to more detailed information on the topic.
For the example class created, check the information in the *Properties* tab. Choose *General*. The *ABAP Language Version* is maintained as *Standard ABAP*:
![Standard ABAP](./files/standard.png)
- If you have not imported the ABAP cheat sheet GitHub repository, remove the lines of code using artifacts from that repository, i.e. remove the statements using objects starting with `Z...`. You should not see any syntax errors. Activate the class.
- Run the class with *F9*. The code should have been processed up to the `BREAK-POINT` statement and the debugger should have started. You may want to check the content of the variables in the debugger. Choose *Terminate* to exit the debugger.
- Run the class with *F9*. The code should have been processed up to the `BREAK-POINT` statement and the debugger should have started. Choose *Terminate* to exit the debugger.
- So, unlike in the case of ABAP for Cloud Development above, you should be able to activate and run the code (which does not represent a meaningful code example).
c) Verifying cloud-readiness of your code in classic ABAP

View File

@@ -3288,8 +3288,6 @@ cl_abap_unit_assert=>assert_equals(
exp = 100
msg = `The value does not match the expected result`
quit = if_abap_unit_constant=>quit-no ).
ENDDO.
```
</td>

View File

@@ -441,7 +441,7 @@ CLASS zcl_demo_abap_auth IMPLEMENTATION.
IF flag = abap_true.
out->write( `Something went wrong with the example procedure. There should only be entries with the condition countryfr = 'US'.` ).
ELSE.
out->write( `Excepted result. There are only entries with the condition countryfr = 'US' in the internal table.` ).
out->write( `Expected result. There are only entries with the condition countryfr = 'US' in the internal table.` ).
ENDIF.
out->write( |\n| ).
@@ -451,7 +451,7 @@ CLASS zcl_demo_abap_auth IMPLEMENTATION.
out->write( `SELECT statements that specify WHERE clauses:` ).
IF itab3 IS NOT INITIAL AND itab4 IS INITIAL.
out->write( `Excepted result. Only entries with the condition countryfr = 'US' should be accessible.` ).
out->write( `Expected result. Only entries with the condition countryfr = 'US' should be accessible.` ).
ELSE.
out->write( `Something went wrong with the example procedure. There should only be entries with the condition countryfr = 'US'.` ).
ENDIF.