From 1c50246e587e92df0b4e51d926ecf0b5d3422432 Mon Sep 17 00:00:00 2001
From: danrega <16720986+danrega@users.noreply.github.com>
Date: Mon, 6 Nov 2023 16:54:31 +0100
Subject: [PATCH] Update
---
src/zcl_demo_abap_amdp.clas.abap | 31 +-
....clas.abap => zcl_demo_abap_aux.clas.abap} | 16 +-
...ay.clas.xml => zcl_demo_abap_aux.clas.xml} | 4 +-
src/zcl_demo_abap_cds_ve.clas.abap | 102 +-
src/zcl_demo_abap_cloud_excursion.clas.abap | 48 +-
src/zcl_demo_abap_constructor_expr.clas.abap | 381 +-
src/zcl_demo_abap_display.clas.abap | 160 -
src/zcl_demo_abap_dtype_dobj.clas.abap | 264 +-
src/zcl_demo_abap_dtype_dobj.clas.xml | 2 +-
src/zcl_demo_abap_dynamic_prog.clas.abap | 701 ++--
src/zcl_demo_abap_flight_tables.clas.xml | 16 -
src/zcl_demo_abap_internal_tables.clas.abap | 3365 +++++++++--------
src/zcl_demo_abap_objects.clas.abap | 300 +-
src/zcl_demo_abap_prog_flow_logic.clas.abap | 380 +-
src/zcl_demo_abap_rap_draft_ln_m.clas.abap | 158 +-
src/zcl_demo_abap_rap_ext_num_m.clas.abap | 295 +-
src/zcl_demo_abap_rap_ext_num_u.clas.abap | 328 +-
src/zcl_demo_abap_sql.clas.abap | 324 +-
src/zcl_demo_abap_sql_group_by.clas.abap | 54 +-
src/zcl_demo_abap_string_proc.clas.abap | 850 +++--
src/zcl_demo_abap_structures.clas.abap | 278 +-
src/zcl_demo_abap_unit_test.clas.abap | 1006 +++--
22 files changed, 4769 insertions(+), 4294 deletions(-)
rename src/{zcl_demo_abap_flight_tables.clas.abap => zcl_demo_abap_aux.clas.abap} (98%)
rename src/{zcl_demo_abap_display.clas.xml => zcl_demo_abap_aux.clas.xml} (78%)
delete mode 100644 src/zcl_demo_abap_display.clas.abap
delete mode 100644 src/zcl_demo_abap_flight_tables.clas.xml
diff --git a/src/zcl_demo_abap_amdp.clas.abap b/src/zcl_demo_abap_amdp.clas.abap
index 485a660..2076667 100644
--- a/src/zcl_demo_abap_amdp.clas.abap
+++ b/src/zcl_demo_abap_amdp.clas.abap
@@ -13,8 +13,8 @@
* fairly simple. AMDP is not needed in simple cases like these.
* - The example is primarily intended for ABAP Cloud.
* For example, in ABAP Cloud only read-only operations are possible.
-* In general, there are more syntax options available in classic
-* ABAP. Check the ABAP Keyword Documentation for more details and
+* In general, there are more syntax options available in classic
+* ABAP. Check the ABAP Keyword Documentation for more details and
* examples.
*
* ----------------------- GETTING STARTED -----------------------------
@@ -150,12 +150,12 @@ ENDCLASS.
-CLASS zcl_demo_abap_amdp IMPLEMENTATION.
+CLASS ZCL_DEMO_ABAP_AMDP IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
- zcl_demo_abap_flight_tables=>fill_dbtabs( ).
+ zcl_demo_abap_aux=>fill_dbtabs( ).
ENDMETHOD.
@@ -253,11 +253,9 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
- DATA(output) = NEW zcl_demo_abap_display( out ).
+ out->write( `ABAP Cheat Sheet Example: ABAP AMDP` ).
- output->display( `ABAP Cheat Sheet Example: ABAP AMDP` ).
-
- output->display( `1) AMDP procedure` ).
+ out->write( |\n1) AMDP Procedure\n\n| ).
"Declaring an internal table to store the data that are
"returned by the following method.
@@ -272,11 +270,11 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
NEW zcl_demo_abap_amdp( )->select_carriers(
IMPORTING carr_tab = amdp_proc_res ).
- output->display( input = amdp_proc_res name = `amdp_proc_res` ).
+ out->write( data = amdp_proc_res name = `amdp_proc_res` ).
**********************************************************************
- output->next_section( `2) Calling an AMDP Procedure from SQLScript` ).
+ out->write( zcl_demo_abap_aux=>heading( `2) Calling an AMDP Procedure from SQLScript` ) ).
"As can be seen in the method implementation part, this AMDP procedure
"includes an AMDP procedure call from SQLScript.
@@ -290,16 +288,16 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
CATCH cx_amdp_execution_error INTO DATA(error1).
- output->display( error1->get_text( ) ).
+ out->write( error1->get_text( ) ).
ENDTRY.
- output->display( input = call_amdp_res name = `call_amdp_res` ).
+ out->write( data = call_amdp_res name = `call_amdp_res` ).
**********************************************************************
- output->next_section( `3) AMDP Table Function for AMDP Method` ).
+ out->write( zcl_demo_abap_aux=>heading( `3) AMDP Table Function for AMDP Method` ) ).
"The AMDP procedure select_get_carr_fli calls the AMDP table function
"get_carr_fli in the implementation part. AMDP table functions can
@@ -316,7 +314,7 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
ENDTRY.
- output->display( input = amdp_tab_func name = `amdp_tab_func` ).
+ out->write( data = amdp_tab_func name = `amdp_tab_func` ).
"Note: When commented in, the following code results in a runtime
"error since you cannot call an AMDP function in ABAP directly.
@@ -325,8 +323,7 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
**********************************************************************
- output->next_section( `4) AMDP Table Function for CDS Table Function` ).
-
+ out->write( zcl_demo_abap_aux=>heading( `4) AMDP Table Function for CDS Table Function` ) ).
"The example demonstrates that a CDS table function can be used as a
"data source of ABAP SQL read statements.
@@ -343,7 +340,7 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
SELECT * FROM zdemo_abap_table_function
INTO TABLE @DATA(cds_tab_func).
- output->display( input = cds_tab_func name = `cds_tab_func` ).
+ out->write( data = cds_tab_func name = `cds_tab_func` ).
ENDMETHOD.
diff --git a/src/zcl_demo_abap_flight_tables.clas.abap b/src/zcl_demo_abap_aux.clas.abap
similarity index 98%
rename from src/zcl_demo_abap_flight_tables.clas.abap
rename to src/zcl_demo_abap_aux.clas.abap
index b656210..dbc8c9d 100644
--- a/src/zcl_demo_abap_flight_tables.clas.abap
+++ b/src/zcl_demo_abap_aux.clas.abap
@@ -20,22 +20,24 @@
"!
Class supporting ABAP cheat sheet examples
"! The class supports the ABAP cheat examples by clearing and populating demo database tables that are used there.
"! The demo database tables contain airline and flight information.
-CLASS zcl_demo_abap_flight_tables DEFINITION
+CLASS zcl_demo_abap_aux DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
CLASS-METHODS: clear_dbtabs,
- fill_dbtabs.
+ fill_dbtabs,
+ heading IMPORTING text TYPE string
+ RETURNING VALUE(output) TYPE string.
-protected section.
-private section.
+ PROTECTED SECTION.
+ PRIVATE SECTION.
ENDCLASS.
-CLASS ZCL_DEMO_ABAP_FLIGHT_TABLES IMPLEMENTATION.
+CLASS zcl_demo_abap_aux IMPLEMENTATION.
METHOD clear_dbtabs.
@@ -708,4 +710,8 @@ CLASS ZCL_DEMO_ABAP_FLIGHT_TABLES IMPLEMENTATION.
seatsocc_f = 20 ) ) ).
ENDMETHOD.
+ METHOD heading.
+ output = |\n_________________________________________________________________________________\n\n{ text }\n\n|.
+ ENDMETHOD.
+
ENDCLASS.
diff --git a/src/zcl_demo_abap_display.clas.xml b/src/zcl_demo_abap_aux.clas.xml
similarity index 78%
rename from src/zcl_demo_abap_display.clas.xml
rename to src/zcl_demo_abap_aux.clas.xml
index 32954f8..ac3f0f7 100644
--- a/src/zcl_demo_abap_display.clas.xml
+++ b/src/zcl_demo_abap_aux.clas.xml
@@ -3,9 +3,9 @@
- ZCL_DEMO_ABAP_DISPLAY
+ ZCL_DEMO_ABAP_AUX
E
- Class for ABAP cheat sheet examples
+ Class supporting ABAP cheat sheet examples
1
X
X
diff --git a/src/zcl_demo_abap_cds_ve.clas.abap b/src/zcl_demo_abap_cds_ve.clas.abap
index bb5d15f..f0f0b1a 100644
--- a/src/zcl_demo_abap_cds_ve.clas.abap
+++ b/src/zcl_demo_abap_cds_ve.clas.abap
@@ -53,16 +53,18 @@ CLASS zcl_demo_abap_cds_ve DEFINITION
if_oo_adt_classrun.
CLASS-METHODS class_constructor.
+protected section.
+private section.
ENDCLASS.
-CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
+CLASS ZCL_DEMO_ABAP_CDS_VE IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
- zcl_demo_abap_flight_tables=>fill_dbtabs( ).
+ zcl_demo_abap_aux=>fill_dbtabs( ).
"Some more database table insertions for this particular example
MODIFY zdemo_abap_carr FROM TABLE @( VALUE #(
@@ -98,12 +100,10 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
- DATA(output) = NEW zcl_demo_abap_display( out ).
+ out->write( |ABAP Cheat Sheet Example: CDS view entities\n\n| ).
- output->display( `ABAP Cheat Sheet Example: CDS view entities` ).
-
- output->display( `1) Operands, expressions and built-in functions ` &&
- `in a CDS view entity` ).
+ out->write( `1) Operands, expressions and built-in functions ` &&
+ |in a CDS view entity\n\n| ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved. The sample CDS view entity
@@ -120,11 +120,11 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY CarrierId
INTO TABLE @DATA(select_from_cds).
- output->display( input = select_from_cds name = `select_from_cds` ).
+ out->write( data = select_from_cds name = `select_from_cds` ).
**********************************************************************
- output->next_section( `2) Aggregate Expressions` ).
+ out->write( zcl_demo_abap_aux=>heading( `2) Aggregate Expressions` ) ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved. The sample CDS view entity
@@ -135,11 +135,11 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY carrid
INTO TABLE @DATA(agg_expr).
- output->display( input = agg_expr name = `agg_expr` ).
+ out->write( data = agg_expr name = `agg_expr` ).
**********************************************************************
- output->next_section( `3) Joins` ).
+ out->write( zcl_demo_abap_aux=>heading( `3) Joins` ) ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved. The sample CDS view entity
@@ -155,11 +155,11 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY carrid
INTO TABLE @DATA(cds_joins).
- output->display( input = cds_joins name = `cds_joins` ).
+ out->write( data = cds_joins name = `cds_joins` ).
**********************************************************************
- output->next_section( `4) Excursion: ABAP SQL and joins` ).
+ out->write( zcl_demo_abap_aux=>heading( `4) Excursion: ABAP SQL and joins` ) ).
"The following ABAP SQL SELECT statements are intended to reproduce
"the different joins that are performed by the CDS view entity.
@@ -172,7 +172,9 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
" contain the coalesce function and CASE expressions similar to the
" CDS view entity.
- output->display( `---------- Inner join ----------` ).
+ out->write( `---------- Inner join ----------` ).
+ out->write( |\n| ).
+ out->write( |\n| ).
SELECT _carr~carrid,
_carr~carrname,
@@ -184,9 +186,12 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY _carr~carrid
INTO TABLE @DATA(sql_inner_join).
- output->display( input = sql_inner_join name = `sql_inner_join` ).
+ out->write( data = sql_inner_join name = `sql_inner_join` ).
- output->display( `---------- Left outer join ----------` ).
+ out->write( |\n| ).
+ out->write( `---------- Left outer join ----------` ).
+ out->write( |\n| ).
+ out->write( |\n| ).
SELECT _carr~carrid,
_carr~carrname,
@@ -198,9 +203,12 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY _carr~carrid
INTO TABLE @DATA(sql_left_outer_join).
- output->display( input = sql_left_outer_join name = `sql_left_outer_join` ).
+ out->write( data = sql_left_outer_join name = `sql_left_outer_join` ).
- output->display( `---------- Right outer join ----------` ).
+ out->write( |\n| ).
+ out->write( `---------- Right outer join ----------` ).
+ out->write( |\n| ).
+ out->write( |\n| ).
SELECT _carr~carrid,
_carr~carrname,
@@ -215,9 +223,12 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY _carr~carrid
INTO TABLE @DATA(sql_right_outer_join).
- output->display( input = sql_right_outer_join name = `sql_right_outer_join` ).
+ out->write( data = sql_right_outer_join name = `sql_right_outer_join` ).
- output->display( `---------- Cross join ----------` ).
+ out->write( |\n| ).
+ out->write( `---------- Cross join ----------` ).
+ out->write( |\n| ).
+ out->write( |\n| ).
SELECT _carr~carrid,
_carr~carrname,
@@ -228,36 +239,37 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY _carr~carrid
INTO TABLE @DATA(sql_cross_join).
- output->display( input = sql_cross_join name = `sql_cross_join` ).
+ out->write( data = sql_cross_join name = `sql_cross_join` ).
+ out->write( |\n| ).
"Just a check what join example is currently commented in
IF cds_joins = sql_inner_join.
- output->display( `In the example CDS view entity, the inner join example is commented in.` ).
+ out->write( `In the example CDS view entity, the inner join example is commented in.` ).
ELSEIF cds_joins = sql_left_outer_join.
- output->display( `In the example CDS view entity, the left outer join example is commented in.` ).
+ out->write( `In the example CDS view entity, the left outer join example is commented in.` ).
ELSEIF cds_joins = sql_right_outer_join.
- output->display( `In the example CDS view entity, the right outer join example is commented in.` ).
+ out->write( `In the example CDS view entity, the right outer join example is commented in.` ).
ELSEIF cds_joins = sql_cross_join.
- output->display( `In the example CDS view entity, the cross join example is commented in.` ).
+ out->write( `In the example CDS view entity, the cross join example is commented in.` ).
ELSE.
- output->display( `In the example CDS view entity, there is some other code present.` ).
+ out->write( `In the example CDS view entity, there is some other code present.` ).
ENDIF.
**********************************************************************
- output->next_section( `Associations` ).
+ out->write( zcl_demo_abap_aux=>heading( `Associations` ) ).
- output->display( `5) Selecting data from a CDS view that contains associations` ).
+ out->write( |5) Selecting data from a CDS view that contains associations\n\n| ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved. The sample CDS view entity
@@ -274,16 +286,16 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY carrier
INTO TABLE @DATA(assoc).
- output->display( input = assoc name = `assoc` ).
+ out->write( data = assoc name = `assoc` ).
**********************************************************************
- output->next_section( `Using exposed associations in ABAP SQL statements: ...` ).
+ out->write( zcl_demo_abap_aux=>heading( `Using exposed associations in ABAP SQL statements: ...` ) ).
"The following examples use path expressions to access the association
"targets of exposed associations.
- output->display( `6) ... SELECT clause` ).
+ out->write( |6) ... SELECT clause\n\n| ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. The statement uses an exposed association.
@@ -306,11 +318,11 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY carrier
INTO TABLE @DATA(assoc_exp_select).
- output->display( input = assoc_exp_select name = `assoc_exp_select` ).
+ out->write( data = assoc_exp_select name = `assoc_exp_select` ).
**********************************************************************
- output->next_section( `7) ... FROM clause` ).
+ out->write( zcl_demo_abap_aux=>heading( `7) ... FROM clause` ) ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved.
@@ -329,7 +341,8 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY carrid
INTO TABLE @DATA(assoc_exp_from).
- output->display( input = assoc_exp_from name = `assoc_exp_from` ).
+ out->write( data = assoc_exp_from name = `assoc_exp_from` ).
+ out->write( |\n| ).
"The following ABAP SQL SELECT statement is intended to reproduce
"the data retrieval as above.
@@ -351,17 +364,18 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY _carr~carrid
INTO TABLE @DATA(sql_repr).
- output->display( input = sql_repr name = `sql_repr` ).
+ out->write( data = sql_repr name = `sql_repr` ).
+ out->write( |\n| ).
IF sql_repr = assoc_exp_from.
- output->display( `The result sets are the same.` ).
+ out->write( `The result sets are the same.` ).
ELSE.
- output->display( `The result sets are differrent.` ).
+ out->write( `The result sets are differrent.` ).
ENDIF.
**********************************************************************
- output->next_section( `8) ... Specifying attributes` ).
+ out->write( zcl_demo_abap_aux=>heading( `8) ... Specifying attributes` ) ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. The statement uses an exposed association.
@@ -398,7 +412,8 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY carrid, connid, flightdate
INTO TABLE @DATA(assoc_attr_card).
- output->display( input = assoc_attr_card name = `assoc_attr_card` ).
+ out->write( data = assoc_attr_card name = `assoc_attr_card` ).
+ out->write( |\n| ).
"Specifying the join type explicitly
"- INNER, LEFT/RIGHT OUTER are possible
@@ -415,7 +430,8 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY carrid, connid, flightdate
INTO TABLE @DATA(assoc_attr_joty).
- output->display( input = assoc_attr_joty name = `assoc_attr_joty` ).
+ out->write( data = assoc_attr_joty name = `assoc_attr_joty` ).
+ out->write( |\n| ).
"Specifying conditions
"- Filter conditions can be specified for the current association
@@ -439,11 +455,11 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY carrid, connid, flightdate
INTO TABLE @DATA(assoc_attr_where).
- output->display( input = assoc_attr_where name = `assoc_attr_where` ).
+ out->write( data = assoc_attr_where name = `assoc_attr_where` ).
**********************************************************************
- output->next_section( `9) ... WHERE clause` ).
+ out->write( zcl_demo_abap_aux=>heading( `9) ... WHERE clause` ) ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. The statement uses an exposed association.
@@ -459,7 +475,7 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
ORDER BY carrid, connid
INTO TABLE @DATA(assoc_exp_where).
- output->display( input = assoc_exp_where name = `assoc_exp_where` ).
+ out->write( data = assoc_exp_where name = `assoc_exp_where` ).
ENDMETHOD.
ENDCLASS.
diff --git a/src/zcl_demo_abap_cloud_excursion.clas.abap b/src/zcl_demo_abap_cloud_excursion.clas.abap
index ea49e73..c2c91ea 100644
--- a/src/zcl_demo_abap_cloud_excursion.clas.abap
+++ b/src/zcl_demo_abap_cloud_excursion.clas.abap
@@ -83,8 +83,16 @@ CLASS zcl_demo_abap_cloud_excursion DEFINITION
ENDCLASS.
+
+
CLASS zcl_demo_abap_cloud_excursion IMPLEMENTATION.
+
+ METHOD heading.
+ output = |\n_________________________________________________________________________________\n\n{ text }\n\n|.
+ ENDMETHOD.
+
+
METHOD if_oo_adt_classrun~main.
out->write( |ABAP Cheat Sheet Example: Excursions into ABAP for Cloud Development\n| ).
out->write( `1) Restrictions in ABAP for Cloud Development` ).
@@ -194,20 +202,14 @@ CLASS zcl_demo_abap_cloud_excursion IMPLEMENTATION.
APPEND |{ month_wa-CalendarMonth } { month_wa-CalendarMonthName } ({ month_wa-Language })| TO string_tab.
ENDLOOP.
- "Using a released API, the data is serialized
- DATA(json_str) = /ui2/cl_json=>serialize( data = string_tab
- pretty_name = /ui2/cl_json=>pretty_mode-low_case
- compress = abap_false
- hex_as_base64 = abap_false
- format_output = abap_true
- assoc_arrays = abap_true
- assoc_arrays_opt = abap_true ).
+ "Creating a JSON string from a data object using a released API
+ DATA(json_str) = xco_cp_json=>data->from_abap( months )->to_string( ).
out->write( |\nNumber of months per language: { number_of_months }| ).
out->write( |\nMonths returned:| ).
- out->write( data = string_tab ).
- out->write( |\nMonths returned (serialized data object):| ).
- out->write( data = json_str ).
+ out->write( data = string_tab name = `string_tab` ).
+ out->write( |\nMonths returned (JSON string):| ).
+ out->write( data = json_str name = `json_str` ).
"Getting APIs for use in ABAP for Cloud Development
"The released CDS view contains the relevant information. In the example,
@@ -940,24 +942,43 @@ CLASS zcl_demo_abap_cloud_excursion IMPLEMENTATION.
DATA(m20_user_name) = xco_cp=>sy->user( )->name.
out->write( data = m1_user_time_zone name = `m1_user_time_zone` ).
+ out->write( |\n| ).
out->write( data = m2_moment_string name = `m2_moment_string` ).
+ out->write( |\n| ).
out->write( data = m3_moment_format_a name = `m3_moment_format_a` ).
+ out->write( |\n| ).
out->write( data = m4_moment_format_b name = `m4_moment_format_b` ).
+ out->write( |\n| ).
out->write( data = m5_cur_moment4user name = `m5_cur_moment4user` ).
+ out->write( |\n| ).
out->write( data = m6_cur_moment_utc name = `m6_cur_moment_utc` ).
+ out->write( |\n| ).
out->write( data = m7_unix_tstmp name = `m7_unix_tstmp` ).
+ out->write( |\n| ).
out->write( data = m8_time name = `m8_time` ).
+ out->write( |\n| ).
out->write( data = m9_seconds name = `m9_seconds` ).
+ out->write( |\n| ).
out->write( data = m10_minutes name = `m10_minutes` ).
+ out->write( |\n| ).
out->write( data = m11_hours name = `m11_hours` ).
+ out->write( |\n| ).
out->write( data = m12_add_time name = `m12_add_time` ).
+ out->write( |\n| ).
out->write( data = m13_subtract_time name = `m13_subtract_time` ).
+ out->write( |\n| ).
out->write( data = m14_date name = `m14_date` ).
+ out->write( |\n| ).
out->write( data = m15_day name = `m15_day` ).
+ out->write( |\n| ).
out->write( data = m16_month name = `m16_month` ).
+ out->write( |\n| ).
out->write( data = m17_year name = `m17_year` ).
+ out->write( |\n| ).
out->write( data = m18_add_date name = `m18_add_date` ).
+ out->write( |\n| ).
out->write( data = m19_subtract_date name = `m19_subtract_date` ).
+ out->write( |\n| ).
out->write( data = m20_user_name name = `m20_user_name` ).
**********************************************************************
@@ -988,7 +1009,7 @@ CLASS zcl_demo_abap_cloud_excursion IMPLEMENTATION.
" "abap_true".
"
"The generation of the objects is only carried out if all of the mentioned
- "prerequisites are met.
+ "prerequisites are met.
"Checking validity of the specified transport request ID
TRY.
@@ -1099,7 +1120,4 @@ CLASS zcl_demo_abap_cloud_excursion IMPLEMENTATION.
out->write( details_tab ).
ENDIF.
ENDMETHOD.
- METHOD heading.
- output = |\n_________________________________________________________________________________\n\n{ text }\n\n|.
- ENDMETHOD.
ENDCLASS.
diff --git a/src/zcl_demo_abap_constructor_expr.clas.abap b/src/zcl_demo_abap_constructor_expr.clas.abap
index e550065..d5794f2 100644
--- a/src/zcl_demo_abap_constructor_expr.clas.abap
+++ b/src/zcl_demo_abap_constructor_expr.clas.abap
@@ -107,7 +107,7 @@ ENDCLASS.
-CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
+CLASS ZCL_DEMO_ABAP_CONSTRUCTOR_EXPR IMPLEMENTATION.
METHOD fill_deep_structures.
@@ -164,12 +164,10 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
- DATA(output) = NEW zcl_demo_abap_display( out ).
+ out->write( `ABAP Cheat Sheet Example: Constructor Expressions` ).
- output->display( `ABAP Cheat Sheet Example: Constructor expressions` ).
-
- output->display( `VALUE` ).
- output->display( `1) Structures: Populating a flat structure` ).
+ out->write( |\nVALUE\n| ).
+ out->write( |1) Structures: Populating a flat structure\n\n| ).
"A flat structure is created based on a data type defined with a
"TYPES statement. The structure is then filled using a constructor
@@ -187,29 +185,30 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
"Filling structure
struc = VALUE #( num = 1 char1 = 'aaa' char2 = 'abc' ).
- output->display( input = struc name = `struc` ).
+ out->write( data = struc name = `struc` ).
**********************************************************************
- output->next_section( `2) Structures: Omitting value assignment to components / BASE addition` ).
+ out->write( zcl_demo_abap_aux=>heading( `2) Structures: Omitting value assignment to components / BASE addition` ) ).
"The same structure is then filled purposely omitting components, i.
"e. these components remain initial.
struc = VALUE #( char1 = 'bbb' ).
- output->display( input = struc name = `struc` ).
+ out->write( data = struc name = `struc` ).
"You can use the BASE addition to retain existing content
"Compare with the BASE example further down regarding internal tables: There are
"no extra parentheses within the outer pair of parentheses.
struc = VALUE #( BASE struc char2 = 'xyz' ).
- output->display( input = struc name = `struc` ).
+ out->write( |\n| ).
+ out->write( data = struc name = `struc` ).
**********************************************************************
- output->next_section( `3) Structures: Inline declaration, explicit type specification` ).
+ out->write( zcl_demo_abap_aux=>heading( `3) Structures: Inline declaration, explicit type specification` ) ).
"The example demonstrates a variable that is declared inline. Here,
"the result is a structure which is filled using a constructor
@@ -222,11 +221,11 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
char1 = 'ccc'
char2 = 'def' ).
- output->display( input = struc_inl name = `struc_inl` ).
+ out->write( data = struc_inl name = `struc_inl` ).
**********************************************************************
- output->next_section( `4) Internal tables: Declaration and population` ).
+out->write( zcl_demo_abap_aux=>heading( `4) Internal tables: Declaration and population` ) ).
"The example demonstrates the declaration of an internal table. The
"internal table is then filled using a constructor expression with
@@ -242,11 +241,11 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
( num = 2 char1 = 'bbb' char2 = 'def' )
( num = 3 char1 = 'ccc' ) ).
- output->display( input = itab name = `itab` ).
+ out->write( data = itab name = `itab` ).
**********************************************************************
- output->next_section( `5) Internal tables: Inline declaration, explicit type specification` ).
+ out->write( zcl_demo_abap_aux=>heading( `5) Internal tables: Inline declaration, explicit type specification` ) ).
"The example demonstrates an internal table declared inline that is
"filled using a constructor expression with VALUE by specifying the
@@ -266,12 +265,13 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
( `table` )
( `of type string` ) ).
- output->display( input = itab2 name = `itab2` ).
- output->display( input = str_table name = `str_table` ).
+ out->write( data = itab2 name = `itab2` ).
+ out->write( |\n| ).
+ out->write( data = str_table name = `str_table` ).
**********************************************************************
- output->next_section( `6) LINES OF addition` ).
+ out->write( zcl_demo_abap_aux=>heading( `6) LINES OF addition` ) ).
"Using the LINES OF addition, you can add lines of other tables.
"Note: The line type of the other internal table must match the one of
@@ -283,22 +283,22 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
( LINES OF itab )
( LINES OF itab FROM 1 TO 2 ) ).
- output->display( input = itab2 name = `itab2` ).
+ out->write( data = itab2 name = `itab2` ).
**********************************************************************
- output->next_section( `7) BASE addition for keeping existing data` ).
+ out->write( zcl_demo_abap_aux=>heading( `7) BASE addition for keeping existing data` ) ).
"Using the BASE addition, you can keep existing content of the source
"internal table.
itab2 = VALUE #( BASE itab2 ( num = 7 char1 = 'ggg' char2 = 'pqr' ) ).
- output->display( input = itab2 name = `itab2` ).
+ out->write( data = itab2 name = `itab2` ).
**********************************************************************
- output->next_section( `8) Assignemnt with the VALUE operator without specifying content in parentheses` ).
+ out->write( zcl_demo_abap_aux=>heading( `8) Assignemnt with the VALUE operator without specifying content in parentheses` ) ).
"Using the VALUE operator without populating anything in the parentheses,
"data objects are initialized.
@@ -316,44 +316,48 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
str_table = VALUE #( ).
struc = VALUE #( ).
- output->display( input = some_num name = `some_num` ).
- output->display( input = another_num name = `another_num` ).
- output->display( input = some_str name = `some_str` ).
- output->display( input = str_table name = `str_table` ).
- output->display( input = struc name = `struc` ).
+ out->write( data = some_num name = `some_num` ).
+ out->write( |\n| ).
+ out->write( data = another_num name = `another_num` ).
+ out->write( |\n| ).
+ out->write( data = some_str name = `some_str` ).
+ out->write( |\n| ).
+ out->write( data = str_table name = `str_table` ).
+ out->write( |\n| ).
+ out->write( data = struc name = `struc` ).
**********************************************************************
- output->next_section( `Excursions: VALUE operator in use with ABAP statements and ABAP SQL statements` ).
+ out->write( zcl_demo_abap_aux=>heading( `Excursions: VALUE operator in use with ABAP statements and ABAP SQL statements` ) ).
"The following examples use ABAP and ABAP SQL statements in which table lines
"are constructed inline using the VALUE operator.
- output->display( `9) Modifying internal table from a structure created inline` ).
+ out->write( `9) Modifying internal table from a structure created inline` && |\n\n| ).
MODIFY TABLE itab2 FROM VALUE #( num = 7 char1 = 'hhh' char2 = 'stu' ).
- output->display( input = itab2 name = `itab2` ).
+ out->write( data = itab2 name = `itab2` ).
**********************************************************************
- output->next_section( `10) Inserting a table line that is created inline into an internal table` ).
+ out->write( zcl_demo_abap_aux=>heading( `10) Inserting a table line that is created inline into an internal table` ) ).
INSERT VALUE #( num = 8 char1 = 'iii' char2 = 'vwx' ) INTO TABLE itab2.
- output->display( input = itab2 name = `itab2` ).
+ out->write( data = itab2 name = `itab2` ).
**********************************************************************
- output->next_section( `11) Deleting a table entry based on a line created inline` ).
+ out->write( zcl_demo_abap_aux=>heading( `11) Deleting a table entry based on a line created inline` ) ).
DELETE TABLE itab2 FROM VALUE #( num = 3 ).
- output->display( input = itab2 name = `itab2` ).
+ out->write( data = itab2 name = `itab2` ).
**********************************************************************
- output->next_section( `12) Modifying a database table based on an internal table created inline` ).
+ out->write( zcl_demo_abap_aux=>heading( `12) Modifying a database table based on an internal table created inline` ) ).
"Deleting demo database table entries for the following example
DELETE FROM zdemo_abap_carr.
@@ -375,12 +379,12 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
ORDER BY carrid
INTO TABLE @DATA(itab_carr).
- output->display( input = itab_carr name = `itab_carr` ).
+ out->write( data = itab_carr name = `itab_carr` ).
**********************************************************************
- output->next_section( `Excursion: Deep structures and tables` ).
- output->display( `13) Deep structure` ).
+ out->write( zcl_demo_abap_aux=>heading( `Excursion: Deep structures and tables` ) ).
+ out->write( |13) Deep structure\n| ).
"The example demonstrates the use of constructor expressions with
"VALUE in the context of a deep structure. Here, a structure is declared
@@ -400,11 +404,11 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
char1 = 'aaa'
substruc = VALUE #( int = 123 str = `hallo` ) ).
- output->display( input = deep_struc name = `deep_struc` ).
+ out->write( data = deep_struc name = `deep_struc` ).
**********************************************************************
- output->next_section( `14) Deep internal table` ).
+ out->write( zcl_demo_abap_aux=>heading( `14) Deep internal table` ) ).
"A deep internal table is created. Also here, nested VALUE
"expressions are demonstrated.
@@ -421,32 +425,35 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
( char = 'aaa' tab = VALUE #( ( 1 ) ( 2 ) ( 3 ) ) )
( char = 'bbb' tab = VALUE #( ( 4 ) ( 5 ) ( 6 ) ) ) ).
- output->display( input = deep_itab name = `deep_itab` ).
+ out->write( data = deep_itab name = `deep_itab` ).
**********************************************************************
- output->next_section( `CORRESPONDING` ).
- output->display( `Simple Examples with structures and internal tables` ).
+ out->write( zcl_demo_abap_aux=>heading( `CORRESPONDING` ) ).
+ out->write( |Simple Examples with structures and internal tables\n| ).
"Method to fill demo structures and internal tables
"with values to work with
fill_struc_and_tab( ).
- output->display( `15) Original structure and table content` ).
+ out->write( `15) Original structure and table content` && |\n\n| ).
"Displaying the original structures and tables that are filled in the
"course of a method call. The structures and tables are filled anew
"throughout the examples so that all CORRESPONDING expressions are based
"on the same values.
- output->display( input = s1 name = `s1` ).
- output->display( input = s2 name = `s2` ).
- output->display( input = tab1 name = `tab1` ).
- output->display( input = tab2 name = `it_st` ).
+ out->write( data = s1 name = `s1` ).
+ out->write( |\n| ).
+ out->write( data = s2 name = `s2` ).
+ out->write( |\n| ).
+ out->write( data = tab1 name = `tab1` ).
+ out->write( |\n| ).
+ out->write( data = tab2 name = `it_st` ).
**********************************************************************
- output->next_section( `16) CORRESPONDING without addition` ).
+ out->write( zcl_demo_abap_aux=>heading( `16) CORRESPONDING without addition` ) ).
"The target structure and table have a different type but identically
"named components. The identically named components are filled. Note
@@ -459,12 +466,13 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
tab2 = CORRESPONDING #( tab1 ).
- output->display( input = s2 name = `s2` ).
- output->display( input = tab2 name = `tab2` ).
+ out->write( data = s2 name = `s2` ).
+ out->write( |\n| ).
+ out->write( data = tab2 name = `tab2` ).
**********************************************************************
- output->next_section( `17) BASE addition for keeping original content` ).
+ out->write( zcl_demo_abap_aux=>heading( `17) BASE addition for keeping original content` ) ).
"The BASE addition keeps the original content. Structure: The non-
"identical component name retains its value. Internal table: Existing
@@ -476,12 +484,13 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
tab2 = CORRESPONDING #( BASE ( tab2 ) tab1 ).
- output->display( input = s2 name = `s2` ).
- output->display( input = tab2 name = `tab2` ).
+ out->write( data = s2 name = `s2` ).
+ out->write( |\n| ).
+ out->write( data = tab2 name = `tab2` ).
**********************************************************************
- output->next_section( `18) MAPPING/EXCEPT additions` ).
+ out->write( zcl_demo_abap_aux=>heading( `18) MAPPING/EXCEPT additions` ) ).
"The example demonstrates the additions MAPPING and EXCEPT. MAPPING:
"One component of the target structure is assigned the value of a
@@ -494,15 +503,16 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
tab2 = CORRESPONDING #( tab1 EXCEPT comp1 ).
- output->display( input = s2 name = `s2` ).
- output->display( input = tab2 name = `tab2` ).
+ out->write( data = s2 name = `s2` ).
+ out->write( |\n| ).
+ out->write( data = tab2 name = `tab2` ).
**********************************************************************
- output->next_section( `CORRESPONDING: Demonstrating various` &&
- ` additions using deep structures` ).
+ out->write( zcl_demo_abap_aux=>heading( `CORRESPONDING: Demonstrating various` &&
+ ` additions using deep structures` ) ).
- output->display( `19) Original content of deep structures` ).
+ out->write( `19) Original content of deep structures` && |\n\n| ).
"Displaying the original deep structures and tables that are filled in
"the course of a method call. The deep structures and tables are filled
@@ -513,12 +523,13 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
"with values to work with
fill_deep_structures( ).
- output->display( input = struc1 name = `struc1` ).
- output->display( input = struc2 name = `struc2` ).
+ out->write( data = struc1 name = `struc1` ).
+ out->write( |\n| ).
+ out->write( data = struc2 name = `struc2` ).
**********************************************************************
- output->next_section( `20) CORRESPONDING without addition` ).
+ out->write( zcl_demo_abap_aux=>heading( `20) CORRESPONDING without addition` ) ).
"CORRESPONDING operator without addition
"Existing contents of identically named components are replaced.
@@ -537,11 +548,11 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
struc2 = CORRESPONDING #( struc1 ).
- output->display( input = struc2 name = `struc2` ).
+ out->write( data = struc2 name = `struc2` ).
**********************************************************************
- output->next_section( `21) DEEP addition` ).
+ out->write( zcl_demo_abap_aux=>heading( `21) DEEP addition` ) ).
"CORRESPONDING operator with the addition DEEP
"Existing contents of identically named components are replaced.
@@ -560,11 +571,11 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
struc2 = CORRESPONDING #( DEEP struc1 ).
- output->display( input = struc2 name = `struc2` ).
+ out->write( data = struc2 name = `struc2` ).
**********************************************************************
- output->next_section( `22) BASE addition` ).
+ out->write( zcl_demo_abap_aux=>heading( `22) BASE addition` ) ).
"CORRESPONDING operator with the addition BASE
"Existing contents of identically named components are replaced.
@@ -586,11 +597,11 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
struc2 = CORRESPONDING #( BASE ( struc2 ) struc1 ).
- output->display( input = struc2 name = `struc2` ).
+ out->write( data = struc2 name = `struc2` ).
**********************************************************************
- output->next_section( `23) DEEP BASE addition` ).
+ out->write( zcl_demo_abap_aux=>heading( `23) DEEP BASE addition` ) ).
"CORRESPONDING operator with the additions DEEP BASE
"Existing contents of identically named components are replaced.
@@ -610,11 +621,11 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
struc2 = CORRESPONDING #( DEEP BASE ( struc2 ) struc1 ).
- output->display( input = struc2 name = `struc2` ).
+ out->write( data = struc2 name = `struc2` ).
**********************************************************************
- output->next_section( `24) APPENDING addition` ).
+ out->write( zcl_demo_abap_aux=>heading( `24) APPENDING addition` ) ).
"CORRESPONDING operator with the addition APPENDING
"Existing contents of identically named components are replaced.
@@ -636,11 +647,11 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
struc2 = CORRESPONDING #( APPENDING ( struc2 ) struc1 ).
- output->display( input = struc2 name = `struc2` ).
+ out->write( data = struc2 name = `struc2` ).
**********************************************************************
- output->next_section( `25) DEEP APPENDING` ).
+ out->write( zcl_demo_abap_aux=>heading( `25) DEEP APPENDING` ) ).
"CORRESPONDING operator with the additions DEEP APPENDING
"Existing contents of identically named components are replaced.
@@ -661,12 +672,12 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
struc2 = CORRESPONDING #( DEEP APPENDING ( struc2 ) struc1 ).
- output->display( input = struc2 name = `struc2` ).
+ out->write( data = struc2 name = `struc2` ).
**********************************************************************
- output->next_section( `NEW` ).
- output->display( `26) Creating Anonymous Data Objects` ).
+ out->write( zcl_demo_abap_aux=>heading( `NEW` ) ).
+ out->write( `26) Creating Anonymous Data Objects` && |\n\n| ).
"The examples show the creation of anonymous data objects.
"First, data reference variables are declared using a DATA statement.
@@ -713,17 +724,23 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
DATA(dref6) = NEW zdemo_abap_carr( carrid = 'AA'
carrname = 'American Airlines' ).
- output->display( input = val name = `val` ).
- output->display( input = dref1 name = `dref1` ).
- output->display( input = dref2 name = `dref2` ).
- output->display( input = dref3 name = `dref3` ).
- output->display( input = dref4 name = `dref4` ).
- output->display( input = dref5 name = `dref5` ).
- output->display( input = dref6 name = `dref6` ).
+ out->write( data = val name = `val` ).
+ out->write( |\n| ).
+ out->write( data = dref1 name = `dref1` ).
+ out->write( |\n| ).
+ out->write( data = dref2 name = `dref2` ).
+ out->write( |\n| ).
+ out->write( data = dref3 name = `dref3` ).
+ out->write( |\n| ).
+ out->write( data = dref4 name = `dref4` ).
+ out->write( |\n| ).
+ out->write( data = dref5 name = `dref5` ).
+ out->write( |\n| ).
+ out->write( data = dref6 name = `dref6` ).
**********************************************************************
- output->next_section( `27) Creating Instances of Classes` ).
+ out->write( zcl_demo_abap_aux=>heading( `27) Creating Instances of Classes` ) ).
"The example demonstrates the creation of instances of classes.
"First, an object reference variable is declared with a DATA statement.
@@ -749,22 +766,25 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
"in the parentheses
oref1 = NEW #( txt = `Hallo` ).
- output->display( input = oref1 name = `oref1` ).
+ out->write( data = oref1 name = `oref1` ).
+ out->write( |\n| ).
"Creating an instance of a class, object reference variable
"is declared inline, explicit type specification
DATA(oref2) = NEW local_class( `Salut` ).
- output->display( input = oref2 name = `oref2` ).
+ out->write( data = oref2 name = `oref2` ).
+ out->write( |\n| ).
"Method chaining
DATA(result) = NEW local_class( `Ciao` )->double( int = NEW #( 5 ) ).
- output->display( input = result name = `result` ).
+ out->write( data = result name = `result` ).
+ out->write( |\n| ).
**********************************************************************
- output->next_section( `28) CONV` ).
+ out->write( zcl_demo_abap_aux=>heading( `28) CONV` ) ).
"The examples show the effect of the CONV operator.
"A variable of type i is declared and assigned a value. Then,
@@ -795,8 +815,10 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
"... with conversion using an appropriate type
DATA(dec_num) = CONV decfloat34( num / 4 ).
- output->display( input = i name = `i` ).
- output->display( input = dec_num name = `dec_num` ).
+ out->write( data = i name = `i` ).
+ out->write( |\n| ).
+ out->write( data = dec_num name = `dec_num` ).
+ out->write( |\n| ).
"Declaring data objects
DATA(txt) = VALUE abap_bool( ).
@@ -804,25 +826,26 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
DATA(str) = ` `.
"Comparing the data objects with and without conversion
- output->display( `Without conversion:` ).
+ out->write( `Without conversion:` ).
IF txt = str.
- output->display( `txt is equal to str.` ).
+ out->write( `txt is equal to str.` ).
ELSE.
- output->display( `txt is not equal to str.` ).
+ out->write( `txt is not equal to str.` ).
ENDIF.
- output->display( `With conversion:` ).
+ out->write( |\n| ).
+ out->write( `With conversion:` ).
IF txt = CONV abap_bool( str ).
- output->display( `txt is equal to converted str.` ).
+ out->write( `txt is equal to converted str.` ).
ELSE.
- output->display( `txt is not equal to converted str.` ).
+ out->write( `txt is not equal to converted str.` ).
ENDIF.
**********************************************************************
- output->next_section( `29) EXACT` ).
+ out->write( zcl_demo_abap_aux=>heading( `29) EXACT` ) ).
"The examples show the effect of the EXACT operator that enforces either
"a lossless assignment or a lossless calculation.
@@ -861,28 +884,34 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
DATA(conv_comp) = CONV numtext( '2 Apples + 5 Oranges' ).
IF ex1 IS INITIAL.
- output->display( |ex2: { ex2 }; { t1 }| ).
+ out->write( |ex2: "{ ex2 }"; t1: "{ t1 }"| ).
ELSE.
- output->display( ex1 ).
+ out->write( ex1 ).
ENDIF.
+ out->write( |\n| ).
+
IF ex3 IS INITIAL.
- output->display( |ex4: { ex4 }; { t2 }| ).
+ out->write( |ex4: "{ ex4 }"; t2: "{ t2 }"| ).
ELSE.
- output->display( input = ex3 name = `ex3` ).
+ out->write( data = ex3 name = `ex3` ).
ENDIF.
+ out->write( |\n| ).
+ out->write( |\n| ).
+
IF ex5 IS INITIAL.
- output->display( input = t3 name = `t3` ).
+ out->write( data = t3 name = `t3` ).
ELSE.
- output->display( input = ex5 name = `ex5` ).
+ out->write( data = ex5 name = `ex5` ).
ENDIF.
- output->display( input = conv_comp name = `conv_comp` ).
+ out->write( |\n| ).
+ out->write( data = conv_comp name = `conv_comp` ).
**********************************************************************
- output->next_section( `30) REF` ).
+ out->write( zcl_demo_abap_aux=>heading( `30) REF` ) ).
"The example includes the declaration of a data object and some data
"reference variables. One data reference variable is typed with a
@@ -915,15 +944,19 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
DATA(oref_a) = NEW local_class( `Ciao` ).
DATA(oref_b) = REF #( oref_a ).
- output->display( input = dref_a name = `dref_a` ).
- output->display( input = dref_b name = `dref_b` ).
- output->display( input = dref_c name = `dref_c` ).
- output->display( input = dref_d name = `dref_d` ).
- output->display( input = oref_b name = `oref_b` ).
+ out->write( data = dref_a name = `dref_a` ).
+ out->write( |\n| ).
+ out->write( data = dref_b name = `dref_b` ).
+ out->write( |\n| ).
+ out->write( data = dref_c name = `dref_c` ).
+ out->write( |\n| ).
+ out->write( data = dref_d name = `dref_d` ).
+ out->write( |\n| ).
+ out->write( data = oref_b name = `oref_b` ).
**********************************************************************
- output->next_section( `31) CAST` ).
+ out->write( zcl_demo_abap_aux=>heading( `31) CAST` ) ).
"The example demonstrates the CAST operator in the context of Run Time
"Type Identification (RTTI).
@@ -966,14 +999,17 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
dref_i = CAST #( dref_data ).
- output->display( input = components_s2 name = `components_s2` ).
- output->display( input = methods name = `methods` ).
- output->display( input = components_s1 name = `components_s1` ).
- output->display( input = dref_i name = `dref_i` ).
+ out->write( data = components_s2 name = `components_s2` ).
+ out->write( |\n| ).
+ out->write( data = methods name = `methods` ).
+ out->write( |\n| ).
+ out->write( data = components_s1 name = `components_s1` ).
+ out->write( |\n| ).
+ out->write( data = dref_i name = `dref_i` ).
**********************************************************************
- output->next_section( `32) COND` ).
+ out->write( zcl_demo_abap_aux=>heading( `32) COND` ) ).
"The example demonstrates the use of the COND operator. The syntax
"includes several WHEN and THEN expressions.
@@ -997,11 +1033,11 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
ELSE |Hallo, { sy-uname }.|
).
- output->display( input = greets name = `greets` ).
+ out->write( data = greets name = `greets` ).
**********************************************************************
- output->next_section( `33) SWITCH` ).
+ out->write( zcl_demo_abap_aux=>heading( `33) SWITCH` ) ).
"The example demonstrates the use of the SWITCH operator. Here,
"calculations are carried out. For this
@@ -1030,15 +1066,15 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
WHEN '*' THEN CONV decfloat34( num1 * num2 )
WHEN '/' THEN CONV decfloat34( num1 / num2 )
ELSE `That doesn't work.` ).
- output->display( |{ num1 } { } { num2 } = { calc_result }| ).
+ out->write( |{ num1 } { } { num2 } = { calc_result }| ).
CATCH cx_sy_arithmetic_error INTO DATA(error).
- output->display( |Arithmetic error. { error->get_text( ) }| ).
+ out->write( |Arithmetic error. { error->get_text( ) }| ).
ENDTRY.
ENDLOOP.
**********************************************************************
- output->next_section( `34) FILTER` ).
+ out->write( zcl_demo_abap_aux=>heading( `34) FILTER` ) ).
"This section covers multiple examples demonstrating the syntactical variety
"of the FILTER operator.
@@ -1071,36 +1107,43 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
"Here, the primary key is used
DATA(f1) = FILTER #( fi_tab1 WHERE a >= 3 ).
- output->display( input = f1 name = `f1` ).
+ out->write( data = f1 name = `f1` ).
+ out->write( |\n| ).
"USING KEY primary_key explicitly specified; same as above
DATA(f2) = FILTER #( fi_tab1 USING KEY primary_key WHERE a >= 3 ).
- output->display( input = f2 name = `f2` ).
+ out->write( data = f2 name = `f2` ).
+ out->write( |\n| ).
"EXCEPT addition
DATA(f3) = FILTER #( fi_tab1 EXCEPT WHERE a >= 3 ).
- output->display( input = f3 name = `f3` ).
+ out->write( data = f3 name = `f3` ).
+ out->write( |\n| ).
DATA(f4) = FILTER #( fi_tab1 EXCEPT USING KEY primary_key WHERE a >= 3 ).
- output->display( input = f4 name = `f4` ).
+ out->write( data = f4 name = `f4` ).
+ out->write( |\n| ).
"Secondary table key specified after USING KEY
DATA(f5) = FILTER #( fi_tab2 USING KEY sec_key WHERE a >= 4 ).
- output->display( input = f5 name = `f5` ).
+ out->write( data = f5 name = `f5` ).
+ out->write( |\n| ).
DATA(f6) = FILTER #( fi_tab2 EXCEPT USING KEY sec_key WHERE a >= 3 ).
- output->display( input = f6 name = `f6` ).
+ out->write( data = f6 name = `f6` ).
+ out->write( |\n| ).
"Note: In case of a hash key, exactly one comparison expression for each key
"component is allowed; only = as comparison operator possible.
DATA(f7) = FILTER #( fi_tab3 WHERE a = 3 ).
- output->display( input = f7 name = `f7` ).
+ out->write( data = f7 name = `f7` ).
+ out->write( |\n| ).
"Using a filter table
"In the WHERE condition, the columns of source and filter table are compared.
@@ -1120,45 +1163,51 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
DATA(f8) = FILTER #( fi_tab1 IN filter_tab1 WHERE a = table_line ).
- output->display( input = f8 name = `f8` ).
+ out->write( data = f8 name = `f8` ).
+ out->write( |\n| ).
"EXCEPT addition
DATA(f9) = FILTER #( fi_tab1 EXCEPT IN filter_tab1 WHERE a = table_line ).
- output->display( input = f9 name = `f9` ).
+ out->write( data = f9 name = `f9` ).
+ out->write( |\n| ).
"USING KEY is specified for the filter table
DATA(f10) = FILTER #( fi_tab2 IN filter_tab2 USING KEY line WHERE a = table_line ).
- output->display( input = f10 name = `f10` ).
+ out->write( data = f10 name = `f10` ).
+ out->write( |\n| ).
"USING KEY is specified for the source table, including EXCEPT
DATA(f11) = FILTER #( fi_tab2 USING KEY sec_key EXCEPT IN filter_tab2 WHERE a = table_line ).
- output->display( input = f11 name = `f11` ).
+ out->write( data = f11 name = `f11` ).
+ out->write( |\n| ).
**********************************************************************
- output->next_section( `Iteration Expressions with FOR` ).
+ out->write( zcl_demo_abap_aux=>heading( `Iteration Expressions with FOR` ) ).
"The examples demonstrate iteration expressions with FOR. The examples
"are based on demo internal tables that are filled using a method. The
"tables are displayed to show the original content of the internal
"tables that are to be processed.
- output->display( `35) Original table content` ).
+ out->write( |35) Original table content\n\n| ).
"Method to fill demo internal tables with values to work with.
"Tables are displayed showing the values.
fill_struc_and_tab( ).
- output->display( input = tab1 name = `tab1` ).
- output->display( input = tab2 name = `tab2` ).
- output->display( input = tab3 name = `tab3` ).
+ out->write( data = tab1 name = `tab1` ).
+ out->write( |\n| ).
+ out->write( data = tab2 name = `tab2` ).
+ out->write( |\n| ).
+ out->write( data = tab3 name = `tab3` ).
**********************************************************************
- output->next_section( `36) FOR ... IN ... (LOOP Semantics)` ).
+ out->write( zcl_demo_abap_aux=>heading( `36) FOR ... IN ... (LOOP Semantics)` ) ).
"Examples demonstrating FOR ... IN ... that has the semantics of LOOP.
"1) An internal table is looped across. The whole line is stored in a
@@ -1202,9 +1251,12 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
comp2 = `hallo`
comp3 = wa-comp4 ) ).
- output->display( input = for1 name = `for1` ).
- output->display( input = for2 name = `for2` ).
- output->display( input = for3 name = `for3` ).
+ out->write( data = for1 name = `for1` ).
+ out->write( |\n| ).
+ out->write( data = for2 name = `for2` ).
+ out->write( |\n| ).
+ out->write( data = for3 name = `for3` ).
+ out->write( |\n| ).
"The example demonstrates multiple iteration expressions with FOR. Here,
"a new table is created that is declared inline. Three tables are
@@ -1230,12 +1282,12 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
compY = wa2-comp1
compZ = wa3-comp3 ) ).
- output->display( input = for4 name = `for4` ).
+ out->write( data = for4 name = `for4` ).
**********************************************************************
- output->next_section( `37) FOR ... WHILE/UNTIL ... ` &&
- `(DO/WHILE Semantics)` ).
+ out->write( zcl_demo_abap_aux=>heading( `37) FOR ... WHILE/UNTIL ... ` &&
+ `(DO/WHILE Semantics)` ) ).
"Examples demonstrating FOR ... WHILE/UNTIL ... that has the semantics
"of DO/WHILE.
@@ -1264,12 +1316,13 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
FOR y = 31 THEN y - 10 UNTIL y < 10
( col1 = y col2 = y + 1 col3 = y + 2 ) ).
- output->display( input = for5 name = `for5` ).
- output->display( input = for6 name = `for6` ).
+ out->write( data = for5 name = `for5` ).
+ out->write( |\n| ).
+ out->write( data = for6 name = `for6` ).
**********************************************************************
- output->next_section( `38) REDUCE (1)` ).
+ out->write( zcl_demo_abap_aux=>heading( `38) REDUCE (1)` ) ).
"The examples demonstrate the REDUCE operator using values contained in
"an internal table column. Here, the table is of type string.
@@ -1308,12 +1361,13 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
FOR word IN tab
NEXT text = |{ text }{ sep }{ word }| sep = ` ` ) && '.'.
- output->display( input = a_word name = `a_word` ).
- output->display( input = sentence name = `sentence` ).
+ out->write( data = a_word name = `a_word` ).
+ out->write( |\n| ).
+ out->write( data = sentence name = `sentence` ).
**********************************************************************
- output->next_section( `39) REDUCE (2)` ).
+ out->write( zcl_demo_abap_aux=>heading( `39) REDUCE (2)` ) ).
"The examples demonstrate summations using the REDUCE operator.
"1) Example using FOR ... UNTIL .... It calculates the total of the
@@ -1339,12 +1393,13 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
FOR z IN itab_i
NEXT x = x + z ).
- output->display( input = sum1 name = `sum1` ).
- output->display( input = sum2 name = `sum2` ).
+ out->write( data = sum1 name = `sum1` ).
+ out->write( |\n| ).
+ out->write( data = sum2 name = `sum2` ).
**********************************************************************
- output->next_section( `40) REDUCE (3)` ).
+ out->write( zcl_demo_abap_aux=>heading( `40) REDUCE (3)` ) ).
"The examples demonstrate the concatenation of strings
"1) without the addition THEN
@@ -1367,13 +1422,15 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
UNTIL strlen( t ) > 10
NEXT text &&= |{ t } | ).
- output->display( input = conc1 name = `conc1` ).
- output->display( input = conc2 name = `conc2` ).
- output->display( input = conc3 name = `conc3` ).
+ out->write( data = conc1 name = `conc1` ).
+ out->write( |\n| ).
+ out->write( data = conc2 name = `conc2` ).
+ out->write( |\n| ).
+ out->write( data = conc3 name = `conc3` ).
**********************************************************************
- output->next_section( `41) LET Expressions (1)` ).
+ out->write( zcl_demo_abap_aux=>heading( `41) LET Expressions (1)` ) ).
"The examples demonstrate LET expressions in different contexts.
@@ -1388,11 +1445,11 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
( |To do is to { it }| )
( |Do { it } do { it } do| ) ).
- output->display( input = str_tab name = `str_tab` ).
+ out->write( data = str_tab name = `str_tab` ).
**********************************************************************
- output->next_section( `42) LET Expressions (2)` ).
+ out->write( zcl_demo_abap_aux=>heading( `42) LET Expressions (2)` ) ).
"2) LET within a constructor expression with COND: 12 o'clock is
"specified as value for the LET expression. Based on this value, checks
@@ -1409,11 +1466,11 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
WHEN system_time = tm THEN |High Noon|
ELSE |?| ).
- output->display( input = time name = `time` ).
+ out->write( data = time name = `time` ).
**********************************************************************
- output->next_section( `43) LET Expressions (3)` ).
+ out->write( zcl_demo_abap_aux=>heading( `43) LET Expressions (3)` ) ).
"3) An internal table that includes three components is created and
"filled. A loop across this table is carried out. The purpose of the
@@ -1450,7 +1507,7 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
stringtab = VALUE #( BASE stringtab ( isodate ) ).
ENDDO.
- output->display( input = stringtab name = `stringtab` ).
+ out->write( data = stringtab name = `stringtab` ).
ENDMETHOD.
ENDCLASS.
diff --git a/src/zcl_demo_abap_display.clas.abap b/src/zcl_demo_abap_display.clas.abap
deleted file mode 100644
index 67ed4da..0000000
--- a/src/zcl_demo_abap_display.clas.abap
+++ /dev/null
@@ -1,160 +0,0 @@
-***********************************************************************
-*
-* Class for ABAP cheat sheet examples designed to support displaying
-* output in the ADT console
-*
-* -------------------------- NOTE -------------------------------------
-* This helper class is only used to display complex types contained in
-* the example classes of the ABAP cheat sheets in older ABAP releases.
-* In newer ABAP releases, this helper class is, in principle, not needed.
-* You can use the write method of the classrun interface directly and
-* display all types.
-*
-* The code presented in this class is intended only to support the ABAP
-* cheat sheets. It is not intended for direct use in a production system
-* environment. The code examples in the ABAP cheat sheets are primarily
-* intended to provide a better explanation and visualization of the
-* syntax and semantics of ABAP statements, not to solve concrete
-* programming tasks. For production application programs, you should
-* always work out your own solution for each individual case. There is
-* no guarantee for the correctness or completeness of the code.
-* Furthermore, there is no legal responsibility or liability for any
-* errors or their consequences that may occur when using the the example
-* code.
-*
-***********************************************************************
-"! Class supporting ABAP cheat sheet examples
-"! The class supports displaying output of the ABAP cheat sheet examples in the ADT console.
-CLASS zcl_demo_abap_display DEFINITION
- PUBLIC
- FINAL
- CREATE PUBLIC .
-
- PUBLIC SECTION.
- METHODS:
- constructor
- IMPORTING
- io_out TYPE REF TO if_oo_adt_classrun_out,
- display
- IMPORTING
- input TYPE data
- name TYPE string DEFAULT ``
- RETURNING
- VALUE(output) TYPE string,
- next_section
- IMPORTING
- heading TYPE string.
-
- PROTECTED SECTION.
- PRIVATE SECTION.
- DATA:
- mo_out TYPE REF TO if_oo_adt_classrun_out,
- offset TYPE i.
-
- CONSTANTS nl TYPE string VALUE cl_abap_char_utilities=>newline.
-ENDCLASS.
-
-
-
-CLASS zcl_demo_abap_display IMPLEMENTATION.
-
-
- METHOD constructor.
- mo_out = io_out.
- ENDMETHOD.
-
-
- METHOD display.
- "Checking data type
- DATA(type_descr) = cl_abap_typedescr=>describe_by_data( input ).
- CASE type_descr->kind.
- WHEN cl_abap_typedescr=>kind_struct.
- DATA(struct_descr) = CAST cl_abap_structdescr( type_descr ).
- "Checking for complex output
- IF struct_descr->struct_kind = cl_abap_structdescr=>structkind_nested
- OR line_exists( struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_table ] )
- OR line_exists( struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_dref ] )
- OR line_exists( struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_oref ] ).
- DATA(to_be_serialized) = abap_true.
- ELSE.
- DATA(display) = mo_out->get( data = input name = name ).
- ENDIF.
- WHEN cl_abap_typedescr=>kind_table.
- DATA(table_descr) = CAST cl_abap_tabledescr( type_descr ).
- TRY.
- DATA(line_type_struct_descr) = CAST cl_abap_structdescr( table_descr->get_table_line_type( ) ).
- "Checking for complex output
- IF line_type_struct_descr->struct_kind = cl_abap_structdescr=>structkind_nested
- OR line_exists( line_type_struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_table ] )
- OR line_exists( line_type_struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_dref ] )
- OR line_exists( line_type_struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_oref ] ).
- to_be_serialized = abap_true.
- ELSE.
- display = mo_out->get( data = input name = name ).
- ENDIF.
- CATCH cx_sy_move_cast_error.
- to_be_serialized = abap_true.
- ENDTRY.
- WHEN cl_abap_typedescr=>kind_class.
- to_be_serialized = abap_true.
- WHEN cl_abap_typedescr=>kind_intf.
- to_be_serialized = abap_true.
- WHEN cl_abap_typedescr=>kind_elem.
- display = mo_out->get( data = COND string( WHEN name IS INITIAL THEN input ELSE `"` && name && `":` && nl && input ) ).
- WHEN cl_abap_typedescr=>kind_ref.
- "Checking for data references
- IF type_descr->type_kind = cl_abap_typedescr=>typekind_dref.
- "Checking type of dereferenced data object
- DATA(type_check_dref) = cl_abap_typedescr=>describe_by_data( input->* ).
- "Processing (non-)elementary types
- IF type_check_dref->kind = type_descr->kind_elem.
- display = mo_out->get( data = COND string( WHEN name IS INITIAL THEN input->* ELSE `"` && name && `":` && nl && input->* ) ).
- ELSE.
- to_be_serialized = abap_true.
- ENDIF.
- ELSE.
- to_be_serialized = abap_true.
- ENDIF.
- ENDCASE.
-
- "Processing complex output by serializiation
- FIND SUBSTRING `Data type not yet supported ...` IN display MATCH OFFSET DATA(off) MATCH LENGTH DATA(len).
- IF sy-subrc = 0 OR to_be_serialized = abap_true.
- "ABAP JSON serializing
- DATA(json) = /ui2/cl_json=>serialize( data = input
- pretty_name = /ui2/cl_json=>pretty_mode-low_case
- compress = abap_false
- hex_as_base64 = abap_false
- format_output = abap_true
- assoc_arrays = abap_true
- assoc_arrays_opt = abap_true ).
- IF to_be_serialized = abap_true.
- IF name IS INITIAL.
- REPLACE PCRE `^` IN display WITH json && nl.
- ELSE.
- REPLACE PCRE `^` IN display WITH `"` && name && `":` && nl && json && nl.
- ENDIF.
- "substring found
- ELSE.
- IF name IS INITIAL.
- REPLACE SECTION OFFSET off LENGTH len OF display WITH json && nl.
- ELSE.
- REPLACE SECTION OFFSET off LENGTH len OF display WITH `"` && name && `":` && nl && json && nl.
- ENDIF.
- ENDIF.
- mo_out->write( display && nl ).
- ELSE.
- mo_out->write( display && nl ).
- ENDIF.
- ENDMETHOD.
-
-
- METHOD next_section.
- mo_out->write( `_________________________________________________________________________________`
- && nl
- && nl
- && heading
- && nl
- && nl ).
- ENDMETHOD.
-ENDCLASS.
diff --git a/src/zcl_demo_abap_dtype_dobj.clas.abap b/src/zcl_demo_abap_dtype_dobj.clas.abap
index 3534da1..9aa469b 100644
--- a/src/zcl_demo_abap_dtype_dobj.clas.abap
+++ b/src/zcl_demo_abap_dtype_dobj.clas.abap
@@ -39,7 +39,7 @@
* code.
*
***********************************************************************
-"! ABAP Cheat Sheet: Data Types and Data Objects
+"! ABAP cheat sheet: Data Types and Data Objects
"! Example to demonstrate data types and data objects in ABAP.
Choose F9 in ADT to run the class.
CLASS zcl_demo_abap_dtype_dobj DEFINITION
PUBLIC
@@ -68,6 +68,8 @@ CLASS zcl_demo_abap_dtype_dobj DEFINITION
num2 TYPE numeric
RETURNING VALUE(result) TYPE decfloat34.
+ constants no_output type string value `No output for this section. Check out the types in the code e.g. using the F2 information.`.
+
**********************************************************************
"Types and methods for demonstrating enumerated types and objects
@@ -116,7 +118,7 @@ ENDCLASS.
-CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
+CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
METHOD adapt_text.
@@ -124,7 +126,7 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
text = cl_text && comma && sy-uname && me->text.
- str = text && |\n(Note: The value of me->text is "{ me->text }")|.
+ str = text && | (Note: The value of me->text is "{ me->text }")|.
ENDMETHOD.
@@ -135,7 +137,7 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
- zcl_demo_abap_flight_tables=>fill_dbtabs( ).
+ zcl_demo_abap_aux=>fill_dbtabs( ).
ENDMETHOD.
@@ -259,13 +261,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
- DATA(output) = NEW zcl_demo_abap_display( out ).
-
- output->display( `ABAP Cheat Sheet Example: Data Types and Data Objects` ).
+ out->write( |ABAP Cheat Sheet Example: Data Types and Data Objects\n\n| ).
**********************************************************************
- output->display( `Declaring data types` ).
+ out->write( |Declaring data types\n\n| ).
"The following examples deal with the declaration of data types.
"They show how data types can be declared locally in an ABAP program.
@@ -277,7 +277,7 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
"- The examples show a selection.
"- Only non-generic types can be used.
- output->display( `1) Declaring data types based on elementary types` ).
+ out->write( |1) Declaring data types based on elementary types\n\n| ).
"See the ABAP Keyword Documentation for the value ranges that are
"accepted by these types.
@@ -366,13 +366,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
TYPES te_tp TYPE abap_bool.
TYPES te_const_in_tp LIKE abap_true.
- output->display( `No output for this section. Check out the code, `
- && `for example, when running the class in the debugger after setting `
- && `a breakpoint, or the F2 information in ADT when selecting a type.` ).
+ out->write( no_output ).
**********************************************************************
- output->next_section( `2) Declaring data types based on complex types` ).
+ out->write( zcl_demo_abap_aux=>heading( `2) Declaring data types based on complex types` ) ).
"Structure and internal table types as examples for complex types
@@ -436,13 +434,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
"Elementary line type; the type is available in a global interface
TYPES tt_elem_type_from_itf TYPE TABLE OF zdemo_abap_get_data_itf=>occ_rate.
- output->display( `No output for this section. Check out the code, `
- && `for example, when running the class in the debugger after setting `
- && `a breakpoint, or the F2 information in ADT when selecting a type.` ).
+ out->write( no_output ).
**********************************************************************
- output->next_section( `3) Declaring reference types` ).
+ out->write( zcl_demo_abap_aux=>heading( `3) Declaring reference types` ) ).
"Declaring reference types with static types
TYPES tr_i TYPE REF TO i.
@@ -471,15 +467,13 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
"Reference table types
TYPES tr_tab_ref_i TYPE TABLE OF REF TO i.
DATA itab_str TYPE TABLE OF string.
- TYPES tr_like_table_ref LIKE TABLE OF REF TO itab_str.
+ TYPES tr_like_table_ref LIKE TABLE OF ref TO itab_str.
- output->display( `No output for this section. Check out the code, `
- && `for example, when running the class in the debugger after setting `
- && `a breakpoint, or the F2 information in ADT when selecting a type.` ).
+ out->write( no_output ).
**********************************************************************
- output->next_section( `Declaring data objects` ).
+ out->write( zcl_demo_abap_aux=>heading( `Declaring data objects` ) ).
"The following examples deal with the declaration of data ojects.
"They show how data objects can be declared locally in an ABAP program.
@@ -497,7 +491,7 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
"- The examples show a selection. For more information, check out the ABAP
" Keyword Documentation.
- output->display( `4) Declaring data objects based on elementary data types` ).
+ out->write( |4) Declaring data objects based on elementary data types\n\n| ).
"The elementary, built-in data types can be used as shown for data type
" declarations. Chained statements are also possible with DATA.
@@ -571,13 +565,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
...
ENDIF.
- output->display( `No output for this section. Check out the code, `
- && `for example, when running the class in the debugger after setting `
- && `a breakpoint, or the F2 information in ADT when selecting a type.` ).
+ out->write( no_output ).
**********************************************************************
- output->next_section( `5) Declaring structures and internal tables as examples for complex types` ).
+ out->write( zcl_demo_abap_aux=>heading( `5) Declaring structures and internal tables as examples for complex types` ) ).
"Note: See more details and examples in the ABAP Keyword Documentations and in the
"respective ABAP cheat sheets.
@@ -632,13 +624,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
DATA struc_from_itab_type TYPE LINE OF tt_ddic_tab.
DATA struc_like_line LIKE LINE OF itab_ddic_tab.
- output->display( `No output for this section. Check out the code, `
- && `for example, when running the class in the debugger after setting `
- && `a breakpoint, or the F2 information in ADT when selecting a type.` ).
+ out->write( no_output ).
**********************************************************************
- output->next_section( `6) Declaring data reference variables` ).
+ out->write( zcl_demo_abap_aux=>heading( `6) Declaring data reference variables` ) ).
"Declaring data reference variables types with static types
DATA dref_int TYPE REF TO i.
@@ -665,13 +655,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
DATA dref_tab_i TYPE TABLE OF REF TO i.
DATA dref_tab_str LIKE TABLE OF REF TO do_some_string.
- output->display( `No output for this section. Check out the code, `
- && `for example, when running the class in the debugger after setting `
- && `a breakpoint, or the F2 information in ADT when selecting a type.` ).
+ out->write( no_output ).
**********************************************************************
- output->next_section( `7) Assigning values to data objects` ).
+ out->write( zcl_demo_abap_aux=>heading( `7) Assigning values to data objects` ) ).
"An assignment passes the content of a source to a target data object.
"Note:
@@ -769,13 +757,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
"with the conversion rules.
str_a2 = some_itab[ 2 ]-carrname.
- output->display( `No output for this section. Check out the code, `
- && `for example, when running the class in the debugger after setting `
- && `a breakpoint, or the F2 information in ADT when selecting a type.` ).
+ out->write( no_output ).
**********************************************************************
- output->next_section( `8) Creating data objects by inline declaration` ).
+ out->write( zcl_demo_abap_aux=>heading( `8) Creating data objects by inline declaration` ) ).
"The declaration operator DATA can be specified in any designated declaration position.
"The data type of the variable is determined by the operand type. It must be possible
@@ -883,13 +869,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
"NEW addition
SELECT * FROM zdemo_abap_carr INTO TABLE NEW @DATA(itab_ref).
- output->display( `No output for this section. Check out the code, `
- && `for example, when running the class in the debugger after setting `
- && `a breakpoint, or the F2 information in ADT when selecting a type.` ).
+ out->write( no_output ).
**********************************************************************
- output->next_section( `9) Assigning references to data reference variables` ).
+ out->write( zcl_demo_abap_aux=>heading( `9) Assigning references to data reference variables` ) ).
"Note:
"- As is true for other data object and types, there are special assignment rules
@@ -979,7 +963,7 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
TRY.
dref_2_str = CAST #( dref_3_data ).
CATCH cx_sy_move_cast_error INTO DATA(e).
- output->display( input = e->get_text( ) name = `e->get_text( )` ).
+ out->write( data = e->get_text( ) name = `e->get_text( )` ).
ENDTRY.
"Old syntax using the ?= operator
@@ -991,7 +975,7 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
**********************************************************************
- output->next_section( `10) Creating anonymous data objects` ).
+ out->write( zcl_demo_abap_aux=>heading( `10) Creating anonymous data objects` ) ).
"Anonymous data objects are a topic related to data reference variables.
"These data objects are unnamed data objects.
@@ -1090,15 +1074,13 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
FROM zdemo_abap_carr
INTO TABLE NEW @DATA(dref_14_inline).
- output->display( `No output for this section. Check out the code, `
- && `for example, when running the class in the debugger after setting `
- && `a breakpoint, or the F2 information in ADT when selecting a type.` ).
+ out->write( no_output ).
**********************************************************************
- output->next_section( `Excursions: Elementary types and type conversions` ).
+ out->write( zcl_demo_abap_aux=>heading( `Excursions: Elementary types and type conversions` ) ).
- output->display( `11) Implicit and explicit conversion` ).
+ out->write( |11) Implicit and explicit conversion\n\n| ).
"Implicit conversions are performed in assignments using the assignment operator =
"The content of a data object is converted according to the associated conversion rules.
@@ -1110,20 +1092,23 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
DATA do_2_c3 TYPE c LENGTH 3.
do_2_c3 = do_1_str.
- output->display( input = do_2_c3 name = `do_2_c3` ).
+ out->write( data = do_2_c3 name = `do_2_c3` ).
+ out->write( |\n| ).
"Conversions with the types i and decfloat34
DATA do_4_i TYPE i.
DATA do_5_dcfl34 TYPE decfloat34 VALUE '4.56'.
do_4_i = do_5_dcfl34.
- output->display( input = do_4_i name = `do_4_i` ).
+ out->write( data = do_4_i name = `do_4_i` ).
+ out->write( |\n| ).
"Conversions with the types i and string
do_4_i = -5.
do_1_str = do_4_i.
- output->display( input = do_1_str name = `do_1_str` ).
+ out->write( data = do_1_str name = `do_1_str` ).
+ out->write( |\n| ).
"Explicit type conversions can be performed with the CONV operator
"It converts the value specified within the parentheses to the data type specified
@@ -1137,22 +1122,25 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
DATA do_6_dcfl34 TYPE decfloat34 VALUE '2.78'.
DATA(do_7_i) = CONV i( do_6_dcfl34 ).
- output->display( input = do_7_i name = `do_7_i` ).
+ out->write( data = do_7_i name = `do_7_i` ).
+ out->write( |\n| ).
"# character when the type can be derived
DATA do_8_i TYPE i.
do_8_i = CONV #( do_6_dcfl34 ).
- output->display( input = do_8_i name = `do_8_i` ).
+ out->write( data = do_8_i name = `do_8_i` ).
+ out->write( |\n| ).
"The following two calculations yield different results
do_8_i = sqrt( 5 ) + sqrt( 6 ).
- output->display( input = do_8_i name = `do_8_i` ).
+ out->write( data = do_8_i name = `do_8_i` ).
+ out->write( |\n| ).
do_8_i = CONV i( sqrt( 5 ) ) + CONV i( sqrt( 6 ) ).
- output->display( input = do_8_i name = `do_8_i` ).
+ out->write( data = do_8_i name = `do_8_i` ).
"CONV operator for creating data objects inline with elementary data types
"Assume, you want a data object typed with decfloat34.
@@ -1169,7 +1157,7 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
**********************************************************************
- output->next_section( `12) Character strings and text field strings` ).
+ out->write( zcl_demo_abap_aux=>heading( `12) Character strings and text field strings` ) ).
"The following example shows the difference between text field strings
"of type c and character strings of type string when it comes to trailing
@@ -1182,11 +1170,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
result3 = '-->' && text_space && '<--'.
result4 = '-->' && string_space && '<--'.
- output->display( |{ result3 }\n{ result4 }| ).
+ out->write( |{ result3 }\n{ result4 }| ).
**********************************************************************
- output->next_section( `13) Floating point numbers` ).
+ out->write( zcl_demo_abap_aux=>heading( `13) Floating point numbers` ) ).
"The following example shows the difference between binary and decimal
"floating point numbers.
@@ -1196,12 +1184,12 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
result1 = 815 / 1000.
result2 = 815 / 1000.
- output->display( |Binary floating point: { result1 }\n| &&
+ out->write( |Binary floating point: { result1 }\n| &&
|Decimal floating point: { result2 }\n| ).
**********************************************************************
- output->next_section( `14) Byte-like types` ).
+ out->write( zcl_demo_abap_aux=>heading( `14) Byte-like types` ) ).
"The following example shows byte-like types x and xstring.
@@ -1226,12 +1214,14 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
codepage = `UTF-8`
)->convert( source = some_string ).
- output->display( input = xstr name = `xstr` ).
+ out->write( data = xstr name = `xstr` ).
+ out->write( |\n| ).
DATA(xstring2string) = cl_abap_conv_codepage=>create_in( codepage = `UTF-8`
)->convert( source = xstr ).
- output->display( input = xstring2string name = `xstring2string` ).
+ out->write( data = xstring2string name = `xstring2string` ).
+ out->write( |\n| ).
DATA line_feed_hex TYPE x LENGTH 1 VALUE '0A'.
@@ -1241,8 +1231,10 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
ASSERT line_feed_str = |\n|.
ASSERT line_feed_str = cl_abap_char_utilities=>newline.
- output->display( `Y-->` && line_feed_str && `<--` ).
- output->display( `Y-->` && |\n| && `<--` ).
+ out->write( `Y-->` && line_feed_str && `<--` ).
+ out->write( |\n| ).
+ out->write( `Y-->` && |\n| && `<--` ).
+ out->write( |\n| ).
DATA a_blank_x TYPE x LENGTH 1 VALUE '20'.
@@ -1251,11 +1243,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
ASSERT blank = ` `.
- output->display( `-->` && blank && `<--` ).
+ out->write( `-->` && blank && `<--` ).
**********************************************************************
- output->next_section( `15) Date and time` ).
+ out->write( zcl_demo_abap_aux=>heading( `15) Date and time` ) ).
"In the example, a date field is assigned the current values
"using the cl_abap_context_info class. A calculation follows. The date of next
@@ -1267,24 +1259,26 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
"calendar. In this case, the date would exceeed the maximum value '99991231'.
"In such a case, the date field is assigned the invalid value '00000000'.
- DATA: today TYPE d,
- tomorrow TYPE d.
- today = cl_abap_context_info=>get_system_date( ).
- tomorrow = today + 1.
- output->display(
- |Today: { today }\n| &&
- |Tommorow: { tomorrow }| ).
+ DATA: today TYPE d,
+ tomorrow TYPE d.
+ today = cl_abap_context_info=>get_system_date( ).
+ tomorrow = today + 1.
+ out->write( data = today name = `today` ).
+ out->write( |\n| ).
+ out->write( data = tomorrow name = `tomorrow` ).
+ out->write( |\n| ).
DATA date TYPE d.
date = '20240101'.
- output->display( input = date name = `date` ).
+ out->write( data = date name = `date` ).
+ out->write( |\n| ).
date = 20240101.
- output->display( input = date name = `date` ).
+ out->write( data = date name = `date` ).
**********************************************************************
- output->next_section( `16) Type conversion rules` ).
+ out->write( zcl_demo_abap_aux=>heading( `16) Type conversion rules` ) ).
"The purpose of this example is to emphasize the conversion rules
"that should be noted when performing conversions. The example
@@ -1384,7 +1378,7 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
ENDTRY.
IF wa_ref_con->type = `T`.
- wa_ref_con->conv_err_d = `Move error: T to D. Otherwise, a runtime error is caused.`.
+ wa_ref_con->conv_err_d = `T to D not possible.`.
ELSE.
TRY.
wa_ref_con->conv_d = wa_ref_con->to_be_converted->*.
@@ -1402,7 +1396,7 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
ENDTRY.
IF wa_ref_con->type = `D`.
- wa_ref_con->conv_err_t = `Move error: D to T. Otherwise, a runtime error is caused.`.
+ wa_ref_con->conv_err_t = `D to T not possible.`.
ELSE.
TRY.
wa_ref_con->conv_t = wa_ref_con->to_be_converted->*.
@@ -1435,11 +1429,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
ENDLOOP.
- output->display( input = tt_conv_tab name = `tt_conv_tab` ).
+ out->write( data = tt_conv_tab name = `tt_conv_tab` ).
**********************************************************************
- output->next_section( `17) Excursion: RTTI` ).
+ out->write( zcl_demo_abap_aux=>heading( `17) Excursion: RTTI` ) ).
"Using RTTI to check type compatibility
"In the following example the applies_to_data method of the RTTI class
@@ -1462,19 +1456,24 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
IF CAST cl_abap_datadescr( cl_abap_typedescr=>describe_by_data( ref1->* )
)->applies_to_data( ref2->* ).
ref1->* = ref2->*.
- output->display( `The types of ref1->* and ref2->* are compatible.` ).
+ out->write( `The types of ref1->* and ref2->* are compatible.` ).
ELSE.
- output->display( `The types of ref1->* and ref2->* are not compatible.` ).
+ out->write( `The types of ref1->* and ref2->* are not compatible.` ).
ENDIF.
+ out->write( |\n| ).
+
IF CAST cl_abap_datadescr( cl_abap_typedescr=>describe_by_data( ref1->* )
)->applies_to_data( ref3->* ).
ref1->* = ref3->*.
- output->display( `The types of ref1->* and ref3->* are compatible.` ).
+ out->write( `The types of ref1->* and ref3->* are compatible.` ).
ELSE.
- output->display( `The types of ref1->* and ref3->* are not compatible.` ).
+ out->write( `The types of ref1->* and ref3->* are not compatible.` ).
ENDIF.
+ out->write( |\n| ).
+ out->write( |\n| ).
+
"Using RTTI to get type descriptions
"In the following example, an internal table that has been filled in
"a previous example is looped over. It contains references to various types
@@ -1501,11 +1500,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
ENDLOOP.
- output->display( input = rtti_tab name = `rtti_tab` ).
+ out->write( data = rtti_tab name = `rtti_tab` ).
**********************************************************************
- output->next_section( `18) Constants and immutable variables` ).
+ out->write( zcl_demo_abap_aux=>heading( `18) Constants and immutable variables` ) ).
"As mentioned above, constants cannot be changed at runtime.
CONSTANTS con_str TYPE string VALUE `hallo`.
@@ -1538,13 +1537,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
"SELECT statement with a an immutable target table declared inline
SELECT * FROM zdemo_abap_carr INTO TABLE @FINAL(itab_final_inl).
- output->display( `No output for this section. Check out the code, `
- && `for example, when running the class in the debugger after setting `
- && `a breakpoint, or the F2 information in ADT when selecting a type.` ).
+ out->write( no_output ).
**********************************************************************
- output->next_section( `19) Various ABAP glossary terms on data types and objects in a nutshell` ).
+ out->write( zcl_demo_abap_aux=>heading( `19) Various ABAP glossary terms on data types and objects in a nutshell` ) ).
"Standalone and bound data types
"Standalone: Data type that is defined using the statement TYPES in an ABAP program, as
@@ -1612,24 +1609,29 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
"Field symbols with generic data types can be assigned appropriate values
ASSIGN do_e_c5 TO .
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
ASSIGN do_f_str TO .
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
"Generic type data
ASSIGN do_e_c5 TO .
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
ASSIGN do_f_str TO .
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
ASSIGN itab_a TO .
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
**********************************************************************
@@ -1752,14 +1754,16 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
"Unnamed data objects
"Literal that is output. It cannot be addressed via a dedicated name.
- output->display( `I'm a literal...` ).
+ out->write( `I'm a literal...` ).
+ out->write( |\n| ).
"Anonymous data object created using the NEW operator
"Can be addressed using reference variables or field symbols.
DATA(dref_c_str) = NEW string( `hi` ).
- output->display( input = dref_c_str->* name = `dref_c_str->*` ).
+ out->write( data = dref_c_str->* name = `dref_c_str->*` ).
+ out->write( |\n| ).
"Anonymous data object created inline using the NEW addition to the INTO
"clause of a SELECT statement
@@ -1768,11 +1772,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
INTO TABLE NEW @DATA(dref_d_tab)
UP TO 3 ROWS.
- output->display( input = dref_d_tab->* name = `dref_d_tab->*` ).
+ out->write( data = dref_d_tab->* name = `dref_d_tab->*` ).
**********************************************************************
- output->next_section( `20) Generic ABAP types for formal parameters of methods` ).
+ out->write( zcl_demo_abap_aux=>heading( `20) Generic ABAP types for formal parameters of methods` ) ).
"Generic data types have already been covered above.
"A generic data type is an incomplete type specification that covers multiple
@@ -1808,13 +1812,13 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
ENDTRY.
ENDLOOP.
- output->display( input = tab_num name = `tab_num` ).
-
- output->display( input = error->get_text( ) name = `error->get_text( )` ).
+ out->write( data = tab_num name = `tab_num` ).
+ out->write( |\n| ).
+ out->write( data = error->get_text( ) name = `error->get_text( )` ).
**********************************************************************
- output->next_section( `21) Built-in data objects` ).
+ out->write( zcl_demo_abap_aux=>heading( `21) Built-in data objects` ) ).
"This example demonstrates the availability of built-in data objects in ABAP.
@@ -1832,7 +1836,8 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
APPEND sy-index TO syidx.
ENDDO.
- output->display( input = syidx name = `syidx` ).
+ out->write( data = syidx name = `syidx` ).
+ out->write( |\n| ).
DATA str_tab TYPE TABLE OF string.
@@ -1842,7 +1847,8 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
APPEND |Value of processed table line: { wa_sy1 } / Table index { sy-tabix }| TO str_tab.
ENDLOOP.
- output->display( input = str_tab name = `str_tab` ).
+ out->write( data = str_tab name = `str_tab` ).
+ out->write( |\n| ).
"sy-subrc contains a return code that is set by many ABAP statements.
"In general, the value 0 means that the statement was executed without problems.
@@ -1850,11 +1856,14 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
READ TABLE syidx INDEX 6 INTO DATA(wa_sy2).
IF sy-subrc = 0.
- output->display( |Yes, the table line was found. sy-subrc value that was returned is { sy-subrc }.| ).
+ out->write( |Yes, the table line was found. sy-subrc value that was returned is { sy-subrc }.| ).
ELSE.
- output->display( |No, the table line was not found. sy-subrc value that was returned is { sy-subrc }.| ).
+ out->write( |No, the table line was not found. sy-subrc value that was returned is { sy-subrc }.| ).
ENDIF.
+ out->write( |\n| ).
+ out->write( |\n| ).
+
"The program-global constant space has the data type c, length 1, and contains a blank character.
"In the following example, the table lines are concatenated into a string, separated by a blank.
@@ -1866,7 +1875,8 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
CONCATENATE LINES OF ctab INTO c_f SEPARATED BY space.
- output->display( input = c_f name = `c_f` ).
+ out->write( data = c_f name = `c_f` ).
+ out->write( |\n| ).
"Self-reference me
"Within the implementation of each instance method, an implicitly created local
@@ -1888,12 +1898,11 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
DATA(res_str) = oref->adapt_text( ).
- output->display( input = res_str name = `res_str` ).
-
+ out->write( data = res_str name = `res_str` ).
**********************************************************************
- output->next_section( `22) Declaration context` ).
+ out->write( zcl_demo_abap_aux=>heading( `22) Declaration context` ) ).
"The purpose of this example is to emphasize the importance of where
"data objects are decalred. The example deals with local declarations
@@ -1908,13 +1917,15 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
number = number + 1.
ENDDO.
- output->display( input = number name = `number` ).
+ out->write( data = number name = `number` ).
+ out->write( |\n| ).
DO 10 TIMES.
number = number + 1.
ENDDO.
- output->display( input = number name = `number` ).
+ out->write( data = number name = `number` ).
+ out->write( |\n| ).
"Comparing the behavior with a data object declared inline.
"In each loop pass, the value object is set to 10. Therefore,
@@ -1930,16 +1941,18 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
number_B = number_B + 1.
ENDDO.
- output->display( input = number_b name = `number_b` ).
+ out->write( data = number_b name = `number_b` ).
+ out->write( |\n| ).
DO 10 TIMES.
number_b = number_b + 1.
ENDDO.
- output->display( input = number_b name = `number_b` ).
+ out->write( data = number_b name = `number_b` ).
+ out->write( |\n| ).
**********************************************************************
- output->next_section( `23) Enumerated Types and Objects` ).
+ out->write( zcl_demo_abap_aux=>heading( `23) Enumerated Types and Objects` ) ).
"Examples for enumerated types and objects are contained in
"separate methods. Check the comments there.
@@ -1953,28 +1966,31 @@ CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
"enumerated values of the enumerated type can be passed to the parameter.
DATA enum_var1 TYPE t_enum VALUE a.
DATA(output_for_enum_var1) = enum_meth_params( enum_var1 ).
- output->display( input = output_for_enum_var1 name = `output_for_enum_var1` ).
+ out->write( data = output_for_enum_var1 name = `output_for_enum_var1` ).
+ out->write( |\n| ).
DATA enum_var2 TYPE t_enum VALUE b.
DATA(output_for_enum_var2) = enum_meth_params( enum_var2 ).
- output->display( input = output_for_enum_var2 name = `output_for_enum_var2` ).
+ out->write( data = output_for_enum_var2 name = `output_for_enum_var2` ).
+ out->write( |\n| ).
DATA enum_var3 TYPE t_enum VALUE d.
DATA(output_for_enum_var3) = enum_meth_params( enum_var3 ).
- output->display( input = output_for_enum_var3 name = `output_for_enum_var3` ).
+ out->write( data = output_for_enum_var3 name = `output_for_enum_var3` ).
+ out->write( |\n| ).
"The enum_processing method demonstrates various ways of processing enumerated
"objects.
DATA(output_for_enum_processing) = enum_processing( ).
- output->display( input = output_for_enum_processing name = `output_for_enum_processing` ).
+ out->write( data = output_for_enum_processing name = `output_for_enum_processing` ).
+ out->write( |\n| ).
"The rtti_enum method demonstrates the RTTI class cl_abap_enumdescr.
DATA(output_for_rtti_enum) = rtti_enum( ).
- output->display( input = output_for_rtti_enum name = `output_for_rtti_enum` ).
+ out->write( data = output_for_rtti_enum name = `output_for_rtti_enum` ).
ENDMETHOD.
-
METHOD rtti_enum.
DATA enum1 TYPE t_enum.
diff --git a/src/zcl_demo_abap_dtype_dobj.clas.xml b/src/zcl_demo_abap_dtype_dobj.clas.xml
index cf0dbff..3de7131 100644
--- a/src/zcl_demo_abap_dtype_dobj.clas.xml
+++ b/src/zcl_demo_abap_dtype_dobj.clas.xml
@@ -5,7 +5,7 @@
ZCL_DEMO_ABAP_DTYPE_DOBJ
E
- ABAP cheat sheets: Data types and data objects
+ ABAP cheat sheet: Data Types and Data Objects
1
X
X
diff --git a/src/zcl_demo_abap_dynamic_prog.clas.abap b/src/zcl_demo_abap_dynamic_prog.clas.abap
index 1d7d322..a21b418 100644
--- a/src/zcl_demo_abap_dynamic_prog.clas.abap
+++ b/src/zcl_demo_abap_dynamic_prog.clas.abap
@@ -65,20 +65,18 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
- zcl_demo_abap_flight_tables=>fill_dbtabs( ).
+ zcl_demo_abap_aux=>fill_dbtabs( ).
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
- DATA(output) = NEW zcl_demo_abap_display( out ).
-
- output->display( `ABAP Cheat Sheet Example: Dynamic Programming` ).
+ out->write( |ABAP Cheat Sheet Example: Dynamic Programming\n\n| ).
**********************************************************************
- output->display( `Excursion: Field Symbols` ).
- output->display( `1) Declaring Field Symbols` ).
+ out->write( |Excursion: Field Symbols\n\n| ).
+ out->write( |1) Declaring Field Symbols\n\n| ).
"Some data declarations and type definitions used further down
DATA: str TYPE string.
@@ -117,11 +115,11 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
...
ENDLOOP.
- output->display( `No output for this section. See the code.` ).
+ out->write( `No output for this section. See the code.` ).
**********************************************************************
- output->next_section( `2) Assigning Data Objects to Field Symbols` ).
+ out->write( zcl_demo_abap_aux=>heading( `2) Assigning Data Objects to Field Symbols` ) ).
"ASSIGN statements assigns the memory area of a data object to a field symbol.
"Once the memory area is assigned, you can work with the content.
@@ -154,11 +152,11 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"Inline declaration is possible, too. The type is derived automatically.
ASSIGN num_a TO FIELD-SYMBOL().
- output->display( `No output for this section. See the code.` ).
+ out->write( `No output for this section. See the code.` ).
**********************************************************************
- output->next_section( `3) Checking Field Symbol Assignment` ).
+ out->write( zcl_demo_abap_aux=>heading( `3) Checking Field Symbol Assignment` ) ).
"When working with field symbols, you should make sure that they are
"assigned. Otherwise, a runtime error occurs.
@@ -175,20 +173,22 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ASSIGN num_b TO .
IF IS ASSIGNED.
- output->display( `Field symbol is assigned.` ).
+ out->write( `Field symbol is assigned.` ).
ELSE.
- output->display( `Field symbol not assigned.` ).
+ out->write( `Field symbol not assigned.` ).
ENDIF.
+ out->write( |\n| ).
+
IF IS ASSIGNED.
- output->display( `Field symbol is assigned.` ).
+ out->write( `Field symbol is assigned.` ).
ELSE.
- output->display( `Field symbol is not assigned.` ).
+ out->write( `Field symbol is not assigned.` ).
ENDIF.
**********************************************************************
- output->next_section( `4) Unassigning Data Objects from Field Symbols` ).
+ out->write( zcl_demo_abap_aux=>heading( `4) Unassigning Data Objects from Field Symbols` ) ).
"If you use an unassigned field symbol, an exception is raised. Before
"using it, you can check the assignment with the following logical
@@ -203,22 +203,24 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ASSIGN num_c TO .
IF IS ASSIGNED.
- output->display( `1. Field symbol is assigned.` ).
+ out->write( `1. Field symbol is assigned.` ).
ELSE.
- output->display( `1. Field symbol is not assigned.` ).
+ out->write( `1. Field symbol is not assigned.` ).
ENDIF.
+ out->write( |\n| ).
+
UNASSIGN .
IF IS ASSIGNED.
- output->display( `2. Field symbol is assigned.` ).
+ out->write( `2. Field symbol is assigned.` ).
ELSE.
- output->display( `2. Field symbol is not assigned.` ).
+ out->write( `2. Field symbol is not assigned.` ).
ENDIF.
**********************************************************************
- output->next_section( `5) Type Casting with Field Symbols` ).
+ out->write( zcl_demo_abap_aux=>heading( `5) Type Casting with Field Symbols` ) ).
"The example demonstrates the CASTING addition. Various additions after
"CASTING are possible.
@@ -240,26 +242,31 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"cannot be used.
ASSIGN dobj_d_l10 TO CASTING.
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
ASSIGN dobj_d_l10 TO CASTING TYPE type_d_l9.
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
"Casting to a generic type
ASSIGN dobj_d_l10 TO CASTING TYPE c.
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
"Casting to a static field type
ASSIGN dobj_d_l10 TO CASTING LIKE dobj_d_l5.
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
"Casting to a dynamic field type
ASSIGN dobj_d_l10 TO CASTING LIKE .
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
"Anticipating dynamic specification of data types
"for the CASTING addition.
@@ -267,7 +274,8 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"object within parentheses.
ASSIGN dobj_d_l10 TO CASTING TYPE (type_name_d).
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
"Anticipating RTTS
"A type description object is created which can be
@@ -276,11 +284,11 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
cl_abap_typedescr=>describe_by_name( 'TYPE_D_L9' ) ).
ASSIGN dobj_d_l10 TO CASTING TYPE HANDLE sometype.
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
**********************************************************************
- output->next_section( `6) Addressing Field Symbols` ).
+ out->write( zcl_demo_abap_aux=>heading( `6) Addressing Field Symbols` ) ).
"The example includes multiple data objects that are assigned to field
"symbols. It is demonstrated that field symbols are addressed in various
@@ -313,30 +321,39 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"Changing values
= 789.
- output->display( input = name = `` ).
- output->display( input = num_e name = `num_e` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
+ out->write( data = num_e name = `num_e` ).
+ out->write( |\n| ).
"Use in expressions
DATA(calc_e) = + 211.
- output->display( input = calc_e name = `calc_e` ).
+ out->write( data = calc_e name = `calc_e` ).
+ out->write( |\n| ).
IF < 1000.
- output->display( `The value of is less than 1000` ).
+ out->write( `The value of is less than 1000` ).
ELSE.
- output->display( `The value of is greater than 1000` ).
+ out->write( `The value of is greater than 1000` ).
ENDIF.
+ out->write( |\n| ).
+ out->write( |\n| ).
+
"Structure
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
DATA(comp_e1) = -carrid.
- output->display( input = comp_e1 name = `comp_e1` ).
+ out->write( data = comp_e1 name = `comp_e1` ).
+ out->write( |\n| ).
-url = 'www.lh.com'.
- output->display( input = -url name = `-url` ).
+ out->write( data = -url name = `-url` ).
+ out->write( |\n| ).
"Internal table
SELECT *
@@ -345,26 +362,30 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
INTO TABLE @
UP TO 3 ROWS.
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
TRY.
DATA(comp_e2) = [ 2 ]-carrname.
- output->display( input = comp_e2 name = `comp_e2` ).
+ out->write( data = comp_e2 name = `comp_e2` ).
CATCH cx_sy_itab_line_not_found INTO DATA(error_e).
ENDTRY.
+ out->write( |\n| ).
+
SELECT *
FROM zdemo_abap_carr
ORDER BY carrid
INTO TABLE @
UP TO 3 ROWS.
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
**********************************************************************
- output->next_section( `7) Using Field Symbols when Processing ` &&
- `Internal Tables` ).
+ out->write( zcl_demo_abap_aux=>heading( `7) Using Field Symbols when Processing ` &&
+ `Internal Tables` ) ).
+
"By using field symbols in the context of loops across internal tables,
"you can avoid an actual copying of content to a work area during
@@ -414,7 +435,8 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
= VALUE #( BASE ( ) ).
ENDLOOP.
- output->display( input = tab_f1 name = `tab_f1` ).
+ out->write( data = tab_f1 name = `tab_f1` ).
+ out->write( |\n| ).
"The following example shows a field symbol declared inline.
LOOP AT ASSIGNING FIELD-SYMBOL().
@@ -427,12 +449,13 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
= VALUE #( BASE ( ) ).
ENDLOOP.
- output->display( input = name = `` ).
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
+ out->write( data = name = `` ).
**********************************************************************
- output->next_section( `8) Field Symbols in the Context of Processing a Structure` ).
+ out->write( zcl_demo_abap_aux=>heading( `8) Field Symbols in the Context of Processing a Structure` ) ).
"In this example, all components of a structure are processed using
"field symbols and an ASSIGN COMPONENT ... OF STRUCTURE ... statement.
@@ -460,7 +483,7 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DO.
"sy-index represents the position of a structure component
- ASSIGN -(sy-index) to .
+ ASSIGN -(sy-index) TO .
"Old syntax
"ASSIGN COMPONENT sy-index OF STRUCTURE TO .
@@ -469,16 +492,17 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"If all components are processed, the loop is exited.
EXIT.
ELSE.
- output->display( |sy-index: { sy-index }, component content:| ).
- output->display( ).
+ out->write( |sy-index: { sy-index }, component content:| ).
+ out->write( ).
+ out->write( |\n| ).
ENDIF.
ENDDO.
**********************************************************************
- output->next_section( `Data references` ).
- output->display( `9) Declaring Data References` ).
+ out->write( zcl_demo_abap_aux=>heading( `Data references` ) ).
+ out->write( |9) Declaring Data References\n\n| ).
"Like field symbols, data reference variables can be declared with both
"a complete and a generic data type using DATA statements and the
@@ -497,12 +521,12 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ref_a5 TYPE ref_type,
ref_a6 TYPE REF TO data. "Generic data type
- output->display( `No output for this section. See the code.` ).
+ out->write( `No output for this section. See the code.` ).
**********************************************************************
- output->next_section( `10) Creating Data References ` &&
- `to Existing Data Objects` ).
+ out->write( zcl_demo_abap_aux=>heading( `10) Creating Data References ` &&
+ `to Existing Data Objects` ) ).
"The example includes data reference variables with both complete and
"generic type. When using the REF operator, the '#' sign means that the
@@ -528,11 +552,11 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"You can explicitly specify the data type after REF.
"DATA(ref_b3) = REF #( g ).
- output->display( `No output for this section. See the code.` ).
+ out->write( `No output for this section. See the code.` ).
**********************************************************************
- output->next_section( `11) Dynamically Creating Data Objects at Runtime Using Static Type Definitions` ).
+ out->write( zcl_demo_abap_aux=>heading( `11) Dynamically Creating Data Objects at Runtime Using Static Type Definitions` ) ).
"The example code shows the creation of anonymous data objects. They
"can be created using the statement CREATE DATA, the instance operator
@@ -601,7 +625,7 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DATA(dref_c6) = NEW zdemo_abap_carr( carrid = 'AB' carrname = 'AB Airlines' ).
"ABAP SQL SELECT statements
- "Using the NEW addition in the INTO clause, an anonymous data object
+ "Using the NEW addition in the INTO clause, an anonymous data object
"can be created in place.
SELECT *
FROM zdemo_abap_carr
@@ -613,13 +637,15 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
WHERE carrid = 'LH'
INTO NEW @DATA(dref_c8). "Structure
- output->display( input = dref_c6->* name = `dref_c6->*` ).
- output->display( input = dref_c7->* name = `dref_c7->*` ).
- output->display( input = dref_c8->* name = `dref_c8->*` ).
+ out->write( data = dref_c6->* name = `dref_c6->*` ).
+ out->write( |\n| ).
+ out->write( data = dref_c7->* name = `dref_c7->*` ).
+ out->write( |\n| ).
+ out->write( data = dref_c8->* name = `dref_c8->*` ).
**********************************************************************
- output->next_section( `12) Data References and Assignments` ).
+ out->write( zcl_demo_abap_aux=>heading( `12) Data References and Assignments` ) ).
"Regarding the assignment, note that static types of both data
"reference variables must be compatible. As a result of an assignment,
@@ -667,13 +693,15 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ref_d5 ?= ref_data_d2.
- output->display( input = ref_d2->* name = `ref_d2->*` ).
- output->display( input = ref_data_d1->* name = `ref_data_d1->*` ).
- output->display( input = ref_d5->* name = `ref_d5->*` ).
+ out->write( data = ref_d2->* name = `ref_d2->*` ).
+ out->write( |\n| ).
+ out->write( data = ref_data_d1->* name = `ref_data_d1->*` ).
+ out->write( |\n| ).
+ out->write( data = ref_d5->* name = `ref_d5->*` ).
**********************************************************************
- output->next_section( `13) Addressing Data References ` ).
+ out->write( zcl_demo_abap_aux=>heading( `13) Addressing Data References ` ) ).
"Before addressing the content of data objects a data reference points
"to, you must dereference data reference variables. Use the
@@ -697,29 +725,35 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"Variable receives the content.
DATA(some_num) = ref_e1->*.
- output->display( input = ref_e1->* name = `ref_e1->*` ).
+ out->write( data = ref_e1->* name = `ref_e1->*` ).
+ out->write( |\n| ).
"Content of referenced data object is changed
ref_e1->* = 10.
- output->display( input = ref_e1->* name = `ref_e1->*` ).
+ out->write( data = ref_e1->* name = `ref_e1->*` ).
+ out->write( |\n| ).
"Data reference used in a logical expression
IF ref_e1->* > 5.
- output->display( `The value of ref_e1 is greater than 5.` ).
+ out->write( `The value of ref_e1 is greater than 5.` ).
ELSE.
- output->display( `The value of ref_e1 is lower than 5.` ).
+ out->write( `The value of ref_e1 is lower than 5.` ).
ENDIF.
+ out->write( |\n| ).
+
"Dereferenced generic type
DATA(calc) = 1 + ref_data_e->*.
- output->display( input = calc name = `calc` ).
+ out->write( data = calc name = `calc` ).
+ out->write( |\n| ).
"Complete structure
DATA(struc) = ref_e2->*.
- output->display( input = ref_e2->* name = `ref_e2->*` ).
+ out->write( data = ref_e2->* name = `ref_e2->*` ).
+ out->write( |\n| ).
"Individual structure component
"When dereferencing a data reference variable that has a structured
@@ -728,17 +762,19 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ref_e2->carrid = 'UA'.
- output->display( input = ref_e2->carrid name = `ref_e2->carrid` ).
+ out->write( data = ref_e2->carrid name = `ref_e2->carrid` ).
+ out->write( |\n| ).
"The following syntax also works (dereferencing operator and the component selector).
ref_e2->*-carrname = 'United Airlines'.
- output->display( input = ref_e2->*-carrname name = `ref_e2->*-carrname` ).
+ out->write( data = ref_e2->*-carrname name = `ref_e2->*-carrname` ).
+ out->write( |\n| ).
**********************************************************************
- output->next_section( `14) Checking if Data Reference ` &&
- `Can Be Dereferenced` ).
+ out->write( zcl_demo_abap_aux=>heading( `14) Checking if Data Reference ` &&
+ `Can Be Dereferenced` ) ).
"You can check if a data reference can be dereferenced by using
"a logical expression with IS [NOT] BOUND.
@@ -748,20 +784,22 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DATA ref_f2 TYPE REF TO i.
IF ref_f1 IS BOUND.
- output->display( `ref_f1 is bound.` ).
+ out->write( `ref_f1 is bound.` ).
ELSE.
- output->display( `ref_f1 is not bound.` ).
+ out->write( `ref_f1 is not bound.` ).
ENDIF.
+ out->write( |\n| ).
+
IF ref_f2 IS BOUND.
- output->display( `ref_f2 is bound.` ).
+ out->write( `ref_f2 is bound.` ).
ELSE.
- output->display( `ref_f2 is not bound.` ).
+ out->write( `ref_f2 is not bound.` ).
ENDIF.
**********************************************************************
- output->next_section( `15) Explicitly Removing a Reference` ).
+ out->write( zcl_demo_abap_aux=>heading( `15) Explicitly Removing a Reference` ) ).
"Note that the garbage collector takes care of removing the references
"automatically once the data is not used any more by a reference.
@@ -769,34 +807,40 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DATA(ref_g1) = NEW string( `hello` ).
IF ref_g1 IS INITIAL.
- output->display( `Before CLEAR: ref_g1 is initial.` ).
+ out->write( `Before CLEAR: ref_g1 is initial.` ).
ELSE.
- output->display( `Before CLEAR: ref_g1 is not intial.` ).
+ out->write( `Before CLEAR: ref_g1 is not intial.` ).
ENDIF.
+ out->write( |\n| ).
+
IF ref_g1 IS BOUND.
- output->display( `Before CLEAR: ref_g1 is bound.` ).
+ out->write( `Before CLEAR: ref_g1 is bound.` ).
ELSE.
- output->display( `Before CLEAR: ref_g1 is not bound.` ).
+ out->write( `Before CLEAR: ref_g1 is not bound.` ).
ENDIF.
+ out->write( |\n| ).
+
CLEAR ref_g1.
IF ref_g1 IS INITIAL.
- output->display( `After CLEAR: ref_g1 is initial.` ).
+ out->write( `After CLEAR: ref_g1 is initial.` ).
ELSE.
- output->display( `After CLEAR: ref_g1 is not initial.` ).
+ out->write( `After CLEAR: ref_g1 is not initial.` ).
ENDIF.
+ out->write( |\n| ).
+
IF ref_g1 IS BOUND.
- output->display( `After CLEAR: ref_g1 is bound.` ).
+ out->write( `After CLEAR: ref_g1 is bound.` ).
ELSE.
- output->display( `After CLEAR: ref_g1 is not bound.` ).
+ out->write( `After CLEAR: ref_g1 is not bound.` ).
ENDIF.
**********************************************************************
- output->next_section( `16) Overwriting Data Reference Variables` ).
+ out->write( zcl_demo_abap_aux=>heading( `16) Overwriting Data Reference Variables` ) ).
"A data reference variable is overwritten if a new object is created
"with a data reference variable already pointing to a data object
@@ -805,15 +849,16 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ref_h1 = NEW i( 111 ).
- output->display( input = ref_h1->* name = `ref_h1->*` ).
+ out->write( data = ref_h1->* name = `ref_h1->*` ).
+ out->write( |\n| ).
ref_h1 = NEW string( `ref_h1 overwritten.` ).
- output->display( input = ref_h1->* name = `ref_h1->*` ).
+ out->write( data = ref_h1->* name = `ref_h1->*` ).
**********************************************************************
- output->next_section( `17) Retaining Data References` ).
+ out->write( zcl_demo_abap_aux=>heading( `17) Retaining Data References` ) ).
"Storing data reference variables in an internal table using
"TYPE TABLE OF REF TO prevents the overwriting.
@@ -838,15 +883,16 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
itab_i = VALUE #( BASE itab_i ( ref_data_i ) ).
ENDDO.
- output->display( input = itab_i name = `itab_i` ).
- output->display( input = `The derefenced value of the data reference - which ` &&
+ out->write( data = itab_i name = `itab_i` ).
+ out->write( |\n| ).
+ out->write( data = `The derefenced value of the data reference - which ` &&
`was changed in the course of the loop - in the second table ` &&
`entry is ` && itab_i[ 2 ]->* && `.` ).
**********************************************************************
- output->next_section( `18) Processing Internal Tables Using ` &&
- `Data References ` ).
+ out->write( zcl_demo_abap_aux=>heading( `18) Processing Internal Tables Using ` &&
+ `Data References ` ) ).
"Similar use case to using field symbols: In a loop across an internal table,
"you can store the content of the line in a data reference variable
@@ -870,12 +916,12 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ref_k->distid = 'KM' .
ENDLOOP.
- output->display( input = flsch_tab name = `flsch_tab` ).
+ out->write( data = flsch_tab name = `flsch_tab` ).
**********************************************************************
- output->next_section( `19) Data References as Part of ` &&
- `Structures and Internal Tables` ).
+ out->write( zcl_demo_abap_aux=>heading( `19) Data References as Part of ` &&
+ `Structures and Internal Tables` ) ).
"In contrast to field symbols, data reference variables can be used as
"components of structures or columns in internal tables.
@@ -894,7 +940,8 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"Filling structure
struc_l = VALUE #( number_l = 1 ref_l = NEW #( 2 ) ).
- output->display( input = struc_l ).
+ out->write( data = struc_l ).
+ out->write( |\n| ).
"Declaring an internal table
DATA itab_l LIKE TABLE OF struc_l WITH EMPTY KEY.
@@ -911,12 +958,12 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
itab_l = VALUE #( BASE itab_l ( struc_l ) ).
ENDDO.
- output->display( input = itab_l name = `itab_l` ).
+ out->write( data = itab_l name = `itab_l` ).
**********************************************************************
- output->next_section( `Dynamic ABAP Statements` ).
- output->display( `20) Dynamic Specifications in ASSIGN Statements (1) - Attributes of Classes/Interfaces` ).
+ out->write( zcl_demo_abap_aux=>heading( `Dynamic ABAP Statements` ) ).
+ out->write( |20) Dynamic Specifications in ASSIGN Statements (1) - Attributes of Classes/Interfaces\n\n| ).
"The following examples demonstrate a selection of various dynamic specifications
"that are possible with ASSIGN statements.
@@ -927,17 +974,22 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ASSIGN lcl_det_at_runtime=>(dobj_name) TO FIELD-SYMBOL().
- output->display( |Data object name determined at runtime: { dobj_name } | ).
- output->display( |The content of the data object is: { } | ).
+ out->write( |Data object name determined at runtime: { dobj_name } | ).
+ out->write( |\n| ).
+ out->write( |The content of the data object is: { } | ).
+ out->write( |\n| ).
+ out->write( |\n| ).
dobj_name = lcl_det_at_runtime=>get_dyn_dobj( ).
"Completely dynamic assign
ASSIGN ('lcl_det_at_runtime')=>(dobj_name) TO FIELD-SYMBOL().
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
ASSIGN ('zdemo_abap_objects_interface')=>('const_intf') TO FIELD-SYMBOL().
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
"Class/interface reference variables pointing to an object that contains attributes
"and that are specified dynamically.
@@ -947,15 +999,16 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ASSIGN iref->('const_intf') TO FIELD-SYMBOL().
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
ASSIGN cl_ref->('another_string') TO FIELD-SYMBOL().
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
**********************************************************************
- output->next_section( `21) Dynamic Specifications in ASSIGN Statements (2) - Setting sy-subrc/ELSE UNASSIGN` ).
+ out->write( zcl_demo_abap_aux=>heading( `21) Dynamic Specifications in ASSIGN Statements (2) - Setting sy-subrc/ELSE UNASSIGN` ) ).
"In dynamic assignments, the statement ASSIGN sets the return code sy-subrc.
"If ELSE UNASSIGN is specified, no memory area is assigned to the field symbol. It has the state unassigned after the ASSIGN statement.
@@ -966,24 +1019,29 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ASSIGN cl_ref->(attribute) TO FIELD-SYMBOL() ELSE UNASSIGN.
IF sy-subrc = 0.
- output->display( |Successful assignment for attribute "{ attribute }". sy-subrc = { sy-subrc }. | ).
- output->display( input = name = `` ).
+ out->write( |Successful assignment for attribute "{ attribute }". sy-subrc = { sy-subrc }. | ).
+ out->write( |\n| ).
+ out->write( data = name = `` ).
ELSE.
- output->display( |Assignment not successful for attribute "{ attribute }". sy-subrc = { sy-subrc }. | ).
+ out->write( |Assignment not successful for attribute "{ attribute }". sy-subrc = { sy-subrc }. | ).
ENDIF.
+ out->write( |\n| ).
+
IF IS ASSIGNED.
- output->display( `The field symbol is assigned.` ).
- output->display( `--------------------` ).
+ out->write( `The field symbol is assigned.` ).
+ out->write( `--------------------` ).
ELSE.
- output->display( `The field symbol is not assigned.` ).
+ out->write( `The field symbol is not assigned.` ).
ENDIF.
+ out->write( |\n| ).
+
ENDLOOP.
**********************************************************************
- output->next_section( `22) Dynamic Specifications in ASSIGN Statements (3) - Structure Components` ).
+ out->write( zcl_demo_abap_aux=>heading( `22) Dynamic Specifications in ASSIGN Statements (3) - Structure Components` ) ).
"Dynamic specification of structure components that are assigned to a field symbol.
@@ -1025,19 +1083,27 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ASSIGN ref_m->('CARRNAME') TO FIELD-SYMBOL().
- output->display( input = name = `` ).
- output->display( input = name = `` ).
- output->display( input = subrc1 name = `subrc1` ).
- output->display( input = subrc2 name = `subrc2` ).
- output->display( input = name = `` ).
- output->display( input = name = `` ).
- output->display( input = name = `` ).
- output->display( input = name = `` ).
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
+ out->write( data = subrc1 name = `subrc1` ).
+ out->write( |\n| ).
+ out->write( data = subrc2 name = `subrc2` ).
+ out->write( |\n| ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
+ out->write( data = name = `` ).
**********************************************************************
- output->next_section( `23) Dynamic Specifications in ASSIGN Statements (4) - Type Casting` ).
+ out->write( zcl_demo_abap_aux=>heading( `23) Dynamic Specifications in ASSIGN Statements (4) - Type Casting` ) ).
"As covered above, the CASTING addition of the ASSIGN statement
"has dynamic syntax elements.
@@ -1048,12 +1114,12 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"A text literal with the name of a type is specified within the parentheses.
ASSIGN dobj_c_l5 TO CASTING TYPE ('DTYPE_C_L2').
- output->display( input = name = `` ).
+ out->write( data = name = `` ).
**********************************************************************
- output->next_section( `Dynamically Creating Data Objects at Runtime Using Dynamic Type Definitions` ).
- output->display( `24) Miscellaneous Data Objects (1)` ).
+ out->write( zcl_demo_abap_aux=>heading( `Dynamically Creating Data Objects at Runtime Using Dynamic Type Definitions` ) ).
+ out->write( |24) Miscellaneous Data Objects (1)\n\n| ).
"In an example above, anonymous data objects are created using static
"type definitions. In this example, anonymous data objects are created
@@ -1080,63 +1146,72 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DATA some_structure TYPE zdemo_abap_carr.
LOOP AT type_names REFERENCE INTO DATA(refwa).
- output->display( |***** Loop iteration { sy-tabix }. Type: { refwa->* } *****| ).
+ out->write( |***** Loop iteration { sy-tabix }. Type: { refwa->* } *****| ).
CASE refwa->*.
WHEN `I`.
CREATE DATA dataref TYPE (refwa->*).
dataref->* = 123.
- output->display( input = dataref->* name = `dataref->*` ).
+ out->write( data = dataref->* name = `dataref->*` ).
+ out->write( |\n| ).
CREATE DATA dataref TYPE TABLE OF (refwa->*).
INSERT 1 INTO TABLE dataref->*.
INSERT 2 INTO TABLE dataref->*.
- output->display( input = dataref->* name = `dataref->*` ).
+ out->write( data = dataref->* name = `dataref->*` ).
+ out->write( |\n| ).
CREATE DATA dataref TYPE REF TO (refwa->*).
dataref->* = REF i( 456 ).
- output->display( input = dataref->* name = `dataref->*` ).
+ out->write( data = dataref->* name = `dataref->*` ).
+ out->write( |\n| ).
WHEN `STRING`.
CREATE DATA dataref TYPE (refwa->*).
dataref->* = `hello`.
- output->display( input = dataref->* name = `dataref->*` ).
+ out->write( data = dataref->* name = `dataref->*` ).
+ out->write( |\n| ).
CREATE DATA dataref TYPE TABLE OF (refwa->*).
INSERT `hello` INTO TABLE dataref->*.
INSERT `abap` INTO TABLE dataref->*.
- output->display( input = dataref->* name = `dataref->*` ).
+ out->write( data = dataref->* name = `dataref->*` ).
+ out->write( |\n| ).
CREATE DATA dataref TYPE REF TO (refwa->*).
dataref->* = REF string( `hi` ).
- output->display( input = dataref->* name = `dataref->*` ).
+ out->write( data = dataref->* name = `dataref->*` ).
+ out->write( |\n| ).
WHEN `ZDEMO_ABAP_CARR`.
CREATE DATA dataref TYPE (refwa->*).
SELECT SINGLE * FROM zdemo_abap_carr INTO @dataref->*.
- output->display( input = dataref->* name = `dataref->*` ).
+ out->write( data = dataref->* name = `dataref->*` ).
+ out->write( |\n| ).
CREATE DATA dataref TYPE TABLE OF (refwa->*).
SELECT * FROM zdemo_abap_carr INTO TABLE @dataref->* UP TO 3 ROWS.
- output->display( input = dataref->* name = `dataref->*` ).
+ out->write( data = dataref->* name = `dataref->*` ).
+ out->write( |\n| ).
CREATE DATA dataref TYPE REF TO (refwa->*).
SELECT SINGLE * FROM zdemo_abap_carr INTO NEW @dataref->*.
- output->display( input = dataref->* name = `dataref->*` ).
+ out->write( data = dataref->* name = `dataref->*` ).
+ out->write( |\n| ).
ENDCASE.
ENDLOOP.
**********************************************************************
- output->next_section( `25) Elementary Data Object (2)` ).
+ out->write( zcl_demo_abap_aux=>heading( `25) Elementary Data Object (2)` ) ).
"The example demonstrates the following:
"- The method call takes care of providing the name of a built-in data type and more
@@ -1159,24 +1234,27 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
WHEN 'p'.
CREATE DATA ref_bt TYPE p LENGTH b_type-len DECIMALS b_type-dec.
WHEN OTHERS.
- output->display( `That didn't work.` ).
+ out->write( `That didn't work.` ).
ENDCASE.
"Getting type information using RTTI
DATA(descr_builtin_type) = CAST cl_abap_elemdescr(
cl_abap_typedescr=>describe_by_data( ref_bt->* ) ).
- output->display( |Built-in type determined at runtime: { b_type-builtin_type } | ).
- output->display( `Created data object at runtime:` ).
- output->display( input = descr_builtin_type name = `descr_builtin_type` ).
+ out->write( |Built-in type determined at runtime: { b_type-builtin_type } | ).
+ out->write( |\n| ).
+ out->write( `Type information of created data object at runtime:` ).
+ out->write( |\n| ).
+ out->write( |\n| ).
+ out->write( data = descr_builtin_type name = `descr_builtin_type` ).
CATCH cx_root.
- output->display( `Something went wrong.` ).
+ out->write( `Something went wrong.` ).
ENDTRY.
**********************************************************************
- output->next_section( `26) Structure (3)` ).
+ out->write( zcl_demo_abap_aux=>heading( `26) Structure (3)` ) ).
"The example demonstrates the following:
"- The method call takes care of providing the name of a database table name.
@@ -1198,12 +1276,14 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
FROM (type4struc)
INTO @ref_dynstruc->*.
- output->display( |Structured data type/database table name determined at runtime: { type4struc } | ).
- output->display( input = ref_dynstruc->* name = `ref_dynstruc->*` ).
+ out->write( |Structured data type/database table name determined at runtime: { type4struc } | ).
+ out->write( |\n| ).
+ out->write( |\n| ).
+ out->write( data = ref_dynstruc->* name = `ref_dynstruc->*` ).
**********************************************************************
- output->next_section( `27) Internal Table (4)` ).
+ out->write( zcl_demo_abap_aux=>heading( `27) Internal Table (4)` ) ).
"The example demonstrates the following:
"- The method call takes care of providing the name of a database table name.
@@ -1232,13 +1312,16 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
INTO TABLE @ref_n->*
UP TO @random_upto ROWS.
- output->display( |Table/type name determined at runtime: { type_name } | ).
- output->display( |At most, { random_upto } lines should have been read from the database table.| ).
- output->display( input = ref_n->* name = `ref_n->*` ).
+ out->write( |Table/type name determined at runtime: { type_name } | ).
+ out->write( |\n| ).
+ out->write( |At most, { random_upto } lines should have been read from the database table.| ).
+ out->write( |\n| ).
+ out->write( |\n| ).
+ out->write( data = ref_n->* name = `ref_n->*` ).
**********************************************************************
- output->next_section( `28) Excursion: Absolute Type Names for Dynamically Specifying Types` ).
+ out->write( zcl_demo_abap_aux=>heading( `28) Excursion: Absolute Type Names for Dynamically Specifying Types` ) ).
"In addition to character-like data objects for the type name specified within the
"parentheses, you can also use absolute type names for statements such as CREATE DATA.
@@ -1265,12 +1348,12 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"Unnamed data object
CREATE OBJECT oref4abs TYPE ('\CLASS=ZCL_DEMO_ABAP_DYNAMIC_PROG').
- output->display( `No output for this section. See the code.` ).
+ out->write( `No output for this section. See the code.` ).
**********************************************************************
- output->next_section( `Dynamically Specifying Components/Clauses in Statements for Processing Internal Tables with ...` ).
- output->display( `29) SORT` ).
+ out->write( zcl_demo_abap_aux=>heading( `Dynamically Specifying Components/Clauses in Statements for Processing Internal Tables with ...` ) ).
+ out->write( |29) SORT\n\n| ).
"A field is determined at runtime on whose basis a sorting is done on an
"internal table.
@@ -1285,13 +1368,15 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
SORT carr_itab BY (field_name).
- output->display( |Field name determined at runtime | &&
+ out->write( |Field name determined at runtime | &&
|by which the sorting was done: { field_name } | ).
- output->display( input = carr_itab name = `carr_itab` ).
+ out->write( |\n| ).
+ out->write( |\n| ).
+ out->write( data = carr_itab name = `carr_itab` ).
**********************************************************************
- output->next_section( `30) READ TABLE` ).
+ out->write( zcl_demo_abap_aux=>heading( `30) READ TABLE` ) ).
"Dynamic key specification in READ TABLE statements
@@ -1318,21 +1403,27 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
WITH KEY (wa_comps-comp) = wa_comps-value.
IF sy-subrc = 0.
- output->display( input = wa_comps-comp name = `wa_comps-comp` ).
- output->display( input = wa_comps-value name = `wa_comps-value` ).
- output->display( input = read_line name = `read_line` ).
+ out->write( data = wa_comps-comp name = `wa_comps-comp` ).
+ out->write( |\n| ).
+ out->write( data = wa_comps-value name = `wa_comps-value` ).
+ out->write( |\n| ).
+ out->write( data = read_line name = `read_line` ).
+ out->write( |\n| ).
CLEAR read_line.
ELSE.
- output->display( input = wa_comps-comp name = `wa_comps-comp` ).
- output->display( input = wa_comps-value name = `wa_comps-value` ).
- output->display( `Line not found.` ).
+ out->write( data = wa_comps-comp name = `wa_comps-comp` ).
+ out->write( |\n| ).
+ out->write( data = wa_comps-value name = `wa_comps-value` ).
+ out->write( |\n| ).
+ out->write( `Line not found.` ).
+ out->write( |\n| ).
ENDIF.
ENDLOOP.
**********************************************************************
- output->next_section( `31) MODIFY` ).
+ out->write( zcl_demo_abap_aux=>heading( `31) MODIFY` ) ).
"Dynamic WHERE condition in MODIFY statements
"Note:
@@ -1352,8 +1443,10 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
( col1 = 'B' col2 = 10 )
( col1 = 'C' col2 = 100 ) ).
- output->display( `Internal table content before modifications:` ).
- output->display( input = itab_mod_tab_dyn name = `itab_mod_tab_dyn` ).
+ out->write( `Internal table content before modifications:` ).
+ out->write( |\n| ).
+ out->write( data = itab_mod_tab_dyn name = `itab_mod_tab_dyn` ).
+ out->write( |\n| ).
"Providing conditions for MODIFY statement
DATA(conditions) = VALUE string_table( ( `col2 < 5` )
@@ -1371,16 +1464,17 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
WHERE (condition).
CATCH cx_sy_itab_dyn_loop.
- output->display( |Invalid WHERE condition "{ condition }".| ).
+ out->write( |Invalid WHERE condition "{ condition }".| ).
ENDTRY.
ENDLOOP.
- output->display( `Internal table content after modifications:` ).
- output->display( input = itab_mod_tab_dyn name = `itab_mod_tab_dyn` ).
+ out->write( `Internal table content after modifications:` ).
+ out->write( |\n| ).
+ out->write( data = itab_mod_tab_dyn name = `itab_mod_tab_dyn` ).
**********************************************************************
- output->next_section( `32) DELETE` ).
+ out->write( zcl_demo_abap_aux=>heading( `32) DELETE` ) ).
"Dynamic WHERE condition in DELETE statements
@@ -1394,8 +1488,10 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
( 500 )
( 600 ) ).
- output->display( `Internal table content before modifications:` ).
- output->display( input = itab_del_tab_dyn name = `itab_del_tab_dyn` ).
+ out->write( `Internal table content before modifications:` ).
+ out->write( |\n| ).
+ out->write( data = itab_del_tab_dyn name = `itab_del_tab_dyn` ).
+ out->write( |\n| ).
DO 3 TIMES.
TRY.
@@ -1413,17 +1509,19 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
USING KEY skey
WHERE (condition).
- output->display( |Condition: { condition }| ).
- output->display( input = itab_del_tab_dyn name = `itab_del_tab_dyn` ).
-
+ out->write( |Condition: { condition }| ).
+ out->write( |\n| ).
+ out->write( data = itab_del_tab_dyn name = `itab_del_tab_dyn` ).
+ out->write( |\n| ).
CATCH cx_sy_itab_dyn_loop.
- output->display( |Invalid WHERE condition "{ condition }".| ).
+ out->write( |Invalid WHERE condition "{ condition }".| ).
+ out->write( |\n| ).
ENDTRY.
ENDDO.
**********************************************************************
- output->next_section( `33) LOOP` ).
+ out->write( zcl_demo_abap_aux=>heading( `33) LOOP` ) ).
"Dynamic specification of the key in LOOP statements
"In the example, the loop can be executed with the entries 'skey' and 'primary_key'.
@@ -1445,16 +1543,18 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
APPEND wa_lo TO itab_dyn_key.
ENDLOOP.
- output->display( |Loop over internal table using key "{ k }".| ).
- output->display( input = itab_dyn_key name = `itab_dyn_key` ).
+ out->write( |Loop over internal table using key "{ k }".| ).
+ out->write( |\n| ).
+ out->write( data = itab_dyn_key name = `itab_dyn_key` ).
+ out->write( |\n| ).
CLEAR itab_dyn_key.
ENDLOOP.
**********************************************************************
- output->next_section( `Dynamically Specifying Clauses in ABAP SQL SELECT Statements` ).
- output->display( `34) SELECT List` ).
+ out->write( zcl_demo_abap_aux=>heading( `Dynamically Specifying Clauses in ABAP SQL SELECT Statements` ) ).
+ out->write( |34) SELECT List\n\n| ).
"In the example, the SELECT list that is used in a SELECT statement is
"determined at runtime.
@@ -1471,12 +1571,14 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
INTO CORRESPONDING FIELDS OF TABLE @sel_table
UP TO 3 ROWS.
- output->display( |SELECT list determined at runtime: { select_list } | ).
- output->display( input = sel_table name = `sel_table` ).
+ out->write( |SELECT list determined at runtime: { select_list } | ).
+ out->write( |\n| ).
+ out->write( |\n| ).
+ out->write( data = sel_table name = `sel_table` ).
**********************************************************************
- output->next_section( `35) FROM Clause` ).
+ out->write( zcl_demo_abap_aux=>heading( `35) FROM Clause` ) ).
"In the example, the FROM clause that is used in a SELECT statement is
"determined at runtime. Here, the number of entries of a database table
@@ -1488,12 +1590,13 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
FROM (tab_name)
INTO @DATA(count).
- output->display( |Table name determined at runtime: { tab_name } | ).
- output->display( |The table { tab_name } has { count } entries.| ).
+ out->write( |Table name determined at runtime: { tab_name } | ).
+ out->write( |\n| ).
+ out->write( |The table { tab_name } has { count } entries.| ).
**********************************************************************
- output->next_section( `36) WHERE Clause` ).
+ out->write( zcl_demo_abap_aux=>heading( `36) WHERE Clause` ) ).
"In the example, the WHERE clause that is used in a SELECT statement is
"determined at runtime. Here, the WHERE clause is based on a string
@@ -1508,14 +1611,18 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
INTO TABLE @DATA(where_tab)
UP TO 5 ROWS.
- output->display( |WHERE clause determined at runtime:| ).
- output->display( input = where_clause name = `where_clause` ).
- output->display( input = where_tab name = `where_tab` ).
+ out->write( |WHERE clause determined at runtime:| ).
+ out->write( |\n| ).
+ out->write( data = where_clause name = `where_clause` ).
+ out->write( |\n| ).
+ out->write( |\n| ).
+ out->write( data = where_tab name = `where_tab` ).
**********************************************************************
- output->next_section( `37a) Excursion: Multiple Dynamically Specified ` &&
- `Clauses in an ABAP SQL SELECT Statement` ).
+ out->write( zcl_demo_abap_aux=>heading( `37a) Excursion: Multiple Dynamically Specified ` &&
+ `Clauses in an ABAP SQL SELECT Statement` ) ).
+
"In this example, multiple clauses in a SELECT statement are
"determined at runtime to demonstrate the rich variety of possibilities.
@@ -1534,8 +1641,10 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
AND dyn_syntax_elem-target IS BOUND
AND dyn_syntax_elem-rows IS NOT INITIAL.
- output->display( `Dynamically determined syntax elements:` ).
- output->display( input = dyn_syntax_elem name = `dyn_syntax_elem` ).
+ out->write( `Dynamically determined syntax elements:` ).
+ out->write( |\n| ).
+ out->write( data = dyn_syntax_elem name = `dyn_syntax_elem` ).
+ out->write( |\n| ).
SELECT (dyn_syntax_elem-select_list)
FROM (dyn_syntax_elem-table)
@@ -1544,15 +1653,15 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
INTO CORRESPONDING FIELDS OF TABLE @dyn_syntax_elem-target->*
UP TO @dyn_syntax_elem-rows ROWS.
- output->display( input = dyn_syntax_elem-target->* name = `dyn_syntax_elem-target->*` ).
+ out->write( data = dyn_syntax_elem-target->* name = `dyn_syntax_elem-target->*` ).
ELSE.
- output->display( `There's an issue with syntax elements.` ).
+ out->write( `There's an issue with syntax elements.` ).
ENDIF.
**********************************************************************
- output->next_section( `37b) Excursion: Checking the validity of dynamic specifications` ).
+ out->write( zcl_demo_abap_aux=>heading( `37b) Excursion: Checking the validity of dynamic specifications` ) ).
"The following example uses the CL_ABAP_DYN_PRG class, which supports
"dynamic programming by checking the validity of dynamic specifications.
"Check out the class documentation for more information.
@@ -1582,17 +1691,22 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
SELECT SINGLE * FROM (dbtab) INTO NEW @DATA(ref_wa).
- output->display( |Result for { wa_tab }| ).
- output->display( ref_wa->* ).
+ out->write( |Result for { wa_tab }:| ).
+ out->write( |\n| ).
+ out->write( |\n| ).
+ out->write( ref_wa->* ).
+ out->write( |\n| ).
CATCH cx_abap_not_a_table cx_abap_not_in_package INTO DATA(err).
- output->display( |Result for { wa_tab }| ).
- output->display( err->get_text( ) ).
+ out->write( |Result for { wa_tab }:| ).
+ out->write( |\n| ).
+ out->write( err->get_text( ) ).
+ out->write( |\n| ).
ENDTRY.
ENDLOOP.
**********************************************************************
- output->next_section( `38) Dynamic Invoke` ).
+ out->write( zcl_demo_abap_aux=>heading( `38) Dynamic Invoke` ) ).
"In the example, both class and method are determined at runtime for
"the method call. The suitable parameter table is filled in the
@@ -1606,11 +1720,14 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
CALL METHOD (cl_name)=>(meth_name) PARAMETER-TABLE p_tab.
- output->display( |Class name determined at runtime: { cl_name } | ).
- output->display( |Method name determined at runtime: { meth_name } | ).
+ out->write( |Class name determined at runtime: { cl_name } | ).
+ out->write( |\n| ).
+ out->write( |Method name determined at runtime: { meth_name } | ).
+ out->write( |\n| ).
- output->display( `Result of method call (text stored in a variable):` ).
- output->display( input = lcl_det_at_runtime=>dyn_meth_call_result name = `lcl_det_at_runtime=>dyn_meth_call_result` ).
+ out->write( `Result of method call (text stored in a variable):` ).
+ out->write( |\n| ).
+ out->write( data = lcl_det_at_runtime=>dyn_meth_call_result name = `lcl_det_at_runtime=>dyn_meth_call_result` ).
"Further method calls
"The class and method to be used is determined here by just providing
@@ -1623,17 +1740,18 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"displayed to see the effect of the dynamic method call.
CALL METHOD lcl_det_at_runtime=>(method).
- output->display( input = lcl_det_at_runtime=>dyn_meth_call_result name = `lcl_det_at_runtime=>dyn_meth_call_result` ).
+ out->write( data = lcl_det_at_runtime=>dyn_meth_call_result name = `lcl_det_at_runtime=>dyn_meth_call_result` ).
+ out->write( |\n| ).
DATA class TYPE string VALUE `LCL_DET_AT_RUNTIME`.
CALL METHOD (class)=>fill_string.
- output->display( input = lcl_det_at_runtime=>dyn_meth_call_result name = `lcl_det_at_runtime=>dyn_meth_call_result` ).
+ out->write( data = lcl_det_at_runtime=>dyn_meth_call_result name = `lcl_det_at_runtime=>dyn_meth_call_result` ).
**********************************************************************
- output->next_section( `39) RTTI: Getting Type Information at Runtime/Getting a Reference to a Type Description Object` ).
+ out->write( zcl_demo_abap_aux=>heading( `39) RTTI: Getting Type Information at Runtime/Getting a Reference to a Type Description Object` ) ).
"Getting a reference to a type description object of a type.
"i.e. getting an instance of a type description class
@@ -1660,7 +1778,7 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
cl_abap_typedescr=>describe_by_name( 'ELEM_TYPE' ) ).
"You may also want to check the type description object in the debugger.
- output->display( input = type_descr_obj_elem_inl name = `type_descr_obj_elem_inl` ).
+ out->write( data = type_descr_obj_elem_inl name = `type_descr_obj_elem_inl` ).
"Various methods/attributes (note that they vary depending on the type) provide
"you with detailed information.
@@ -1670,9 +1788,12 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DATA(type_kind_elem) = type_descr_obj_elem_inl->type_kind.
DATA(output_length_elem) = type_descr_obj_elem_inl->output_length.
- output->display( input = kind_elem name = `kind_elem` ).
- output->display( input = type_kind_elem name = `type_kind_elem` ).
- output->display( input = output_length_elem name = `output_length_elem` ).
+ out->write( data = kind_elem name = `kind_elem` ).
+ out->write( |\n| ).
+ out->write( data = type_kind_elem name = `type_kind_elem` ).
+ out->write( |\n| ).
+ out->write( data = output_length_elem name = `output_length_elem` ).
+ out->write( |\n| ).
"In the following example, the type properties are retrieved
"without casting. The data object has the type ref to
@@ -1688,8 +1809,10 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
TYPES another_elem_type TYPE n LENGTH 3.
DATA(type_descr_obj_elem_inl_2) = cl_abap_typedescr=>describe_by_name( 'ANOTHER_ELEM_TYPE' ).
- output->display( input = type_descr_obj_elem_inl_2->kind name = `type_descr_obj_elem_inl_2->kind` ).
- output->display( input = type_descr_obj_elem_inl_2->type_kind name = `type_descr_obj_elem_inl_2->type_kind` ).
+ out->write( data = type_descr_obj_elem_inl_2->kind name = `type_descr_obj_elem_inl_2->kind` ).
+ out->write( |\n| ).
+ out->write( data = type_descr_obj_elem_inl_2->type_kind name = `type_descr_obj_elem_inl_2->type_kind` ).
+ out->write( |\n| ).
"More types
"Structured data type (here, using the name of a database table)
@@ -1708,10 +1831,14 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"Kind of structure
DATA(struct_kind) = type_descr_obj_struc->struct_kind.
- output->display( input = struc_kind name = `struc_kind` ).
- output->display( input = comps_struc name = `comps_struc` ).
- output->display( input = comps_struc2 name = `comps_struc2` ).
- output->display( input = struct_kind name = `struct_kind` ).
+ out->write( data = struc_kind name = `struc_kind` ).
+ out->write( |\n| ).
+ out->write( data = comps_struc name = `comps_struc` ).
+ out->write( |\n| ).
+ out->write( data = comps_struc2 name = `comps_struc2` ).
+ out->write( |\n| ).
+ out->write( data = struct_kind name = `struct_kind` ).
+ out->write( |\n| ).
"Internal table type
TYPES table_type TYPE SORTED TABLE OF zdemo_abap_carr WITH UNIQUE KEY carrid.
@@ -1731,10 +1858,14 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DATA(tab_comps) = CAST cl_abap_structdescr(
type_descr_obj_tab->get_table_line_type( ) )->get_components( ).
- output->display( input = tab_kind name = `tab_kind` ).
- output->display( input = tab_keys name = `tab_keys` ).
- output->display( input = tab_keys2 name = `tab_keys2` ).
- output->display( input = tab_comps name = `tab_comps` ).
+ out->write( data = tab_kind name = `tab_kind` ).
+ out->write( |\n| ).
+ out->write( data = tab_keys name = `tab_keys` ).
+ out->write( |\n| ).
+ out->write( data = tab_keys2 name = `tab_keys2` ).
+ out->write( |\n| ).
+ out->write( data = tab_comps name = `tab_comps` ).
+ out->write( |\n| ).
"Reference type
TYPES ref_str TYPE REF TO string.
@@ -1752,10 +1883,13 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DATA(ref_type_type_kind) =
type_descr_obj_ref->get_referenced_type( )->type_kind.
- output->display( input = ref_kind name = `ref_kind` ).
- output->display( input = ref_type name = `ref_type` ).
- output->display( input = ref_type_abs_name name = `ref_type_abs_name` ).
- output->display( input = ref_type_type_kind name = `ref_type_type_kind` ).
+ out->write( data = ref_kind name = `ref_kind` ).
+ out->write( |\n| ).
+ out->write( data = ref_type name = `ref_type` ).
+ out->write( |\n| ).
+ out->write( data = ref_type_abs_name name = `ref_type_abs_name` ).
+ out->write( |\n| ).
+ out->write( data = ref_type_type_kind name = `ref_type_type_kind` ).
"Getting a reference to a type description object of an existing data object.
"Instead of referring to the name of a type, referring to a data object here.
@@ -1783,7 +1917,7 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
**********************************************************************
- output->next_section( `40) RTTI: Getting Type Information at Runtime for Miscellaneous Types` ).
+ out->write( zcl_demo_abap_aux=>heading( `40) RTTI: Getting Type Information at Runtime for Miscellaneous Types` ) ).
"The example demonstrates RTTI as follows:
"- The method call takes care of providing the name of a type. It is implemented
@@ -1806,7 +1940,8 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"Retrieving type
DATA(get_type) = lcl_det_at_runtime=>get_random_type( ).
- output->display( |Type name determined at runtime: { get_type }| ).
+ out->write( |Type name determined at runtime: { get_type }| ).
+ out->write( |\n| ).
DATA dref TYPE REF TO data.
@@ -1815,7 +1950,7 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
TRY.
CREATE DATA dref TYPE (get_type).
CATCH cx_sy_create_data_error.
- output->display( `Create data error!` ).
+ out->write( `Create data error!` ).
ENDTRY.
"Retrieving type information
@@ -1825,35 +1960,48 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"Elementary type
IF some_type->kind = cl_abap_typedescr=>kind_elem.
DATA(el) = CAST cl_abap_elemdescr( some_type ).
- output->display( input = el name = `el` ).
+ out->write( data = el name = `el` ).
"Various attributes and methods possible
- output->display( input = el->type_kind name = `el->type_kind` ).
- output->display( input = el->absolute_name name = `el->absolute_name` ).
- output->display( input = el->get_relative_name( ) name = `el->get_relative_name( )` ).
+ out->write( data = el->type_kind name = `el->type_kind` ).
+ out->write( |\n| ).
+ out->write( data = el->absolute_name name = `el->absolute_name` ).
+ out->write( |\n| ).
+ out->write( data = el->get_relative_name( ) name = `el->get_relative_name( )` ).
+ out->write( |\n| ).
"Structure
ELSEIF some_type->kind = cl_abap_typedescr=>kind_struct.
DATA(stru) = CAST cl_abap_structdescr( some_type ).
- output->display( input = stru->absolute_name name = `stru->absolute_name` ).
- output->display( input = stru->components name = `stru->components` ).
- output->display( input = stru->struct_kind name = `stru->struct_kind` ).
- output->display( input = stru->get_components( ) name = `stru->get_components( )` ).
+ out->write( data = stru->absolute_name name = `stru->absolute_name` ).
+ out->write( |\n| ).
+ out->write( data = stru->components name = `stru->components` ).
+ out->write( |\n| ).
+ out->write( data = stru->struct_kind name = `stru->struct_kind` ).
+ out->write( |\n| ).
+ out->write( data = stru->get_components( ) name = `stru->get_components( )` ).
+ out->write( |\n| ).
"Internal table
ELSEIF some_type->kind = cl_abap_typedescr=>kind_table.
DATA(tab) = CAST cl_abap_tabledescr( some_type ).
- output->display( input = tab->absolute_name name = `tab->absolute_name` ).
- output->display( input = tab->table_kind name = `tab->table_kind` ).
- output->display( input = tab->get_keys( ) name = `tab->get_keys` ).
- output->display( input = tab->get_table_line_type( ) name = `tab->get_table_line_type( )` ).
+ out->write( data = tab->absolute_name name = `tab->absolute_name` ).
+ out->write( |\n| ).
+ out->write( data = tab->table_kind name = `tab->table_kind` ).
+ out->write( |\n| ).
+ out->write( data = tab->get_keys( ) name = `tab->get_keys` ).
+ out->write( |\n| ).
+ out->write( data = tab->get_table_line_type( ) name = `tab->get_table_line_type( )` ).
+ out->write( |\n| ).
"Reference
ELSEIF some_type->kind = cl_abap_typedescr=>kind_ref.
DATA(ref_descr) = CAST cl_abap_refdescr( some_type ).
- output->display( input = ref_descr->absolute_name name = `ref_descr->absolute_name` ).
- output->display( input = ref_descr->get_referenced_type( ) name = `ref_descr->get_referenced_type( )` ).
+ out->write( data = ref_descr->absolute_name name = `ref_descr->absolute_name` ).
+ out->write( |\n| ).
+ out->write( data = ref_descr->get_referenced_type( ) name = `ref_descr->get_referenced_type( )` ).
+ out->write( |\n| ).
ELSE.
- output->display( `Others ...` ).
+ out->write( `Others ...` ).
ENDIF.
ELSE.
@@ -1865,9 +2013,12 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
"Class
IF some_type->kind = cl_abap_typedescr=>kind_class.
DATA(class_desc) = CAST cl_abap_classdescr( some_type ).
- output->display( input = class_desc->absolute_name name = `class_desc->absolute_name` ).
- output->display( input = class_desc->attributes name = `class_desc->attributes` ).
- output->display( input = class_desc->methods name = `class_desc->methods` ).
+ out->write( data = class_desc->absolute_name name = `class_desc->absolute_name` ).
+ out->write( |\n| ).
+ out->write( data = class_desc->attributes name = `class_desc->attributes` ).
+ out->write( |\n| ).
+ out->write( data = class_desc->methods name = `class_desc->methods` ).
+ out->write( |\n| ).
"Creating an object based on a type determined at runtime
DATA oref TYPE REF TO object.
@@ -1876,25 +2027,29 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
CREATE OBJECT oref TYPE (get_type).
"Retrieving type information
DATA(descr_ref) = cl_abap_typedescr=>describe_by_object_ref( oref ).
- output->display( input = descr_ref->absolute_name name = `descr_ref->absolute_name` ).
- output->display( input = descr_ref->kind name = `descr_ref->kind` ).
+ out->write( data = descr_ref->absolute_name name = `descr_ref->absolute_name` ).
+ out->write( |\n| ).
+ out->write( data = descr_ref->kind name = `descr_ref->kind` ).
+ out->write( |\n| ).
CATCH cx_root.
- output->display( `Error` ).
+ out->write( `Error` ).
ENDTRY.
"Interface
ELSEIF some_type->kind = cl_abap_typedescr=>kind_intf.
DATA(if_descr) = CAST cl_abap_intfdescr( some_type ).
- output->display( input = if_descr->absolute_name name = `if_descr->absolute_name` ).
- output->display( input = if_descr->methods name = `class_desc->methods` ).
+ out->write( data = if_descr->absolute_name name = `if_descr->absolute_name` ).
+ out->write( |\n| ).
+ out->write( data = if_descr->methods name = `class_desc->methods` ).
+ out->write( |\n| ).
ELSE.
- output->display( `Others ...` ).
+ out->write( `Others ...` ).
ENDIF.
ENDIF.
**********************************************************************
- output->next_section( `41) RTTC: Dynamically Creating Data Types at Runtime` ).
+ out->write( zcl_demo_abap_aux=>heading( `41) RTTC: Dynamically Creating Data Types at Runtime` ) ).
"You can create data types at program runtime using methods of the type
"description classes of RTTS. These types are only valid locally in the
@@ -1989,11 +2144,11 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DATA(tdo_ref_3) = cl_abap_refdescr=>get_by_name( 'T' ).
DATA(tdo_ref_4) = cl_abap_refdescr=>get_by_name( 'ZCL_DEMO_ABAP_DYNAMIC_PROG' ).
- output->display( `No output for this section. See the code.` ).
+ out->write( `No output for this section. See the code.` ).
**********************************************************************
- output->next_section( `42) Dynamically Creating Data Objects at Runtime Using Type Description Objects (1) - Miscellaneous` ).
+ out->write( zcl_demo_abap_aux=>heading( `42) Dynamically Creating Data Objects at Runtime Using Type Description Objects (1) - Miscellaneous` ) ).
"Using the TYPE HANDLE addition to CREATE DATA statements, you can
"dynamically create data objects at runtime based on type description objects.
@@ -2006,7 +2161,8 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
CREATE DATA dref_typ_obj TYPE HANDLE tdo_elem_i.
dref_typ_obj->* = 5 + 4.
- output->display( input = dref_typ_obj->* name = `dref_typ_obj->*` ).
+ out->write( data = dref_typ_obj->* name = `dref_typ_obj->*` ).
+ out->write( |\n| ).
"Structured data object
CREATE DATA dref_typ_obj TYPE HANDLE tdo_struc.
@@ -2015,23 +2171,25 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
dref_typ_obj->('C') = 'abcde'.
dref_typ_obj->('D') = '1.234'.
- output->display( input = dref_typ_obj->* name = `dref_typ_obj->*` ).
+ out->write( data = dref_typ_obj->* name = `dref_typ_obj->*` ).
+ out->write( |\n| ).
"Internal table
CREATE DATA dref_typ_obj TYPE HANDLE tdo_tab_2.
SELECT * FROM zdemo_abap_flsch INTO TABLE @dref_typ_obj->* UP TO 3 ROWS.
- output->display( input = dref_typ_obj->* name = `dref_typ_obj->*` ).
+ out->write( data = dref_typ_obj->* name = `dref_typ_obj->*` ).
+ out->write( |\n| ).
"Reference
CREATE DATA dref_typ_obj TYPE HANDLE tdo_ref_3.
dref_typ_obj->* = NEW t( '120000' ).
- output->display( input = dref_typ_obj->* name = `dref_typ_obj->*` ).
+ out->write( data = dref_typ_obj->* name = `dref_typ_obj->*` ).
**********************************************************************
- output->next_section( `43) Dynamically Creating Data Objects at Runtime Using Type Description Objects (2) - Structure` ).
+ out->write( zcl_demo_abap_aux=>heading( `43) Dynamically Creating Data Objects at Runtime Using Type Description Objects (2) - Structure` ) ).
"This example includes the dynamic definition of a structure with three components
"using the GET method of the CL_ABAP_STRUCTDESCR class.
@@ -2083,11 +2241,11 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
dref_struc->(column2) = 'def'.
dref_struc->(column3) = 'ghi'.
- output->display( input = dref_struc->* name = `dref_struc->*` ).
+ out->write( data = dref_struc->* name = `dref_struc->*` ).
**********************************************************************
- output->next_section( `44) Dynamically Creating Data Objects at Runtime Using Type Description Objects (3) - Internal Table` ).
+ out->write( zcl_demo_abap_aux=>heading( `44) Dynamically Creating Data Objects at Runtime Using Type Description Objects (3) - Internal Table` ) ).
"In the example an internal table type is created based on a DDIC type.
"See the comments in the code.
@@ -2139,9 +2297,12 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
INTO CORRESPONDING FIELDS OF TABLE @ref_tab->*
UP TO 3 ROWS.
- output->display( |Type/Database table name determined at runtime: { table_name }| ).
- output->display( |Internal table entries (ordered by { dyn_order_by }):| ).
- output->display( input = ref_tab->* name = `ref_tab->*` ).
+ out->write( |Type/Database table name determined at runtime: { table_name }| ).
+ out->write( |\n| ).
+ out->write( |Internal table entries (ordered by { dyn_order_by }):| ).
+ out->write( |\n| ).
+ out->write( |\n| ).
+ out->write( data = ref_tab->* name = `ref_tab->*` ).
ENDMETHOD.
-ENDCLASS.
\ No newline at end of file
+ENDCLASS.
diff --git a/src/zcl_demo_abap_flight_tables.clas.xml b/src/zcl_demo_abap_flight_tables.clas.xml
deleted file mode 100644
index 84a3247..0000000
--- a/src/zcl_demo_abap_flight_tables.clas.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
- ZCL_DEMO_ABAP_FLIGHT_TABLES
- E
- Class for ABAP cheat sheet examples
- 1
- X
- X
- X
-
-
-
-
diff --git a/src/zcl_demo_abap_internal_tables.clas.abap b/src/zcl_demo_abap_internal_tables.clas.abap
index ef822c7..9cd04df 100644
--- a/src/zcl_demo_abap_internal_tables.clas.abap
+++ b/src/zcl_demo_abap_internal_tables.clas.abap
@@ -106,1659 +106,16 @@ CLASS zcl_demo_abap_internal_tables DEFINITION
fill_itabs_for_corresponding.
ENDCLASS.
-CLASS zcl_demo_abap_internal_tables IMPLEMENTATION.
- METHOD if_oo_adt_classrun~main.
- DATA(output) = NEW zcl_demo_abap_display( out ).
+CLASS ZCL_DEMO_ABAP_INTERNAL_TABLES IMPLEMENTATION.
- output->display( `ABAP Cheat Sheet Example: Internal Tables` ).
- output->display( `Filling and Copying Internal Table Content` ).
- output->display( `1) Adding single lines using APPEND/INSERT` ).
-
- "Two internal tables, a standard and sorted internal table.
- "Both have the same line type and one field as (non-)unique key.
- DATA it_st TYPE TABLE OF struc1 WITH NON-UNIQUE KEY a.
- DATA it_so TYPE SORTED TABLE OF struc1 WITH UNIQUE KEY a.
-
- "APPEND
- "Standard table
- APPEND VALUE #( a = 1 b = 'aaa' c = 'bbb' d = 'ccc' ) TO it_st.
-
- "A line is created and filled to be used for the APPEND statement.
- "The line type matches the line type of the internal table.
- DATA(line) = VALUE struc1( a = 2 b = 'd' c = 'e' d = 'f' ).
-
- "Sorted table
- "APPEND works here with a sorted table. At this stage, the
- "internal table is empty, so there is no issue (lines are only
- "appended if they match the sort order and do not create
- "duplicate entries if the primary table key is unique).
- APPEND line TO it_so.
-
- "INSERT
- "INSERT has same effect as APPEND with standard tables
- INSERT VALUE #( a = 2 b = 'ddd' c = 'eee' d = 'fff' )
- INTO TABLE it_st.
-
- INSERT VALUE #( a = 1 b = 'a' c = 'b' d = 'c' ) INTO TABLE it_so.
-
- output->display( input = it_st name = `it_st` ).
- output->display( input = it_so name = `it_so` ).
-
-**********************************************************************
-
- output->next_section( `2) Adding initial line` ).
-
- APPEND INITIAL LINE TO it_st.
-
- INSERT INITIAL LINE INTO TABLE it_so.
-
- output->display( input = it_st name = `it_st` ).
- output->display( input = it_so name = `it_so` ).
-
-**********************************************************************
-
- output->next_section( `3) Adding mutliple lines of an internal table to` &&
- ` another one` ).
-
- "No additions: All lines are added to the target internal table
- APPEND LINES OF it_so TO it_st.
-
- "Creating a new itab and filling it.
- DATA it_so2 LIKE it_so.
-
- INSERT VALUE #( a = 3 b = 'g' c = 'h' d = 'i' ) INTO TABLE it_so2.
-
- INSERT VALUE #( a = 4 b = 'j' c = 'k' d = 'l' ) INTO TABLE it_so2.
-
- "Inserting all lines of previously created internal table.
- INSERT LINES OF it_so2 INTO TABLE it_so.
-
- output->display( input = it_st name = `it_st` ).
- output->display( input = it_so name = `it_so` ).
-
-**********************************************************************
-
- output->next_section( `4) Adding lines of an internal table to` &&
- ` another one by specifying the index range.` ).
-
- "When using only FROM, all lines are respected until the final
- "table entry. When using only TO, all lines are respected
- "starting from the first table entry.
- APPEND LINES OF it_so FROM 2 TO 3 TO it_st.
-
- INSERT LINES OF it_so FROM 3 INTO TABLE it_st.
-
- APPEND LINES OF it_so TO 2 TO it_st.
-
- output->display( input = it_st name = `it_st` ).
-
-**********************************************************************
-
- output->next_section( `5) Inserting lines of an internal table` &&
- ` into another one at a specific position` ).
-
- "Inserting a single line
- INSERT VALUE #( a = 10 b = 'ggg' c = 'hhh' d = 'iii' )
- INTO it_st INDEX 1.
-
- "Inserting multiple lines
- INSERT LINES OF it_so2 INTO it_st INDEX 2.
-
- output->display( input = it_st name = `it_st` ).
-
-**********************************************************************
-
- output->next_section( `6) Adding lines using constructor expressions` ).
-
- "Creating a line to be added to an internal table.
- line = VALUE #( a = 1 b = 'aaa' c = 'bbb' d = 'ccc' ).
-
- "Table on the right is constructed inline using VALUE and assigned
- "Note: This way, existing table content is cleared.
- it_st = VALUE #( ( line )
- ( a = 2 b = 'ddd' c = 'eee' d = 'fff' ) ).
-
- output->display( input = it_st name = `it_st` ).
-
-**********************************************************************
-
- output->next_section( `7) Creating a new table inline and adding lines` &&
- ` using a constructor expression` ).
-
- "Internal table type
- TYPES it_type LIKE it_st.
-
- "Creating an internal table inline and filling in one go
- DATA(it_st2) = VALUE it_type( ( a = 3 b = 'ggg'
- c = 'hhh' d = 'iii' )
- ( a = 4 b = 'jjj'
- c = 'kkk' d = 'lll' ) ).
-
- output->display( input = it_st2 name = `it_st2` ).
-
-**********************************************************************
-
- output->next_section( `8) Adding lines using constructor expressions ` &&
- `and keeping existing table content` ).
-
- "BASE addition: existing table content is not removed
- it_st = VALUE #( BASE it_st ( a = 5 b = 'mmm' c = 'nnn' d = 'ooo' )
- ( a = 6 b = 'ppp' c = 'qqq' d = 'rrr' )
- ).
-
- output->display( input = it_st name = `it_st` ).
-
-**********************************************************************
-
- output->next_section( `9) Adding lines from other internal tables using` &&
- ` constructor expressions` ).
-
- "With LINES OF itab specified within the pair of parentheses,
- "all lines of the internal table are added; here, in the same
- "expression another line is added as well
- it_st = VALUE #( BASE it_st ( LINES OF it_st2 )
- ( a = 7 b = 'sss' c = 'ttt' d = 'uuu' )
- ).
-
- output->display( input = it_st name = `it_st` ).
-
-**********************************************************************
-
- output->next_section( `10) Copying table content (without constructor ` &&
- `expression)` ).
-
- "Assignment of a table to another one having a matching line type
- it_st = it_st2.
-
- output->display( input = it_st name = `it_st` ).
-
-**********************************************************************
-
- output->next_section( `11) CORRESPONDING Operator and MOVE-CORRESPONDING` ).
- output->display( `Internal table content before assignments` ).
-
- "Note: Before the following statements, the table content is reset
- "to this state to work with the same set of values.
- fill_itabs_for_corresponding( ).
-
- output->display( input = tab1 name = `tab1` ).
- output->display( input = tab2 name = `tab2` ).
- output->display( input = tab3 name = `tab3` ).
- output->display( input = tab4 name = `tab4` ).
-
-**********************************************************************
-
- output->next_section( `Copying content from another table that has ` &&
- `a different line type ...` ).
- output->display( `12) ... and deleting existing table content ` &&
- `using the CORRESPONDING operator` ).
-
- tab1 = CORRESPONDING #( tab2 ).
-
- output->display( input = tab1 name = `tab1` ).
-
- fill_itabs_for_corresponding( ).
-
-**********************************************************************
-
- output->next_section( `13) ... and deleting existing table content ` &&
- `using MOVE-CORRESPONDING` ).
-
- MOVE-CORRESPONDING tab2 TO tab1.
-
- output->display( input = tab1 name = `tab1` ).
-
- fill_itabs_for_corresponding( ).
-
-**********************************************************************
-
- output->next_section( `14) ... and keeping existing table ` &&
- `content using the CORRESPONDING operator` ).
-
- tab1 = CORRESPONDING #( BASE ( tab1 ) tab2 ).
-
- output->display( input = tab1 name = `tab1` ).
-
- fill_itabs_for_corresponding( ).
-
-**********************************************************************
-
- output->next_section( `15) ... and keeping existing table ` &&
- `content using MOVE-CORRESPONDING` ).
-
- MOVE-CORRESPONDING tab2 TO tab1 KEEPING TARGET LINES.
-
- output->display( input = tab1 name = `tab1` ).
-
- fill_itabs_for_corresponding( ).
-
-**********************************************************************
-
- output->next_section( `16) ... respecting component ` &&
- `mapping` ).
-
- "Specifying components of a source table that are assigned to the
- "components of a target table in mapping relationships
- tab1 = CORRESPONDING #( tab2 MAPPING c = e d = f ).
-
- output->display( input = tab1 name = `tab1` ).
-
- fill_itabs_for_corresponding( ).
-
-**********************************************************************
-
- output->next_section( `17) ... excluding components` ).
-
- "Excluding components from the assignment
- tab1 = CORRESPONDING #( tab2 EXCEPT b ).
-
- output->display( input = tab1 name = `tab1` ).
-
-**********************************************************************
-
- output->next_section( `18) ... excluding components and using MAPPING` ).
-
- "EXCEPT * means that all components remain initial not specified
- "for mapping
- tab1 = CORRESPONDING #( tab2 MAPPING d = f EXCEPT * ).
-
- output->display( input = tab1 name = `tab1` ).
-
- fill_itabs_for_corresponding( ).
-
-**********************************************************************
-
- output->next_section( `19) ... discarding duplicates` ).
-
- "Preventing runtime errors if duplicate lines are assigned to
- "target table that is defined to only accept unique keys.
- "Note: Other tables than above are used here.
- tab3 = CORRESPONDING #( BASE ( tab3 ) tab4 DISCARDING DUPLICATES ).
-
- output->display( input = tab3 name = `tab3` ).
-
- fill_itabs_for_corresponding( ).
-
- tab3 = CORRESPONDING #( BASE ( tab3 ) tab4 DISCARDING DUPLICATES
- MAPPING d = f EXCEPT b ).
-
- output->display( input = tab3 name = `tab3` ).
-
-**********************************************************************
-
- output->next_section( `20) Copying data from a deep ` &&
- `internal table to another deep internal table` ).
- output->display( `Original table content` ).
-
- output->display( input = itab_nested1 name = `itab_nested1` ).
- output->display( input = itab_nested2 name = `itab_nested2` ).
-
-**********************************************************************
-
- output->next_section( `21) ... deleting ` &&
- `existing content (CORRESPONDING operator)` ).
-
- itab_nested2 = CORRESPONDING #( DEEP itab_nested1 ).
-
- output->display( input = itab_nested2 name = `itab_nested2` ).
-
- fill_itabs_for_corresponding( ).
-
-**********************************************************************
-
- output->next_section( `22) ... deleting ` &&
- `existing content (MOVE-CORRESPONDING)` ).
-
- MOVE-CORRESPONDING itab_nested1 TO itab_nested2
- EXPANDING NESTED TABLES.
-
- output->display( input = itab_nested2 name = `itab_nested2` ).
-
- fill_itabs_for_corresponding( ).
-
-**********************************************************************
-
- output->next_section( `23) ... keeping ` &&
- `existing content (CORRESPONDING operator)` ).
-
- itab_nested2 = CORRESPONDING #( DEEP BASE ( itab_nested2 )
- itab_nested1 ).
-
- output->display( input = itab_nested2 name = `itab_nested2` ).
-
- fill_itabs_for_corresponding( ).
-
-**********************************************************************
-
- output->next_section( `24) ... keeping ` &&
- `existing content (MOVE-CORRESPONDING)` ).
-
- MOVE-CORRESPONDING itab_nested1 TO itab_nested2
- EXPANDING NESTED TABLES KEEPING TARGET LINES.
-
- output->display( input = itab_nested2 name = `itab_nested2` ).
-
-**********************************************************************
-
- output->next_section( `Filling internal tables: Excursions` ).
- output->display( `25) Selecting multiple rows from a database ` &&
- `table into an internal table` ).
-
- SELECT FROM zdemo_abap_tab1
- FIELDS key_field, char1, char2, num1, num2
- WHERE num1 > 3
- INTO TABLE @DATA(itab_select1).
-
- output->display( input = itab_select1 name = `itab_select1` ).
-
-**********************************************************************
-
- output->next_section( `26) Sequentially adding multiple rows from ` &&
- `a database table to an internal table` ).
-
- DATA itab TYPE TABLE OF zdemo_abap_tab1 WITH NON-UNIQUE KEY client key_field.
-
- SELECT FROM zdemo_abap_tab1
- FIELDS *
- WHERE num1 > 3
- INTO @DATA(struc_select).
-
- IF sy-subrc = 0.
- "Some modifications on the read lines (capitalizing letters)
- struc_select-char1 = to_upper( struc_select-char1 ).
- struc_select-char2 = to_upper( struc_select-char2 ).
-
- "Adding modified line to an internal table
- APPEND struc_select TO itab.
- ENDIF.
- ENDSELECT.
-
- output->display( input = itab name = `itab` ).
-
-**********************************************************************
-
- output->next_section( `27) Adding multiple rows from a database table ` &&
- `to an internal table that has a different line type than the ` &&
- `database table and keeping existing table content` ).
-
- SELECT FROM zdemo_abap_tab2
- FIELDS *
- WHERE num1 > 10
- APPENDING CORRESPONDING FIELDS OF TABLE @itab.
-
- output->display( input = itab name = `itab` ).
-
-**********************************************************************
-
- output->next_section( `28) Adding multiple rows from a database table ` &&
- `to an internal table that has a different line type than the ` &&
- `database table and deleting existing table content` ).
-
- SELECT FROM zdemo_abap_tab2
- FIELDS *
- WHERE num1 > 10
- INTO CORRESPONDING FIELDS OF TABLE @itab.
-
- output->display( input = itab name = `itab` ).
-
-**********************************************************************
-
- output->next_section( `29) Adding multiple rows from an internal table ` &&
- `to an internal table using SELECT` ).
-
- SELECT key_field, char1, char2, num1, num2
- FROM @itab AS itab_alias
- INTO TABLE @DATA(itab_clone).
-
- output->display( input = itab_clone name = `itab_clone` ).
-
-**********************************************************************
-
- output->next_section( `30) Combining data of multiple tables into an` &&
- ` internal table using an inner join` ).
-
- "Filling table to be selected from
- itab = VALUE #( ( key_field = 500 char1 = 'uuu' char2 = 'vvv'
- num1 = 501 num2 = 502 )
- ( key_field = 600 char1 = 'www' char2 = 'xxx'
- num1 = 601 num2 = 602 ) ).
-
- "SELECT list includes fields from both tables
- "If there are no equivalent entries in the first or second table,
- "the rows are not joined.
- SELECT itab_alias1~key_field, itab_alias1~char2,
- zdemo_abap_tab2~numlong
- FROM @itab AS itab_alias1
- INNER JOIN zdemo_abap_tab2
- ON itab_alias1~key_field = zdemo_abap_tab2~key_field
- INTO TABLE @DATA(join_result).
-
- output->display( input = join_result name = `join_result` ).
-
-**********************************************************************
-
- output->next_section( `31) Filling internal table ` &&
- `using a subquery (1)` ).
-
- "A subquery is specified in the WHERE clause
- "Here, data is selected from a database table depending on
- "whether the value of a certain field is not among the
- "values specified in parentheses.
- SELECT key_field, char1, numlong
- FROM zdemo_abap_tab2
- WHERE char1 NOT IN ( 'iii', 'mmm', 'ooo', 'ppp' )
- INTO TABLE @DATA(subquery_result1).
-
- output->display( input = subquery_result1 name = `subquery_result1` ).
-
-**********************************************************************
-
- output->next_section( `32) Filling internal table ` &&
- `using a subquery (2)` ).
-
- "A subquery using EXISTS in the WHERE clause.
- "In the example, data is selected from a database table depending
- "on the existence of data in an internal table. Only if a line
- "with a matching value of the specified field exists in both
- "database and internal table, data is read.
- SELECT key_field, numlong
- FROM zdemo_abap_tab2
- WHERE EXISTS
- ( SELECT 'X' FROM @itab AS itab_alias2
- WHERE key_field = zdemo_abap_tab2~key_field )
- INTO TABLE @DATA(subquery_result2).
-
- output->display( input = subquery_result2 name = `subquery_result2` ).
-
-**********************************************************************
-
- output->next_section( `33) Filling an internal table from a table ` &&
- `depending on the existence of data in another internal table ` &&
- `using the addition FOR ALL ENTRIES` ).
-
- "In the example, data is selected from a database table depending
- "on the existence of data in an internal table. Only if a line
- "with a matching value of the specified field exists in both
- "database and internal table, data is read.
- "Ensure that the internal table from which to read is not initial.
- IF ( 0 < lines( itab ) ).
- SELECT key_field, char1, numlong
- FROM zdemo_abap_tab2
- FOR ALL ENTRIES IN @itab
- WHERE key_field = @itab-key_field
- INTO TABLE @DATA(select_result).
- ENDIF.
-
- output->display( input = select_result name = `select_result` ).
-
-**********************************************************************
-
- output->next_section( `34) Adding content from a database to internal` &&
- ` table by using alias names in the SELECT list` ).
-
- DATA itab2 TYPE TABLE OF zdemo_abap_tab2 WITH EMPTY KEY.
-
- "Specifying alias names can help fill an existing internal
- "table that has not a matching line type to the database table.
- "Here, two fields are specified with an alias name to match the
- "names of components contained in the existing internal table.
- "The individual types of the fields match, too.
- SELECT key_field, char2 AS char1, num2 AS num1
- FROM zdemo_abap_tab1
- INTO CORRESPONDING FIELDS OF TABLE @itab2 UP TO 3 ROWS.
-
- output->display( input = itab2 name = `itab2` ).
-
-**********************************************************************
-
- output->next_section( `35) FILTER: Filtering internal table by condition` ).
-
- "This section covers multiple examples demonstrating the syntactical variety
- "of the FILTER operator.
-
- TYPES: BEGIN OF fi_str,
- a TYPE i,
- b TYPE c LENGTH 3,
- c TYPE c LENGTH 3,
- END OF fi_str.
-
- "basic form, condition created with single values
- "itab must have at least one sorted key or one hash key used for access.
- "This variant of the filter operator is not possible for an internal table itab without a sorted key or hash key.
- DATA fi_tab1 TYPE SORTED TABLE OF fi_str WITH NON-UNIQUE KEY a.
- DATA fi_tab2 TYPE STANDARD TABLE OF fi_str WITH NON-UNIQUE SORTED KEY sec_key COMPONENTS a.
- DATA fi_tab3 TYPE HASHED TABLE OF fi_str WITH UNIQUE KEY a.
-
- "Filling internal tables
- fi_tab1 = VALUE #( ( a = 1 b = 'aaa' c = 'abc' )
- ( a = 2 b = 'bbb' c = 'def' )
- ( a = 3 b = 'ccc' c = 'hij' )
- ( a = 4 b = 'ddd' c = 'klm' )
- ( a = 5 b = 'eee' c = 'nop' ) ).
-
- fi_tab2 = fi_tab1.
- fi_tab3 = fi_tab1.
-
- "The lines meeting the condition are respected.
- "Note: The source table must have at least one sorted or hashed key.
- "Here, the primary key is used
- DATA(f1) = FILTER #( fi_tab1 WHERE a >= 3 ).
-
- output->display( input = f1 name = `f1` ).
-
- "USING KEY primary_key explicitly specified; same as above
- DATA(f2) = FILTER #( fi_tab1 USING KEY primary_key WHERE a >= 3 ).
-
- output->display( input = f2 name = `f2` ).
-
- "EXCEPT addition
- DATA(f3) = FILTER #( fi_tab1 EXCEPT WHERE a >= 3 ).
-
- output->display( input = f3 name = `f3` ).
-
- DATA(f4) = FILTER #( fi_tab1 EXCEPT USING KEY primary_key WHERE a >= 3 ).
-
- output->display( input = f4 name = `f4` ).
-
- "Secondary table key specified after USING KEY
- DATA(f5) = FILTER #( fi_tab2 USING KEY sec_key WHERE a >= 4 ).
-
- output->display( input = f5 name = `f5` ).
-
- DATA(f6) = FILTER #( fi_tab2 EXCEPT USING KEY sec_key WHERE a >= 3 ).
-
- output->display( input = f6 name = `f6` ).
-
- "Note: In case of a hash key, exactly one comparison expression for each key
- "component is allowed; only = as comparison operator possible.
- DATA(f7) = FILTER #( fi_tab3 WHERE a = 3 ).
-
- output->display( input = f7 name = `f7` ).
-
- "Using a filter table
- "In the WHERE condition, the columns of source and filter table are compared.
- "Those lines in the source table are used for which at least one line in the
- "filter table meets the condition. EXCEPT and USING KEY are also possible.
-
- "Declaring and filling filter tables
- DATA filter_tab1 TYPE SORTED TABLE OF i
- WITH NON-UNIQUE KEY table_line.
-
- DATA filter_tab2 TYPE STANDARD TABLE OF i
- WITH EMPTY KEY
- WITH UNIQUE SORTED KEY line COMPONENTS table_line.
-
- filter_tab1 = VALUE #( ( 3 ) ( 5 ) ).
- filter_tab2 = filter_tab1.
-
- DATA(f8) = FILTER #( fi_tab1 IN filter_tab1 WHERE a = table_line ).
-
- output->display( input = f8 name = `f8` ).
-
- "EXCEPT addition
- DATA(f9) = FILTER #( fi_tab1 EXCEPT IN filter_tab1 WHERE a = table_line ).
-
- output->display( input = f9 name = `f9` ).
-
- "USING KEY is specified for the filter table
- DATA(f10) = FILTER #( fi_tab2 IN filter_tab2 USING KEY line WHERE a = table_line ).
-
- output->display( input = f10 name = `f10` ).
-
- "USING KEY is specified for the source table, including EXCEPT
- DATA(f11) = FILTER #( fi_tab2 USING KEY sec_key EXCEPT IN filter_tab2 WHERE a = table_line ).
-
- output->display( input = f11 name = `f11` ).
-
-**********************************************************************
-
- output->next_section( `36) Inserting data into an internal table ` &&
- `using a COLLECT statement` ).
-
- "Internal table to work with
- DATA itab_num TYPE SORTED TABLE OF l_type2
- WITH UNIQUE KEY key_field.
-
- itab_num = VALUE #( ( key_field = 1 num1 = 2 num2 = 3 )
- ( key_field = 2 num1 = 4 num2 = 5 )
- ( key_field = 3 num1 = 6 num2 = 7 ) ).
-
- "Values of numeric components are added to the
- "corresponding values in an internal table
- COLLECT VALUE l_type2( key_field = 1 num1 = 10 num2 = 10 )
- INTO itab_num.
-
- output->display( input = itab_num name = `itab_num` ).
-
-**********************************************************************
-
- output->next_section( `37) Reading from internal tables` ).
-
- "Filling internal tables
- it_st = VALUE #( ( a = 1 b = 'aaa' c = 'bbb' d = 'ccc' )
- ( a = 2 b = 'ddd' c = 'eee' d = 'fff' )
- ( a = 3 b = 'ggg' c = 'hhh' d = 'iii' )
- ( a = 4 b = 'jjj' c = 'kkk' d = 'lll' ) ).
-
- "Declaring demo sorted/hashed tables having primary and
- "secondary keys as well as alias names defined
- DATA it_so_sec TYPE SORTED TABLE OF struc1
- WITH NON-UNIQUE KEY primary_key ALIAS pk COMPONENTS a
- WITH NON-UNIQUE SORTED KEY sec_key ALIAS sk COMPONENTS b.
-
- DATA it_ha_sec TYPE HASHED TABLE OF struc1
- WITH UNIQUE KEY primary_key ALIAS pkh COMPONENTS a
- WITH NON-UNIQUE SORTED KEY sec_key_h ALIAS skh COMPONENTS b.
-
- "Filling internal table
- it_so_sec = VALUE #( ( a = 1 b = 'bbb' c = '###' d = '###' )
- ( a = 2 b = 'ccc' c = '###' d = '###' )
- ( a = 3 b = 'aaa' c = 'zzz' d = '###' )
- ( a = 4 b = 'ddd' c = '###' d = '###' ) ).
-
- "Filling internal table with the content above
- it_ha_sec = it_so_sec.
-
- output->display( `Original table content` ).
-
- output->display( input = it_so_sec name = `it_so_sec` ).
- output->display( input = it_ha_sec name = `it_ha_sec` ).
-
-**********************************************************************
-
- output->next_section( `38) Reading a single line into target area` ).
-
- "The examples anticipate the reading of a line by index since the
- "syntax requires to specify the reading via index or key. Both
- "inline declarations and existing target areas are demonstrated.
-
- "Work area
- READ TABLE it_so_sec INTO DATA(wa1) INDEX 1.
- DATA wa2 LIKE LINE OF it_so_sec.
-
- "The addition TRANSPORTING specifies which components are to be
- "respected for the copying. If it is not specified, all components
- "are respected.
- READ TABLE it_so_sec INTO wa2 INDEX 2 TRANSPORTING a b c.
-
- "Field symbol
- READ TABLE it_so_sec ASSIGNING FIELD-SYMBOL() INDEX 3.
-
- FIELD-SYMBOLS LIKE LINE OF it_so_sec.
- READ TABLE it_st ASSIGNING INDEX 1.
-
- "Data reference variable
- READ TABLE it_so_sec REFERENCE INTO DATA(dref) INDEX 4.
-
- DATA dref2 LIKE REF TO wa2.
- READ TABLE it_so_sec REFERENCE INTO dref2 INDEX 2.
-
- output->display( input = wa1 name = `wa1` ).
- output->display( input = wa2 name = `wa2` ).
- output->display( input = name = `` ).
- output->display( input = name = `` ).
- output->display( input = dref->* name = `dref->*` ).
- output->display( input = dref2->* name = `dref2->*` ).
-
-**********************************************************************
-
- output->next_section( `Reading a single line via index ...` ).
- output->display( `39) ... using READ TABLE` ).
-
- "Primary table index used implicitly
- READ TABLE it_so_sec INTO DATA(wa3) INDEX 1.
-
- "Primary table index used implicitly; result here: same as above
- READ TABLE it_so_sec INTO DATA(wa4) INDEX 1 USING KEY primary_key.
-
- "Primary table key alias; result here: same as above
- READ TABLE it_so_sec INTO DATA(wa5) INDEX 1 USING KEY pk.
-
- "Secondary table key; secondary table index used
- READ TABLE it_so_sec INTO DATA(wa6) INDEX 1 USING KEY sec_key.
-
- "Secondary table key alias; secondary table index used
- "result here: same as above
- READ TABLE it_so_sec INTO DATA(wa7) INDEX 1 USING KEY sk.
-
- "Index access for hashed tables using secondary table index
- READ TABLE it_ha_sec INTO DATA(wa8) INDEX 1 USING KEY sec_key_h.
-
- output->display( input = wa3 name = `wa3` ).
- output->display( input = wa4 name = `wa4` ).
- output->display( input = wa5 name = `wa5` ).
- output->display( input = wa6 name = `wa6` ).
- output->display( input = wa7 name = `wa7` ).
- output->display( input = wa8 name = `wa8` ).
-
-**********************************************************************
-
- output->next_section( `40) ... table expressions (1)` ).
-
- "Reading via index; primary table index is used implicitly
- DATA(lv1) = it_so_sec[ 2 ].
-
- "Note: A line that is not found results in an runtime error.
- DATA(idx) = 10.
-
- TRY.
- DATA(lv2) = it_so_sec[ idx ].
- CATCH cx_sy_itab_line_not_found.
- DATA(error) = |Line with index { idx } does not exist.|.
- ENDTRY.
-
- "Reading via index and specifying the table index (via the key)
- "to be read from
- DATA(lv3) = it_so_sec[ KEY primary_key INDEX 1 ].
-
- DATA(lv4) = it_so_sec[ KEY sec_key INDEX 4 ].
-
- "Hashed table example (secondary table index)
- DATA(lv5) = it_ha_sec[ KEY sec_key_h INDEX 3 ].
-
- output->display( input = lv1 name = `lv1` ).
-
- IF lv2 IS NOT INITIAL.
- output->display( input = lv2 name = `lv2` ).
- ENDIF.
-
- IF error IS NOT INITIAL.
- output->display( input = error name = `error` ).
- ENDIF.
-
- output->display( input = lv3 name = `lv3` ).
- output->display( input = lv4 name = `lv4` ).
- output->display( input = lv5 name = `lv5` ).
-
-**********************************************************************
-
- output->next_section( `41) ... table expressions (2)` ).
-
- "Copying a table line via table expression and embedding in
- "a constructor expression
- DATA(lv6) = VALUE #( it_so_sec[ 2 ] ).
-
- "Reading into data reference variable using the REF operator
- DATA(dref3) = REF #( it_so_sec[ 4 ] ).
-
- "OPTIONAL/DEFAULT additions: An unsuccessful reading operation
- "does not raise the exception; returns either an initial or
- "default line in case of an unsuccessful reading operation
- DATA(lv7) = VALUE #( it_so_sec[ 10 ] OPTIONAL ).
-
- DATA(lv8) = VALUE #( it_so_sec[ 10 ] DEFAULT it_so_sec[ 2 ] ).
-
- output->display( input = lv6 name = `lv6` ).
- output->display( input = dref3->* name = `dref3->*` ).
- output->display( input = lv7 name = `lv7` ).
- output->display( input = lv8 name = `lv8` ).
-
-**********************************************************************
-
- output->next_section( `Reading a single line via table keys ...` ).
- output->display( `42) ... using READ TABLE (1)` ).
-
- "Primary table key (COMPONENTS addition is optional)
- READ TABLE it_so_sec INTO DATA(wa9)
- WITH TABLE KEY primary_key COMPONENTS a = 1.
-
- READ TABLE it_so_sec INTO DATA(wa10) WITH TABLE KEY a = 2.
-
- "Primary table key alias
- READ TABLE it_so_sec INTO DATA(wa11)
- WITH TABLE KEY pk COMPONENTS a = 3.
-
- "Secondary table key
- READ TABLE it_so_sec INTO DATA(wa12)
- WITH TABLE KEY sec_key COMPONENTS b = 'ddd'.
-
- "Secondary table key alias
- READ TABLE it_so_sec INTO DATA(wa13)
- WITH TABLE KEY sk COMPONENTS b = 'ccc'.
-
- output->display( input = wa9 name = `wa9` ).
- output->display( input = wa10 name = `wa10` ).
- output->display( input = wa11 name = `wa11` ).
- output->display( input = wa12 name = `wa12` ).
- output->display( input = wa13 name = `wa13` ).
-
-**********************************************************************
-
- output->next_section( `43) ... using READ TABLE (2)` ).
-
- "Reading a line based on keys specified in a work area
- "Here, the work area contains primary and secondary key values.
- "The line type is compatible to the internal table.
- DATA(pr_keys) = VALUE struc1( a = 2 ).
-
- DATA(sec_keys) = VALUE struc1( b = 'aaa' ).
-
- "Primary table key is used implicitly
- READ TABLE it_so_sec FROM pr_keys INTO DATA(wa14).
-
- "If USING KEY is not specified, the primary table key is used.
- "If it is used, the specified table key is used.
- "Secondary table key
- READ TABLE it_so_sec FROM sec_keys
- USING KEY sec_key INTO DATA(wa15).
-
- "Primary table key; result: same as wa14
- READ TABLE it_so_sec FROM pr_keys
- USING KEY primary_key INTO DATA(wa16).
-
- output->display( input = wa14 name = `wa14` ).
- output->display( input = wa15 name = `wa15` ).
- output->display( input = wa16 name = `wa16` ).
-
-**********************************************************************
-
- output->next_section( `44) ... using table expressions` ).
- "Primary table key (COMPONENTS addition is optional)
- DATA(lv9) = it_so_sec[ KEY primary_key COMPONENTS a = 1 ].
-
- DATA(lv10) = it_so_sec[ KEY primary_key a = 1 ].
-
- DATA(lv11) = it_so_sec[ KEY pk a = 2 ]. "Primary table key alias
-
- "Secondary table key (COMPONENTS mandatory)
- DATA(lv12) = it_so_sec[ KEY sec_key COMPONENTS b = 'aaa' ].
-
- DATA(lv13) = it_so_sec[ KEY sk COMPONENTS b = 'ddd' ]. "Alias
-
- output->display( input = lv9 name = `lv9` ).
- output->display( input = lv10 name = `lv10` ).
- output->display( input = lv11 name = `lv11` ).
- output->display( input = lv12 name = `lv12` ).
- output->display( input = lv13 name = `lv13` ).
-
-**********************************************************************
-
- output->next_section( `45) Reading a single line via free key` ).
- "Note: If there a multiple matching entries, the first found
- "is returned.
- READ TABLE it_so_sec INTO DATA(wa17) WITH KEY c = '###'.
-
- DATA(lv14) = it_so_sec[ c = 'zzz' ].
-
- output->display( input = wa17 name = `wa17` ).
- output->display( input = lv14 name = `lv14` ).
-
-**********************************************************************
-
- output->next_section( `46) Excursion: Addressing individual components` ).
- "Addressing a component using the component selector
- DATA(comp1) = it_so_sec[ 1 ]-b.
-
- READ TABLE it_so_sec ASSIGNING FIELD-SYMBOL() INDEX 2.
-
- DATA(comp2) = -c.
-
- READ TABLE it_so_sec REFERENCE INTO DATA(dref4) INDEX 3.
-
- DATA(comp3) = dref->*-a.
-
- "Same effect as above but less to write
- DATA(comp4) = dref->b.
-
- output->display( input = comp1 name = `comp1` ).
- output->display( input = comp2 name = `comp2` ).
- output->display( input = comp3 name = `comp3` ).
- output->display( input = comp4 name = `comp4` ).
-
-**********************************************************************
-
- output->next_section( `47) Checking if a line exists in an internal table` ).
-
- "Defining the key
- DATA(key1) = 2.
-
- "Internal table function
- IF line_exists( it_so_sec[ a = key1 ] ).
- output->display( |Line { key1 } exists in internal table.| ).
- ELSE.
- output->display( |Line { key1 } does not exist in internal table.| ).
- ENDIF.
-
- "Alternative using READ TABLE (sy-subrc is checked)
- "When using the addition TRANSPORTING NO FIELDS, no field values
- "are read. Only the system fields are filled.
- READ TABLE it_so_sec WITH KEY a = key1 TRANSPORTING NO FIELDS.
-
- IF sy-subrc = 0.
- output->display( |Line { key1 } exists in internal table.| ).
- ELSE.
- output->display( |Line { key1 } does not exist in internal table.| ).
- ENDIF.
-
-**********************************************************************
-
- output->next_section( `48) Checking the index of a ` &&
- `specific line` ).
-
- DATA(key2) = 4.
-
- DATA(idx_of_line1) = line_index( it_so_sec[ a = key2 ] ).
-
- DATA(key3) = 10.
-
- DATA(idx_of_line2) = line_index( it_so_sec[ a = key3 ] ).
-
- "Alternative using READ TABLE
- "The table index is written to the sy-tabix system field
- READ TABLE it_so_sec WITH KEY a = key2 TRANSPORTING NO FIELDS.
-
- IF sy-subrc = 0.
- DATA(tab_idx1) = sy-tabix.
- ENDIF.
-
- READ TABLE it_so_sec WITH KEY a = key3 TRANSPORTING NO FIELDS.
-
- IF sy-subrc = 0.
- DATA(tab_idx2) = sy-tabix.
- ENDIF.
-
- IF idx_of_line1 <> 0.
- output->display( |The index of the line with key = { key2 } | &&
- |is { idx_of_line1 } in the internal table.| ).
- ELSE.
- output->display( |The line with key = { key2 } does not exist | &&
- |in the internal table.| ).
- ENDIF.
-
- IF idx_of_line2 <> 0.
- output->display( |The index of the line with key = { key3 } | &&
- |is { idx_of_line2 } in the internal table.| ).
- ELSE.
- output->display( |The line with key = { key3 } does not exist | &&
- |in the internal table.| ).
- ENDIF.
-
- IF tab_idx1 <> 0.
- output->display( |The index of the line with key = { key2 } | &&
- |is { tab_idx1 } in the internal table.| ).
- ELSE.
- output->display( |The line with key = { key2 } does not exist | &&
- |in the internal table.| ).
- ENDIF.
-
- IF tab_idx2 <> 0.
- output->display( |The index of the line with key = { key3 } | &&
- |is { tab_idx2 } in the internal table.| ).
- ELSE.
- output->display( |The line with key = { key3 } does not exist | &&
- |in the internal table.| ).
- ENDIF.
-
- output->next_section( `49) Checking how many lines are in an` &&
- ` internal table` ).
- DATA(itab_lines) = lines( it_so_sec ).
-
- output->display( |The internal table consists of { itab_lines } | &&
- |lines.| ).
-
-**********************************************************************
-
- output->next_section( `Processing multiple internal table lines ` &&
- `sequentially` ).
- output->display( `50) Reading a complete table by sequentially ` &&
- `reading all lines` ).
-
- "No further addition: All lines are respected.
- LOOP AT it_so_sec ASSIGNING FIELD-SYMBOL().
- "Modifying a component to visualize the reading of all lines.
- -b = 'ZZZ'.
- ENDLOOP.
-
- output->display( input = it_so_sec name = `it_so_sec` ).
-
-**********************************************************************
-
- output->display( `51) LOOP AT statements with different targets` ).
-
- "The following examples demonstrate the different targets that
- "are possible for LOOP AT statements. In the example above,
- "a field symbol is created inline.
- "As above, there are no additions to the loop statement, i.e. all lines
- "are processed.
-
- DATA(lines_in_table) = lines( it_so_sec ).
- output->display( |There should be { lines_in_table } iterations per loop.| ).
-
- "Target: Existing work area
- output->display( `---- Loop target: Existing work area ----` ).
- DATA wa_lo LIKE LINE OF it_so_sec.
-
- LOOP AT it_so_sec INTO wa_lo.
- IF sy-tabix = 1.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ELSEIF sy-tabix = lines_in_table.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ENDIF.
- ENDLOOP.
-
- output->display( `---- Loop target: Work area created inline ----` ).
- LOOP AT it_so_sec INTO DATA(wa_inl).
- IF sy-tabix = 1.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ELSEIF sy-tabix = lines_in_table.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ENDIF.
- ENDLOOP.
-
- output->display( `---- Loop target: Existing field symbol ----` ).
- FIELD-SYMBOLS LIKE LINE OF it_so_sec.
-
- LOOP AT it_so_sec ASSIGNING .
- IF sy-tabix = 1.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ELSEIF sy-tabix = lines_in_table.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ENDIF.
-
- ENDLOOP.
-
- output->display( `---- Loop target: Field symbol created inline ----` ).
- LOOP AT it_so_sec ASSIGNING FIELD-SYMBOL().
- IF sy-tabix = 1.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ELSEIF sy-tabix = lines_in_table.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ENDIF.
- ENDLOOP.
-
- output->display( `---- Loop target: Existing data reference variable ----` ).
- DATA dref_lo TYPE REF TO struc1 .
-
- LOOP AT it_so_sec REFERENCE INTO dref_lo.
- IF sy-tabix = 1.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ELSEIF sy-tabix = lines_in_table.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ENDIF.
- ENDLOOP.
-
- output->display( `Loop target: Data reference variable created inline` ).
- LOOP AT it_so_sec REFERENCE INTO DATA(dref_inl).
- IF sy-tabix = 1.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ELSEIF sy-tabix = lines_in_table.
- output->display( |This text is displayed when reaching line { sy-tabix }.| ).
- ENDIF.
- ENDLOOP.
-
-**********************************************************************
-
- output->next_section( `52) Reading multiple lines by an index range` ).
-
- "Specific lines in an index range are respected
- "Note: FROM/TO alone can specified, too.
- LOOP AT it_so_sec ASSIGNING FIELD-SYMBOL() FROM 2 TO 3.
- "Modifying a component to visualize the reading of specific lines.
- -c = 'YYY'.
- ENDLOOP.
-
- output->display( input = it_so_sec name = `it_so_sec` ).
-
-**********************************************************************
-
- output->next_section( `53) Reading multiple lines by condition` ).
-
- LOOP AT it_so_sec ASSIGNING FIELD-SYMBOL() WHERE a < 3.
- "Modifying a component to visualize the reading of specific lines.
- -d = 'XXX'.
- ENDLOOP.
-
- output->display( input = it_so_sec name = `it_so_sec` ).
-
-**********************************************************************
-
- output->next_section( `54) Looping across a table without an interest` &&
- ` in the table content` ).
-
- "Here, only the system fields are set.
- LOOP AT it_so_sec TRANSPORTING NO FIELDS WHERE a < 3.
- DATA(num) = sy-tabix.
- ENDLOOP.
-
- output->display( |There are { num } lines in the table | &&
- |fulfilling the condition.| ).
-
-**********************************************************************
-
- output->next_section( `55) Loop with table key specification` ).
-
- DATA it_st_em TYPE TABLE OF struc1 WITH EMPTY KEY.
-
- "Looping across hashed table using a secondary key. The loop starts
- "according to the secondary table index. The lines are added to
- "another internal table having a matching type. It basically
- "visualizes the order of the table lines in the secondary table
- "index.
- LOOP AT it_ha_sec ASSIGNING FIELD-SYMBOL() USING KEY sec_key_h.
- APPEND TO it_st_em.
- ENDLOOP.
-
- output->display( input = it_st_em name = `it_st_em` ).
-
-**********************************************************************
-
- output->next_section( `STEP addition in LOOP AT statements` ).
- output->display( `56) Reversing loop order` ).
-
- DATA(it_abc) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ( `d` ) ( `e` ) ( `f` ) ).
- DATA it_abc_result TYPE string_table.
-
- "Reversing the loop order with the addition STEP
- "Each line is read indicated by absolute value 1
- LOOP AT it_abc ASSIGNING FIELD-SYMBOL() STEP -1.
- APPEND TO it_abc_result.
- ENDLOOP.
-
- output->display( input = it_abc_result name = `it_abc_result` ).
-
-**********************************************************************
-
- output->next_section( `57) Forward loop and defining step size` ).
-
- "Forward loop indicated by positive integer, every second line is processed
- CLEAR it_abc_result.
- LOOP AT it_abc ASSIGNING FIELD-SYMBOL() STEP 2.
- APPEND TO it_abc_result.
- ENDLOOP.
-
- output->display( input = it_abc_result name = `it_abc_result` ).
-
-**********************************************************************
-
- output->next_section( `58) STEP addition combined with FROM/TO` ).
-
- "Combining the STEP addition with other additions, e.g. FROM and TO
- "Note: If the value after STEP is negative, the value after FROM
- "must be greater than the value after TO.
- CLEAR it_abc_result.
- LOOP AT it_abc ASSIGNING FIELD-SYMBOL() FROM 6 TO 3 STEP -2.
- APPEND TO it_abc_result.
- ENDLOOP.
-
- output->display( input = it_abc_result name = `it_abc_result` ).
-
-**********************************************************************
-
- output->next_section( `Creating and filling tables using table ` &&
- `iterations with FOR and VALUE` ).
- output->display( `59) Retrieving values of one column in ` &&
- `an internal table.` ).
-
- "Creating internal table type
- TYPES ty_numbers TYPE TABLE OF i WITH EMPTY KEY.
-
- "Table comprehension: Content of an internal table is created by
- "evaluating a table using a table iteration with an iteration
- "expressions within a constructor expression.
- DATA(lv_num_a) = VALUE ty_numbers( FOR ls1 IN it_ha_sec
- ( ls1-a ) ).
-
- output->display( input = lv_num_a name = `lv_num_a` ).
-
-**********************************************************************
-
- output->next_section( `60) Retrieving values of one column in ` &&
- `an internal table based on conditions` ).
-
- DATA(lv_num_b) = VALUE ty_numbers( FOR ls2 IN it_ha_sec
- WHERE ( a < 3 ) ( ls2-a ) ).
-
- output->display( input = lv_num_b name = `lv_num_b` ).
-
-**********************************************************************
-
- output->next_section( `61) Looping across 2 tables ` &&
- `and retrieving values based on conditions` ).
- "Internal table type
- TYPES tabtype LIKE it_so_sec.
-
- DATA(itab_for_2tab) =
- VALUE tabtype(
- FOR ls3 IN it_ha_sec
- FOR ls4 IN it_so_sec WHERE ( a = ls3-a )
- ( a = ls3-a b = ls4-b c = ls3-c d = ls4-d ) ).
-
- output->display( input = itab_for_2tab name = `itab_for_2tab` ).
-
-**********************************************************************
-
- output->next_section( `62) Retrieving and changing values from an ` &&
- `internal tables sequentially` ).
- DATA(it_changed) = VALUE tabtype( FOR ls5 IN it_so_sec
- ( a = ls5-a b = 'WWW' c = 'VVV' d = 'UUU' ) ).
-
- output->display( input = it_changed name = `it_changed` ).
-
-**********************************************************************
-
- output->next_section( `63) Sorting internal tables` ).
-
- "Creating structured data types
- TYPES: BEGIN OF s1,
- a TYPE i,
- b TYPE string,
- c TYPE c LENGTH 1,
- d TYPE i,
- END OF s1.
-
- TYPES: BEGIN OF s2,
- a TYPE i,
- b TYPE i,
- END OF s2.
-
- "Creating internal tables
- DATA it1 TYPE TABLE OF s1 WITH NON-UNIQUE KEY a.
- DATA it2 TYPE TABLE OF s1 WITH DEFAULT KEY.
-
- "Filling internal tables
- it1 = VALUE #( ( a = 1 b = `c` c = 'z' d = 4 )
- ( a = 3 b = `b` c = 'f' d = 3 )
- ( a = 2 b = `d` c = 'r' d = 9 )
- ( a = 4 b = `a` c = 'p' d = 3 )
- ( a = 5 b = `b` c = 'x' d = 2 )
- ( a = 5 b = `a` c = 'x' d = 0 )
- ( a = 1 b = `c` c = 'y' d = 8 ) ).
-
- it2 = it1.
-
- output->display( `Original internal table content ` &&
- `(it1 and it2 have the same content)` ).
-
- output->display( input = it1 name = `it1` ).
- output->display( input = it2 name = `it2` ).
-
-**********************************************************************
-
- output->next_section( `64) Sorting by primary table key` ).
-
- "Primary key: component a
- SORT it1.
-
- output->display( input = it1 name = `it1` ).
-
-**********************************************************************
-
- output->next_section( `65) Sorting by primary table key in ascending` &&
- ` order` ).
-
- "The sorting result is the same as above (where ASCENDING is used
- "implicitly). Here, it is explicitly specified.
- SORT it1 ASCENDING.
-
- output->display( input = it1 name = `it1` ).
-
-**********************************************************************
-
- output->next_section( `66) Sorting by primary table key respecting all ` &&
- `non-numeric fields` ).
-
- "Primary key: standard table key (all non-numeric fields)
- SORT it2.
-
- output->display( input = it2 name = `it2` ).
-
- "The following code is commented out on purpose because it
- "produces a syntax warning. The primary table key is empty.
- "A sorting has no effect.
- "SORT it3.
- "output->display( input = it3 name = `it3` ).
-
-**********************************************************************
-
- output->next_section( `67) Sorting by primary table key in ` &&
- `descending order` ).
-
- "Sorting in descending order and by primary table key
- SORT it1 DESCENDING.
-
- output->display( input = it1 name = `it1` ).
-
-**********************************************************************
-
- output->next_section( `68) Sorting by explicitly specified component (1)` ).
- "Here, the component is the primary table key.
- "The sorting result is the same as above.
- SORT it1 BY a DESCENDING.
-
- output->display( input = it1 name = `it1` ).
-
-**********************************************************************
-
- output->next_section( `69) Sorting by explicitly specified component (2)` ).
-
- "Sorting by arbitrary, non-key field
- SORT it1 BY d DESCENDING.
-
- output->display( input = it1 name = `it1` ).
-
-**********************************************************************
-
- output->next_section( `70) Sorting by multiple explicitly specified` &&
- ` components` ).
-
- "Sorting by multiple components and specifying the sort order
- SORT it1 BY b ASCENDING c DESCENDING.
-
- output->display( input = it1 name = `it1` ).
-
-**********************************************************************
-
- output->next_section( `71) Sorting by respecting the values of all` &&
- ` components` ).
-
- "Sorting by considering the values of each field of the table line
- SORT it1 BY table_line.
-
- output->display( input = it1 name = `it1` ).
-
-**********************************************************************
-
- output->next_section( `72) Modifying internal table content` ).
- output->display( `Internal table content before modifications` ).
-
- "Standard table
- output->display( input = it_st name = `it_st` ).
-
- "Sorted table
- output->display( input = it_so_sec name = `it_so_sec` ).
-
- "Hashed table
- output->display( input = it_ha_sec name = `it_ha_sec` ).
-
-**********************************************************************
-
- output->next_section( `73) Directly modifying recently read table lines` ).
-
- "READ TABLE
- "Reading table line into target area (field symbol)
- READ TABLE it_so_sec ASSIGNING FIELD-SYMBOL() INDEX 1.
- "Directly modifying an individual component value and
- "the entire line (except the key values in sorted/hashed tables)
- -c = 'ABC'.
- = VALUE #( BASE d = 'DEF' ).
-
- "Table expressions
- it_st[ 1 ]-c = 'GHI'. "Individual component
- it_st[ 1 ] = VALUE #( BASE it_st[ 1 ] b = 'JKL' d = 'MNO' ).
-
- output->display( input = it_so_sec[ 1 ] name = `it_so_sec[ 1 ]` ).
- output->display( input = it_st[ 1 ] name = `it_st[ 1 ]` ).
-
-**********************************************************************
-
- output->next_section( `74) Modifying internal table content using MODIFY` ).
- "Modifying table lines via key values
- "Line that is used to modify internal table
- line = VALUE #( a = 2 b = 'zzz' c = 'yyy' ).
-
- "Standard table
- "With the addition FROM wa, the key values in wa determine the line
- "to be modified.
- "Note: Component d is not specified in "line". The value is
- "initialized.
- MODIFY TABLE it_st FROM line.
-
- "Example in which the work area is constructed inline.
- "Components b and c not specified. The values are initialized.
- MODIFY TABLE it_st FROM VALUE #( a = 3 d = 'xxx' ).
-
- "Addition TRANSPORTING: Only specified fields are respected
- "Note: In case of sorted/hasehd tables, key values cannot be
- "specified.
- MODIFY TABLE it_st
- FROM VALUE #( a = 4 b = '###' c = '###' d = '###' )
- TRANSPORTING b c.
-
- "Modifying table lines via index
- "Note: It is only MODIFY, not MODIFY TABLE as above.
- "The following statement modifies the line with number 1 in the
- "primary table index. Without the addition TRANSPORTING, the
- "entire line is changed.
- MODIFY it_st
- FROM VALUE #( a = 1 b = 'aaa' c = 'aaa' d = 'aaa' )
- INDEX 1.
-
- "USING KEY: Determines the table key and thus which table index
- "to respect
- MODIFY it_so_sec
- FROM VALUE #( a = 1 b = 'EEE' c = 'EEE' d = 'EEE' )
- INDEX 1
- USING KEY primary_key
- TRANSPORTING c d.
-
- "Note: Without TRANSPORTING, the statement would overwrite the
- "secondary key which is not allowed.
- MODIFY it_ha_sec
- FROM VALUE #( a = 1 b = 'FFF' c = 'FFF' d = 'FFF' )
- INDEX 1
- USING KEY sec_key_h
- TRANSPORTING d.
-
- output->display( input = it_st name = `it_st` ).
- output->display( input = it_so_sec name = `it_so_sec` ).
- output->display( input = it_ha_sec name = `it_ha_sec` ).
-
-**********************************************************************
-
- output->next_section( `75) Deleting internal table content using DELETE` ).
- "Deleting via index
- "Primary table index is used implicitly.
- DELETE it_st INDEX 1.
-
- "If USING KEY is not used, INDEX can only be used with index
- "tables. If a secondary key is specified, the secondary table
- "index is respected.
- "The following example has the same effect as above.
- DELETE it_st INDEX 1 USING KEY primary_key.
-
- "Hashed table. The secondary table index is respected.
- DELETE it_ha_sec INDEX 1 USING KEY sec_key_h.
-
- "Deleting multiple lines by specifying an index range
- "FROM or TO alone can also be specified
- DELETE it_so_sec FROM 2 TO 3.
-
- "Deleting via keys
- "When using the addition FROM wa, the line wa must have a
- "compatible type to the table's line type and include key values.
- "The first found line with the corresponding keys is deleted.
- "If the key is empty, no line is deleted.
- DELETE TABLE it_so_sec FROM VALUE #( a = 4 ).
-
- "Explicitly specifying the table key
- DELETE TABLE it_so_sec WITH TABLE KEY a = 1.
-
- DELETE TABLE it_ha_sec
- WITH TABLE KEY sec_key_h COMPONENTS b = 'bbb'.
-
- "Deleting multiple lines based on conditions
- "Note: Specifying the additions USING KEY/FROM/TO is also possible
- DELETE it_st WHERE a > 3.
-
- output->display( input = it_st name = `it_st` ).
- output->display( input = it_so_sec name = `it_so_sec` ).
- output->display( input = it_ha_sec name = `it_ha_sec` ).
-
-**********************************************************************
-
- output->next_section( `76) Deleting adjacent duplicate entries` ).
- output->display( `Original table content (restored before` &&
- ` each of the following examples)` ).
-
- it_st = VALUE #( ( a = 1 b = 'BBB' c = '###' d = '###' )
- ( a = 2 b = '###' c = '###' d = '###' )
- ( a = 1 b = '###' c = '###' d = '###' )
- ( a = 3 b = '###' c = '###' d = '###' )
- ( a = 4 b = '###' c = 'CCC' d = '###' )
- ( a = 1 b = 'BBB' c = '###' d = '###' )
- ( a = 2 b = 'BBB' c = '###' d = '###' )
- ( a = 4 b = 'BBB' c = '###' d = '###' )
- ( a = 2 b = 'BBB' c = '###' d = '###' )
- ( a = 3 b = '###' c = '###' d = '###' ) ).
-
- SORT it_st BY table_line.
-
- "Filling another table so that the same content above
- "is available for the examples below.
- it_st2 = it_st.
-
- output->display( input = it_st2 name = `it_st2` ).
-
-**********************************************************************
-
- output->next_section( `77) Deleting adjacent duplicates based on` &&
- ` primary table key` ).
-
- "Note: Using the primary table key can have unexpected consequences
- "if the primary table key is the standard key or if it is empty.
- DELETE ADJACENT DUPLICATES FROM it_st2.
-
- output->display( input = it_st2 name = `it_st2` ).
-
- it_st2 = it_st.
-
-**********************************************************************
-
- output->next_section( `78) Deleting adjacent duplicates by comparing ` &&
- `all field values` ).
-
- DELETE ADJACENT DUPLICATES FROM it_st2 COMPARING ALL FIELDS.
-
- output->display( input = it_st2 name = `it_st2` ).
-
- it_st2 = it_st.
-
-**********************************************************************
-
- output->next_section( `79) Deleting adjacent duplicates by comparing ` &&
- `specific field values` ).
-
- DELETE ADJACENT DUPLICATES FROM it_st2 COMPARING a c.
-
- output->display( input = it_st2 name = `it_st2` ).
-
- it_st2 = it_st.
-
-**********************************************************************
-
- output->next_section( `80) Deleting adjacent duplicates by using a` &&
- ` table key` ).
-
- "In this case, the result is the same as in the first example.
- DELETE ADJACENT DUPLICATES FROM it_st2 USING KEY primary_key.
-
- output->display( input = it_st2 name = `it_st2` ).
-
-**********************************************************************
-
- output->next_section( `81) Deleting the entire internal table content` ).
-
- CLEAR it_st.
-
- "Additionally, FREE releases memory space.
- FREE it_st2.
-
- "Excursion: Assigning an empty constructor expression with VALUE clears
- "the internal table.
- DATA(it_str) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ).
-
- it_str = VALUE #( ).
-
- output->display( input = it_st name = `it_st` ).
- output->display( input = it_st2 name = `it_st2` ).
- output->display( input = it_str name = `it_str` ).
-
-**********************************************************************
-
- output->next_section( `Excursions` ).
- output->display( `82) Secondary table keys and hashed tables` ).
-
- "Declaring a hashed table
- DATA hashed_tab
- TYPE HASHED TABLE OF zdemo_abap_tab1
- WITH UNIQUE KEY primary_key COMPONENTS key_field
- WITH NON-UNIQUE SORTED KEY sec_key COMPONENTS char1 char2.
-
- "Retrieving data to work with
- SELECT * FROM zdemo_abap_tab1 INTO TABLE @hashed_tab UP TO 3 ROWS.
-
- "Integer table to display the table index
- DATA int_itab TYPE TABLE OF i.
-
- "Note: There is no primary table index in hashed tables.
- LOOP AT hashed_tab INTO DATA(hwa) USING KEY primary_key.
- APPEND sy-tabix TO int_itab.
- ENDLOOP.
-
- output->display( input = int_itab name = `int_itab` ).
-
- CLEAR int_itab.
-
- "Demonstrating the secondary table index when using
- "the secondary key
- LOOP AT hashed_tab INTO DATA(hwa2) USING KEY sec_key.
- APPEND sy-tabix TO int_itab.
- ENDLOOP.
-
- output->display( input = int_itab name = `int_itab` ).
-
- "Retrieving a table line via index access to the secondary index
- "of the sorted secondary key
- DATA(line_of_ht) = hashed_tab[ KEY sec_key INDEX 2 ].
-
- output->display( input = line_of_ht name = `line_of_ht` ).
-
-**********************************************************************
-
- output->next_section( `83) Empty keys in internal table created inline` ).
- "This example visualizes the fact that when using an inline
- "construction like INTO TABLE @DATA(itab) in SELECT statements, the
- "resulting table has an empty table key. Here, the key information
- "is retrieved using RTTI. The output shows the key information:
- "the information on the first internal table includes the key as
- "specified (key_field as the primary key, non-unique - since
- "key_kind is U and is_unique is not flagged. The result for the
- "other internal table shows that there is no key name at all and
- "key_kind is E (= empty).
-
- "An internal table representing an existing table having table keys
- "defined in contrast to an internal table created inline.
- DATA it_with_key TYPE TABLE OF zdemo_abap_tab1
- WITH NON-UNIQUE KEY key_field.
-
- "Retrieving data to work with
- SELECT * FROM zdemo_abap_tab1 INTO TABLE @it_with_key UP TO 3 ROWS.
- SELECT * FROM zdemo_abap_tab1 INTO TABLE @DATA(it_inline)
- UP TO 3 ROWS.
-
- "Using RTTI to retrieve the key information
- DATA(k1) = CAST cl_abap_tabledescr(
- cl_abap_typedescr=>describe_by_data(
- it_with_key )
- )->get_keys( ).
-
-
- output->display( input = k1 name = `k1` ).
-
- DATA(k2) = CAST cl_abap_tabledescr(
- cl_abap_typedescr=>describe_by_data(
- it_inline )
- )->get_keys( ).
-
- output->display( input = k2 name = `k2` ).
- ENDMETHOD.
METHOD class_constructor.
fill_dbtabs( ).
ENDMETHOD.
+
METHOD fill_dbtabs.
"Initializing and filling of database tables to have data to work with
@@ -1816,4 +173,1720 @@ CLASS zcl_demo_abap_internal_tables IMPLEMENTATION.
( key_field = 60 char1 = 'kkk'
char2 = 'lll' num1 = 1100 num2 = 1200 ) ) ) ).
ENDMETHOD.
-ENDCLASS.
\ No newline at end of file
+
+
+ METHOD if_oo_adt_classrun~main.
+
+ out->write( |ABAP Cheat Sheet Example: Internal Tables\n\n| ).
+ out->write( |Filling and Copying Internal Table Content\n| ).
+ out->write( |1) Adding single lines using APPEND/INSERT\n\n| ).
+
+ "Two internal tables, a standard and sorted internal table.
+ "Both have the same line type and one field as (non-)unique key.
+ DATA it_st TYPE TABLE OF struc1 WITH NON-UNIQUE KEY a.
+ DATA it_so TYPE SORTED TABLE OF struc1 WITH UNIQUE KEY a.
+
+ "APPEND
+ "Standard table
+ APPEND VALUE #( a = 1 b = 'aaa' c = 'bbb' d = 'ccc' ) TO it_st.
+
+ "A line is created and filled to be used for the APPEND statement.
+ "The line type matches the line type of the internal table.
+ DATA(line) = VALUE struc1( a = 2 b = 'd' c = 'e' d = 'f' ).
+
+ "Sorted table
+ "APPEND works here with a sorted table. At this stage, the
+ "internal table is empty, so there is no issue (lines are only
+ "appended if they match the sort order and do not create
+ "duplicate entries if the primary table key is unique).
+ APPEND line TO it_so.
+
+ "INSERT
+ "INSERT has same effect as APPEND with standard tables
+ INSERT VALUE #( a = 2 b = 'ddd' c = 'eee' d = 'fff' )
+ INTO TABLE it_st.
+
+ INSERT VALUE #( a = 1 b = 'a' c = 'b' d = 'c' ) INTO TABLE it_so.
+
+ out->write( data = it_st name = `it_st` ).
+ out->write( |\n| ).
+ out->write( data = it_so name = `it_so` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `2) Adding initial line` ) ).
+
+ APPEND INITIAL LINE TO it_st.
+
+ INSERT INITIAL LINE INTO TABLE it_so.
+
+ out->write( data = it_st name = `it_st` ).
+ out->write( |\n| ).
+ out->write( data = it_so name = `it_so` ).
+
+**********************************************************************
+
+out->write( zcl_demo_abap_aux=>heading( `3) Adding mutliple lines of an internal table to another one` ) ).
+
+ "No additions: All lines are added to the target internal table
+ APPEND LINES OF it_so TO it_st.
+
+ "Creating a new itab and filling it.
+ DATA it_so2 LIKE it_so.
+
+ INSERT VALUE #( a = 3 b = 'g' c = 'h' d = 'i' ) INTO TABLE it_so2.
+
+ INSERT VALUE #( a = 4 b = 'j' c = 'k' d = 'l' ) INTO TABLE it_so2.
+
+ "Inserting all lines of previously created internal table.
+ INSERT LINES OF it_so2 INTO TABLE it_so.
+
+ out->write( data = it_st name = `it_st` ).
+ out->write( |\n| ).
+ out->write( data = it_so name = `it_so` ).
+
+**********************************************************************
+
+out->write( zcl_demo_abap_aux=>heading( `4) Adding lines of an internal table to another one by specifying the index range.` ) ).
+
+
+ "When using only FROM, all lines are respected until the final
+ "table entry. When using only TO, all lines are respected
+ "starting from the first table entry.
+ APPEND LINES OF it_so FROM 2 TO 3 TO it_st.
+
+ INSERT LINES OF it_so FROM 3 INTO TABLE it_st.
+
+ APPEND LINES OF it_so TO 2 TO it_st.
+
+ out->write( data = it_st name = `it_st` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `5) Inserting lines of an internal table into another one at a specific position` ) ).
+
+ "Inserting a single line
+ INSERT VALUE #( a = 10 b = 'ggg' c = 'hhh' d = 'iii' )
+ INTO it_st INDEX 1.
+
+ "Inserting multiple lines
+ INSERT LINES OF it_so2 INTO it_st INDEX 2.
+
+ out->write( data = it_st name = `it_st` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `6) Adding lines using constructor expressions` ) ).
+
+ "Creating a line to be added to an internal table.
+ line = VALUE #( a = 1 b = 'aaa' c = 'bbb' d = 'ccc' ).
+
+ "Table on the right is constructed inline using VALUE and assigned
+ "Note: This way, existing table content is cleared.
+ it_st = VALUE #( ( line )
+ ( a = 2 b = 'ddd' c = 'eee' d = 'fff' ) ).
+
+ out->write( data = it_st name = `it_st` ).
+
+**********************************************************************
+
+out->write( zcl_demo_abap_aux=>heading( `7) Creating a new table inline and adding lines using a constructor expression` ) ).
+
+ "Internal table type
+ TYPES it_type LIKE it_st.
+
+ "Creating an internal table inline and filling in one go
+ DATA(it_st2) = VALUE it_type( ( a = 3 b = 'ggg'
+ c = 'hhh' d = 'iii' )
+ ( a = 4 b = 'jjj'
+ c = 'kkk' d = 'lll' ) ).
+
+ out->write( data = it_st2 name = `it_st2` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `8) Adding lines using constructor expressions and keeping existing table content` ) ).
+
+ "BASE addition: existing table content is not removed
+ it_st = VALUE #( BASE it_st ( a = 5 b = 'mmm' c = 'nnn' d = 'ooo' )
+ ( a = 6 b = 'ppp' c = 'qqq' d = 'rrr' )
+ ).
+
+ out->write( data = it_st name = `it_st` ).
+
+**********************************************************************
+
+out->write( zcl_demo_abap_aux=>heading( `9) Adding lines from other internal tables using constructor expressions` ) ).
+
+ "With LINES OF itab specified within the pair of parentheses,
+ "all lines of the internal table are added; here, in the same
+ "expression another line is added as well
+ it_st = VALUE #( BASE it_st ( LINES OF it_st2 )
+ ( a = 7 b = 'sss' c = 'ttt' d = 'uuu' )
+ ).
+
+ out->write( data = it_st name = `it_st` ).
+
+**********************************************************************
+
+out->write( zcl_demo_abap_aux=>heading( `10) Copying table content (without constructor expression)` ) ).
+
+ "Assignment of a table to another one having a matching line type
+ it_st = it_st2.
+
+ out->write( data = it_st name = `it_st` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `11) CORRESPONDING Operator and MOVE-CORRESPONDING` ) ).
+ out->write( |Internal table content before assignments\n\n| ).
+
+ "Note: Before the following statements, the table content is reset
+ "to this state to work with the same set of values.
+ fill_itabs_for_corresponding( ).
+
+ out->write( data = tab1 name = `tab1` ).
+ out->write( |\n| ).
+ out->write( data = tab2 name = `tab2` ).
+ out->write( |\n| ).
+ out->write( data = tab3 name = `tab3` ).
+ out->write( |\n| ).
+ out->write( data = tab4 name = `tab4` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `Copying content from another table that has a different line type ...` ) ).
+
+ out->write( |12) ... and deleting existing table content using the CORRESPONDING operator\n\n| ).
+
+ tab1 = CORRESPONDING #( tab2 ).
+
+ out->write( data = tab1 name = `tab1` ).
+
+ fill_itabs_for_corresponding( ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `13) ... and deleting existing table content using MOVE-CORRESPONDING` ) ).
+
+ MOVE-CORRESPONDING tab2 TO tab1.
+
+ out->write( data = tab1 name = `tab1` ).
+
+ fill_itabs_for_corresponding( ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `14) ... and keeping existing table content using the CORRESPONDING operator` ) ).
+
+ tab1 = CORRESPONDING #( BASE ( tab1 ) tab2 ).
+
+ out->write( data = tab1 name = `tab1` ).
+
+ fill_itabs_for_corresponding( ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `15) ... and keeping existing table content using MOVE-CORRESPONDING` ) ).
+
+
+ MOVE-CORRESPONDING tab2 TO tab1 KEEPING TARGET LINES.
+
+ out->write( data = tab1 name = `tab1` ).
+
+ fill_itabs_for_corresponding( ).
+
+**********************************************************************
+
+out->write( zcl_demo_abap_aux=>heading( `16) ... respecting component mapping` ) ).
+
+ "Specifying components of a source table that are assigned to the
+ "components of a target table in mapping relationships
+ tab1 = CORRESPONDING #( tab2 MAPPING c = e d = f ).
+
+ out->write( data = tab1 name = `tab1` ).
+
+ fill_itabs_for_corresponding( ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `17) ... excluding components` ) ).
+
+ "Excluding components from the assignment
+ tab1 = CORRESPONDING #( tab2 EXCEPT b ).
+
+ out->write( data = tab1 name = `tab1` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `18) ... excluding components and using MAPPING` ) ).
+
+ "EXCEPT * means that all components remain initial not specified
+ "for mapping
+ tab1 = CORRESPONDING #( tab2 MAPPING d = f EXCEPT * ).
+
+ out->write( data = tab1 name = `tab1` ).
+
+ fill_itabs_for_corresponding( ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `19) ... discarding duplicates` ) ).
+
+ "Preventing runtime errors if duplicate lines are assigned to
+ "target table that is defined to only accept unique keys.
+ "Note: Other tables than above are used here.
+ tab3 = CORRESPONDING #( BASE ( tab3 ) tab4 DISCARDING DUPLICATES ).
+
+ out->write( data = tab3 name = `tab3` ).
+ out->write( |\n| ).
+
+ fill_itabs_for_corresponding( ).
+
+ tab3 = CORRESPONDING #( BASE ( tab3 ) tab4 DISCARDING DUPLICATES
+ MAPPING d = f EXCEPT b ).
+
+ out->write( data = tab3 name = `tab3` ).
+
+**********************************************************************
+
+out->write( zcl_demo_abap_aux=>heading( `20) Copying data from a deep internal table to another deep internal table` ) ).
+
+ out->write( `Original table content` ).
+ out->write( |\n| ).
+ out->write( |\n| ).
+ out->write( data = itab_nested1 name = `itab_nested1` ).
+ out->write( |\n| ).
+ out->write( data = itab_nested2 name = `itab_nested2` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `21) ... deleting existing content (CORRESPONDING operator)` ) ).
+
+ itab_nested2 = CORRESPONDING #( DEEP itab_nested1 ).
+
+ out->write( data = itab_nested2 name = `itab_nested2` ).
+
+ fill_itabs_for_corresponding( ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `22) ... deleting existing content (MOVE-CORRESPONDING)` ) ).
+
+
+ MOVE-CORRESPONDING itab_nested1 TO itab_nested2
+ EXPANDING NESTED TABLES.
+
+ out->write( data = itab_nested2 name = `itab_nested2` ).
+
+ fill_itabs_for_corresponding( ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `23) ... keeping existing content (CORRESPONDING operator)` ) ).
+
+ itab_nested2 = CORRESPONDING #( DEEP BASE ( itab_nested2 )
+ itab_nested1 ).
+
+ out->write( data = itab_nested2 name = `itab_nested2` ).
+
+ fill_itabs_for_corresponding( ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `24) ... keeping existing content (MOVE-CORRESPONDING)` ) ).
+
+ MOVE-CORRESPONDING itab_nested1 TO itab_nested2
+ EXPANDING NESTED TABLES KEEPING TARGET LINES.
+
+ out->write( data = itab_nested2 name = `itab_nested2` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `Filling internal tables: Excursions` ) ).
+ out->write( |25) Selecting multiple rows from a database table into an internal table\n\n| ).
+
+ SELECT FROM zdemo_abap_tab1
+ FIELDS key_field, char1, char2, num1, num2
+ WHERE num1 > 3
+ INTO TABLE @DATA(itab_select1).
+
+ out->write( data = itab_select1 name = `itab_select1` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `26) Sequentially adding multiple rows from a database table to an internal table` ) ).
+
+
+ DATA itab TYPE TABLE OF zdemo_abap_tab1 WITH NON-UNIQUE KEY client key_field.
+
+ SELECT FROM zdemo_abap_tab1
+ FIELDS *
+ WHERE num1 > 3
+ INTO @DATA(struc_select).
+
+ IF sy-subrc = 0.
+ "Some modifications on the read lines (capitalizing letters)
+ struc_select-char1 = to_upper( struc_select-char1 ).
+ struc_select-char2 = to_upper( struc_select-char2 ).
+
+ "Adding modified line to an internal table
+ APPEND struc_select TO itab.
+ ENDIF.
+ ENDSELECT.
+
+ out->write( data = itab name = `itab` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `27) Adding multiple rows from a database table ` &&
+ `to an internal table that has a different line type than the ` &&
+ `database table and keeping existing table content` ) ).
+
+ SELECT FROM zdemo_abap_tab2
+ FIELDS *
+ WHERE num1 > 10
+ APPENDING CORRESPONDING FIELDS OF TABLE @itab.
+
+ out->write( data = itab name = `itab` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `28) Adding multiple rows from a database table ` &&
+ `to an internal table that has a different line type than the ` &&
+ `database table and deleting existing table content` ) ).
+
+ SELECT FROM zdemo_abap_tab2
+ FIELDS *
+ WHERE num1 > 10
+ INTO CORRESPONDING FIELDS OF TABLE @itab.
+
+ out->write( data = itab name = `itab` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `29) Adding multiple rows from an internal table ` &&
+ `to an internal table using SELECT` ) ).
+
+ SELECT key_field, char1, char2, num1, num2
+ FROM @itab AS itab_alias
+ INTO TABLE @DATA(itab_clone).
+
+ out->write( data = itab_clone name = `itab_clone` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `30) Combining data of multiple tables into an` &&
+ ` internal table using an inner join` ) ).
+
+ "Filling table to be selected from
+ itab = VALUE #( ( key_field = 500 char1 = 'uuu' char2 = 'vvv'
+ num1 = 501 num2 = 502 )
+ ( key_field = 600 char1 = 'www' char2 = 'xxx'
+ num1 = 601 num2 = 602 ) ).
+
+ "SELECT list includes fields from both tables
+ "If there are no equivalent entries in the first or second table,
+ "the rows are not joined.
+ SELECT itab_alias1~key_field, itab_alias1~char2,
+ zdemo_abap_tab2~numlong
+ FROM @itab AS itab_alias1
+ INNER JOIN zdemo_abap_tab2
+ ON itab_alias1~key_field = zdemo_abap_tab2~key_field
+ INTO TABLE @DATA(join_result).
+
+ out->write( data = join_result name = `join_result` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `31) Filling internal table ` &&
+ `using a subquery (1)` ) ).
+
+ "A subquery is specified in the WHERE clause
+ "Here, data is selected from a database table depending on
+ "whether the value of a certain field is not among the
+ "values specified in parentheses.
+ SELECT key_field, char1, numlong
+ FROM zdemo_abap_tab2
+ WHERE char1 NOT IN ( 'iii', 'mmm', 'ooo', 'ppp' )
+ INTO TABLE @DATA(subquery_result1).
+
+ out->write( data = subquery_result1 name = `subquery_result1` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `32) Filling internal table ` &&
+ `using a subquery (2)` ) ).
+
+ "A subquery using EXISTS in the WHERE clause.
+ "In the example, data is selected from a database table depending
+ "on the existence of data in an internal table. Only if a line
+ "with a matching value of the specified field exists in both
+ "database and internal table, data is read.
+ SELECT key_field, numlong
+ FROM zdemo_abap_tab2
+ WHERE EXISTS
+ ( SELECT 'X' FROM @itab AS itab_alias2
+ WHERE key_field = zdemo_abap_tab2~key_field )
+ INTO TABLE @DATA(subquery_result2).
+
+ out->write( data = subquery_result2 name = `subquery_result2` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `33) Filling an internal table from a table ` &&
+ `depending on the existence of data in another internal table ` &&
+ `using the addition FOR ALL ENTRIES` ) ).
+
+ "In the example, data is selected from a database table depending
+ "on the existence of data in an internal table. Only if a line
+ "with a matching value of the specified field exists in both
+ "database and internal table, data is read.
+ "Ensure that the internal table from which to read is not initial.
+ IF ( 0 < lines( itab ) ).
+ SELECT key_field, char1, numlong
+ FROM zdemo_abap_tab2
+ FOR ALL ENTRIES IN @itab
+ WHERE key_field = @itab-key_field
+ INTO TABLE @DATA(select_result).
+ ENDIF.
+
+ out->write( data = select_result name = `select_result` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `34) Adding content from a database to internal` &&
+ ` table by using alias names in the SELECT list` ) ).
+
+ DATA itab2 TYPE TABLE OF zdemo_abap_tab2 WITH EMPTY KEY.
+
+ "Specifying alias names can help fill an existing internal
+ "table that has not a matching line type to the database table.
+ "Here, two fields are specified with an alias name to match the
+ "names of components contained in the existing internal table.
+ "The individual types of the fields match, too.
+ SELECT key_field, char2 AS char1, num2 AS num1
+ FROM zdemo_abap_tab1
+ INTO CORRESPONDING FIELDS OF TABLE @itab2 UP TO 3 ROWS.
+
+ out->write( data = itab2 name = `itab2` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `35) FILTER: Filtering internal table by condition` ) ).
+
+ "This section covers multiple examples demonstrating the syntactical variety
+ "of the FILTER operator.
+
+ TYPES: BEGIN OF fi_str,
+ a TYPE i,
+ b TYPE c LENGTH 3,
+ c TYPE c LENGTH 3,
+ END OF fi_str.
+
+ "basic form, condition created with single values
+ "itab must have at least one sorted key or one hash key used for access.
+ "This variant of the filter operator is not possible for an internal table itab without a sorted key or hash key.
+ DATA fi_tab1 TYPE SORTED TABLE OF fi_str WITH NON-UNIQUE KEY a.
+ DATA fi_tab2 TYPE STANDARD TABLE OF fi_str WITH NON-UNIQUE SORTED KEY sec_key COMPONENTS a.
+ DATA fi_tab3 TYPE HASHED TABLE OF fi_str WITH UNIQUE KEY a.
+
+ "Filling internal tables
+ fi_tab1 = VALUE #( ( a = 1 b = 'aaa' c = 'abc' )
+ ( a = 2 b = 'bbb' c = 'def' )
+ ( a = 3 b = 'ccc' c = 'hij' )
+ ( a = 4 b = 'ddd' c = 'klm' )
+ ( a = 5 b = 'eee' c = 'nop' ) ).
+
+ fi_tab2 = fi_tab1.
+ fi_tab3 = fi_tab1.
+
+ "The lines meeting the condition are respected.
+ "Note: The source table must have at least one sorted or hashed key.
+ "Here, the primary key is used
+ DATA(f1) = FILTER #( fi_tab1 WHERE a >= 3 ).
+
+ out->write( data = f1 name = `f1` ).
+ out->write( |\n| ).
+
+ "USING KEY primary_key explicitly specified; same as above
+ DATA(f2) = FILTER #( fi_tab1 USING KEY primary_key WHERE a >= 3 ).
+
+ out->write( data = f2 name = `f2` ).
+ out->write( |\n| ).
+
+ "EXCEPT addition
+ DATA(f3) = FILTER #( fi_tab1 EXCEPT WHERE a >= 3 ).
+
+ out->write( data = f3 name = `f3` ).
+ out->write( |\n| ).
+
+ DATA(f4) = FILTER #( fi_tab1 EXCEPT USING KEY primary_key WHERE a >= 3 ).
+
+ out->write( data = f4 name = `f4` ).
+ out->write( |\n| ).
+
+ "Secondary table key specified after USING KEY
+ DATA(f5) = FILTER #( fi_tab2 USING KEY sec_key WHERE a >= 4 ).
+
+ out->write( data = f5 name = `f5` ).
+ out->write( |\n| ).
+
+ DATA(f6) = FILTER #( fi_tab2 EXCEPT USING KEY sec_key WHERE a >= 3 ).
+
+ out->write( data = f6 name = `f6` ).
+ out->write( |\n| ).
+
+ "Note: In case of a hash key, exactly one comparison expression for each key
+ "component is allowed; only = as comparison operator possible.
+ DATA(f7) = FILTER #( fi_tab3 WHERE a = 3 ).
+
+ out->write( data = f7 name = `f7` ).
+ out->write( |\n| ).
+
+ "Using a filter table
+ "In the WHERE condition, the columns of source and filter table are compared.
+ "Those lines in the source table are used for which at least one line in the
+ "filter table meets the condition. EXCEPT and USING KEY are also possible.
+
+ "Declaring and filling filter tables
+ DATA filter_tab1 TYPE SORTED TABLE OF i
+ WITH NON-UNIQUE KEY table_line.
+
+ DATA filter_tab2 TYPE STANDARD TABLE OF i
+ WITH EMPTY KEY
+ WITH UNIQUE SORTED KEY line COMPONENTS table_line.
+
+ filter_tab1 = VALUE #( ( 3 ) ( 5 ) ).
+ filter_tab2 = filter_tab1.
+
+ DATA(f8) = FILTER #( fi_tab1 IN filter_tab1 WHERE a = table_line ).
+
+ out->write( data = f8 name = `f8` ).
+ out->write( |\n| ).
+
+ "EXCEPT addition
+ DATA(f9) = FILTER #( fi_tab1 EXCEPT IN filter_tab1 WHERE a = table_line ).
+
+ out->write( data = f9 name = `f9` ).
+ out->write( |\n| ).
+
+ "USING KEY is specified for the filter table
+ DATA(f10) = FILTER #( fi_tab2 IN filter_tab2 USING KEY line WHERE a = table_line ).
+
+ out->write( data = f10 name = `f10` ).
+ out->write( |\n| ).
+
+ "USING KEY is specified for the source table, including EXCEPT
+ DATA(f11) = FILTER #( fi_tab2 USING KEY sec_key EXCEPT IN filter_tab2 WHERE a = table_line ).
+
+ out->write( data = f11 name = `f11` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `36) Inserting data into an internal table ` &&
+ `using a COLLECT statement` ) ).
+
+ "Internal table to work with
+ DATA itab_num TYPE SORTED TABLE OF l_type2
+ WITH UNIQUE KEY key_field.
+
+ itab_num = VALUE #( ( key_field = 1 num1 = 2 num2 = 3 )
+ ( key_field = 2 num1 = 4 num2 = 5 )
+ ( key_field = 3 num1 = 6 num2 = 7 ) ).
+
+ "Values of numeric components are added to the
+ "corresponding values in an internal table
+ COLLECT VALUE l_type2( key_field = 1 num1 = 10 num2 = 10 )
+ INTO itab_num.
+
+ out->write( data = itab_num name = `itab_num` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `37) Reading from internal tables` ) ).
+
+ "Filling internal tables
+ it_st = VALUE #( ( a = 1 b = 'aaa' c = 'bbb' d = 'ccc' )
+ ( a = 2 b = 'ddd' c = 'eee' d = 'fff' )
+ ( a = 3 b = 'ggg' c = 'hhh' d = 'iii' )
+ ( a = 4 b = 'jjj' c = 'kkk' d = 'lll' ) ).
+
+ "Declaring demo sorted/hashed tables having primary and
+ "secondary keys as well as alias names defined
+ DATA it_so_sec TYPE SORTED TABLE OF struc1
+ WITH NON-UNIQUE KEY primary_key ALIAS pk COMPONENTS a
+ WITH NON-UNIQUE SORTED KEY sec_key ALIAS sk COMPONENTS b.
+
+ DATA it_ha_sec TYPE HASHED TABLE OF struc1
+ WITH UNIQUE KEY primary_key ALIAS pkh COMPONENTS a
+ WITH NON-UNIQUE SORTED KEY sec_key_h ALIAS skh COMPONENTS b.
+
+ "Filling internal table
+ it_so_sec = VALUE #( ( a = 1 b = 'bbb' c = '###' d = '###' )
+ ( a = 2 b = 'ccc' c = '###' d = '###' )
+ ( a = 3 b = 'aaa' c = 'zzz' d = '###' )
+ ( a = 4 b = 'ddd' c = '###' d = '###' ) ).
+
+ "Filling internal table with the content above
+ it_ha_sec = it_so_sec.
+
+ out->write( `Original table content` ).
+ out->write( |\n| ).
+ out->write( |\n| ).
+ out->write( data = it_so_sec name = `it_so_sec` ).
+ out->write( |\n| ).
+ out->write( data = it_ha_sec name = `it_ha_sec` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `38) Reading a single line into target area` ) ).
+
+ "The examples anticipate the reading of a line by index since the
+ "syntax requires to specify the reading via index or key. Both
+ "inline declarations and existing target areas are demonstrated.
+
+ "Work area
+ READ TABLE it_so_sec INTO DATA(wa1) INDEX 1.
+ DATA wa2 LIKE LINE OF it_so_sec.
+
+ "The addition TRANSPORTING specifies which components are to be
+ "respected for the copying. If it is not specified, all components
+ "are respected.
+ READ TABLE it_so_sec INTO wa2 INDEX 2 TRANSPORTING a b c.
+
+ "Field symbol
+ READ TABLE it_so_sec ASSIGNING FIELD-SYMBOL() INDEX 3.
+
+ FIELD-SYMBOLS LIKE LINE OF it_so_sec.
+ READ TABLE it_st ASSIGNING INDEX 1.
+
+ "Data reference variable
+ READ TABLE it_so_sec REFERENCE INTO DATA(dref) INDEX 4.
+
+ DATA dref2 LIKE REF TO wa2.
+ READ TABLE it_so_sec REFERENCE INTO dref2 INDEX 2.
+
+ out->write( data = wa1 name = `wa1` ).
+ out->write( |\n| ).
+ out->write( data = wa2 name = `wa2` ).
+ out->write( |\n| ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
+ out->write( data = name = `` ).
+ out->write( |\n| ).
+ out->write( data = dref->* name = `dref->*` ).
+ out->write( |\n| ).
+ out->write( data = dref2->* name = `dref2->*` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `Reading a single line via index ...` ) ).
+ out->write( |39) ... using READ TABLE\n\n| ).
+
+ "Primary table index used implicitly
+ READ TABLE it_so_sec INTO DATA(wa3) INDEX 1.
+
+ "Primary table index used implicitly; result here: same as above
+ READ TABLE it_so_sec INTO DATA(wa4) INDEX 1 USING KEY primary_key.
+
+ "Primary table key alias; result here: same as above
+ READ TABLE it_so_sec INTO DATA(wa5) INDEX 1 USING KEY pk.
+
+ "Secondary table key; secondary table index used
+ READ TABLE it_so_sec INTO DATA(wa6) INDEX 1 USING KEY sec_key.
+
+ "Secondary table key alias; secondary table index used
+ "result here: same as above
+ READ TABLE it_so_sec INTO DATA(wa7) INDEX 1 USING KEY sk.
+
+ "Index access for hashed tables using secondary table index
+ READ TABLE it_ha_sec INTO DATA(wa8) INDEX 1 USING KEY sec_key_h.
+
+ out->write( data = wa3 name = `wa3` ).
+ out->write( |\n| ).
+ out->write( data = wa4 name = `wa4` ).
+ out->write( |\n| ).
+ out->write( data = wa5 name = `wa5` ).
+ out->write( |\n| ).
+ out->write( data = wa6 name = `wa6` ).
+ out->write( |\n| ).
+ out->write( data = wa7 name = `wa7` ).
+ out->write( |\n| ).
+ out->write( data = wa8 name = `wa8` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `40) ... table expressions (1)` ) ).
+
+ "Reading via index; primary table index is used implicitly
+ DATA(lv1) = it_so_sec[ 2 ].
+
+ "Note: A line that is not found results in an runtime error.
+ DATA(idx) = 10.
+
+ TRY.
+ DATA(lv2) = it_so_sec[ idx ].
+ CATCH cx_sy_itab_line_not_found.
+ DATA(error) = |Line with index { idx } does not exist.|.
+ ENDTRY.
+
+ "Reading via index and specifying the table index (via the key)
+ "to be read from
+ DATA(lv3) = it_so_sec[ KEY primary_key INDEX 1 ].
+
+ DATA(lv4) = it_so_sec[ KEY sec_key INDEX 4 ].
+
+ "Hashed table example (secondary table index)
+ DATA(lv5) = it_ha_sec[ KEY sec_key_h INDEX 3 ].
+
+ out->write( data = lv1 name = `lv1` ).
+ out->write( |\n| ).
+
+ IF lv2 IS NOT INITIAL.
+ out->write( data = lv2 name = `lv2` ).
+ out->write( |\n| ).
+ ENDIF.
+
+ IF error IS NOT INITIAL.
+ out->write( data = error name = `error` ).
+ out->write( |\n| ).
+ ENDIF.
+
+ out->write( data = lv3 name = `lv3` ).
+ out->write( |\n| ).
+ out->write( data = lv4 name = `lv4` ).
+ out->write( |\n| ).
+ out->write( data = lv5 name = `lv5` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `41) ... table expressions (2)` ) ).
+
+ "Copying a table line via table expression and embedding in
+ "a constructor expression
+ DATA(lv6) = VALUE #( it_so_sec[ 2 ] ).
+
+ "Reading into data reference variable using the REF operator
+ DATA(dref3) = REF #( it_so_sec[ 4 ] ).
+
+ "OPTIONAL/DEFAULT additions: An unsuccessful reading operation
+ "does not raise the exception; returns either an initial or
+ "default line in case of an unsuccessful reading operation
+ DATA(lv7) = VALUE #( it_so_sec[ 10 ] OPTIONAL ).
+
+ DATA(lv8) = VALUE #( it_so_sec[ 10 ] DEFAULT it_so_sec[ 2 ] ).
+
+ out->write( data = lv6 name = `lv6` ).
+ out->write( |\n| ).
+ out->write( data = dref3->* name = `dref3->*` ).
+ out->write( |\n| ).
+ out->write( data = lv7 name = `lv7` ).
+ out->write( |\n| ).
+ out->write( data = lv8 name = `lv8` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `Reading a single line via table keys ...` ) ).
+ out->write( |42) ... using READ TABLE (1)\n| ).
+
+ "Primary table key (COMPONENTS addition is optional)
+ READ TABLE it_so_sec INTO DATA(wa9)
+ WITH TABLE KEY primary_key COMPONENTS a = 1.
+
+ READ TABLE it_so_sec INTO DATA(wa10) WITH TABLE KEY a = 2.
+
+ "Primary table key alias
+ READ TABLE it_so_sec INTO DATA(wa11)
+ WITH TABLE KEY pk COMPONENTS a = 3.
+
+ "Secondary table key
+ READ TABLE it_so_sec INTO DATA(wa12)
+ WITH TABLE KEY sec_key COMPONENTS b = 'ddd'.
+
+ "Secondary table key alias
+ READ TABLE it_so_sec INTO DATA(wa13)
+ WITH TABLE KEY sk COMPONENTS b = 'ccc'.
+
+ out->write( data = wa9 name = `wa9` ).
+ out->write( |\n| ).
+ out->write( data = wa10 name = `wa10` ).
+ out->write( |\n| ).
+ out->write( data = wa11 name = `wa11` ).
+ out->write( |\n| ).
+ out->write( data = wa12 name = `wa12` ).
+ out->write( |\n| ).
+ out->write( data = wa13 name = `wa13` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `43) ... using READ TABLE (2)` ) ).
+
+ "Reading a line based on keys specified in a work area
+ "Here, the work area contains primary and secondary key values.
+ "The line type is compatible to the internal table.
+ DATA(pr_keys) = VALUE struc1( a = 2 ).
+
+ DATA(sec_keys) = VALUE struc1( b = 'aaa' ).
+
+ "Primary table key is used implicitly
+ READ TABLE it_so_sec FROM pr_keys INTO DATA(wa14).
+
+ "If USING KEY is not specified, the primary table key is used.
+ "If it is used, the specified table key is used.
+ "Secondary table key
+ READ TABLE it_so_sec FROM sec_keys
+ USING KEY sec_key INTO DATA(wa15).
+
+ "Primary table key; result: same as wa14
+ READ TABLE it_so_sec FROM pr_keys
+ USING KEY primary_key INTO DATA(wa16).
+
+ out->write( data = wa14 name = `wa14` ).
+ out->write( |\n| ).
+ out->write( data = wa15 name = `wa15` ).
+ out->write( |\n| ).
+ out->write( data = wa16 name = `wa16` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `44) ... using table expressions` ) ).
+ "Primary table key (COMPONENTS addition is optional)
+ DATA(lv9) = it_so_sec[ KEY primary_key COMPONENTS a = 1 ].
+
+ DATA(lv10) = it_so_sec[ KEY primary_key a = 1 ].
+
+ DATA(lv11) = it_so_sec[ KEY pk a = 2 ]. "Primary table key alias
+
+ "Secondary table key (COMPONENTS mandatory)
+ DATA(lv12) = it_so_sec[ KEY sec_key COMPONENTS b = 'aaa' ].
+
+ DATA(lv13) = it_so_sec[ KEY sk COMPONENTS b = 'ddd' ]. "Alias
+
+ out->write( data = lv9 name = `lv9` ).
+ out->write( |\n| ).
+ out->write( data = lv10 name = `lv10` ).
+ out->write( |\n| ).
+ out->write( data = lv11 name = `lv11` ).
+ out->write( |\n| ).
+ out->write( data = lv12 name = `lv12` ).
+ out->write( |\n| ).
+ out->write( data = lv13 name = `lv13` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `45) Reading a single line via free key` ) ).
+ "Note: If there a multiple matching entries, the first found
+ "is returned.
+ READ TABLE it_so_sec INTO DATA(wa17) WITH KEY c = '###'.
+
+ DATA(lv14) = it_so_sec[ c = 'zzz' ].
+
+ out->write( data = wa17 name = `wa17` ).
+ out->write( |\n| ).
+ out->write( data = lv14 name = `lv14` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `46) Excursion: Addressing individual components` ) ).
+ "Addressing a component using the component selector
+ DATA(comp1) = it_so_sec[ 1 ]-b.
+
+ READ TABLE it_so_sec ASSIGNING FIELD-SYMBOL() INDEX 2.
+
+ DATA(comp2) = -c.
+
+ READ TABLE it_so_sec REFERENCE INTO DATA(dref4) INDEX 3.
+
+ DATA(comp3) = dref->*-a.
+
+ "Same effect as above but less to write
+ DATA(comp4) = dref->b.
+
+ out->write( data = comp1 name = `comp1` ).
+ out->write( |\n| ).
+ out->write( data = comp2 name = `comp2` ).
+ out->write( |\n| ).
+ out->write( data = comp3 name = `comp3` ).
+ out->write( |\n| ).
+ out->write( data = comp4 name = `comp4` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `47) Checking if a line exists in an internal table` ) ).
+
+ "Defining the key
+ DATA(key1) = 2.
+
+ "Internal table function
+ IF line_exists( it_so_sec[ a = key1 ] ).
+ out->write( |Line { key1 } exists in internal table.| ).
+ ELSE.
+ out->write( |Line { key1 } does not exist in internal table.| ).
+ ENDIF.
+
+ out->write( |\n| ).
+
+ "Alternative using READ TABLE (sy-subrc is checked)
+ "When using the addition TRANSPORTING NO FIELDS, no field values
+ "are read. Only the system fields are filled.
+ READ TABLE it_so_sec WITH KEY a = key1 TRANSPORTING NO FIELDS.
+
+ IF sy-subrc = 0.
+ out->write( |Line { key1 } exists in internal table.| ).
+ ELSE.
+ out->write( |Line { key1 } does not exist in internal table.| ).
+ ENDIF.
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `48) Checking the index of a ` &&
+ `specific line` ) ).
+
+ DATA(key2) = 4.
+
+ DATA(idx_of_line1) = line_index( it_so_sec[ a = key2 ] ).
+
+ DATA(key3) = 10.
+
+ DATA(idx_of_line2) = line_index( it_so_sec[ a = key3 ] ).
+
+ "Alternative using READ TABLE
+ "The table index is written to the sy-tabix system field
+ READ TABLE it_so_sec WITH KEY a = key2 TRANSPORTING NO FIELDS.
+
+ IF sy-subrc = 0.
+ DATA(tab_idx1) = sy-tabix.
+ ENDIF.
+
+ READ TABLE it_so_sec WITH KEY a = key3 TRANSPORTING NO FIELDS.
+
+ IF sy-subrc = 0.
+ DATA(tab_idx2) = sy-tabix.
+ ENDIF.
+
+ IF idx_of_line1 <> 0.
+ out->write( |The index of the line with key = { key2 } | &&
+ |is { idx_of_line1 } in the internal table.| ).
+ ELSE.
+ out->write( |The line with key = { key2 } does not exist | &&
+ |in the internal table.| ).
+ ENDIF.
+
+ out->write( |\n| ).
+
+ IF idx_of_line2 <> 0.
+ out->write( |The index of the line with key = { key3 } | &&
+ |is { idx_of_line2 } in the internal table.| ).
+ ELSE.
+ out->write( |The line with key = { key3 } does not exist | &&
+ |in the internal table.| ).
+ ENDIF.
+
+ out->write( |\n| ).
+
+ IF tab_idx1 <> 0.
+ out->write( |The index of the line with key = { key2 } | &&
+ |is { tab_idx1 } in the internal table.| ).
+ ELSE.
+ out->write( |The line with key = { key2 } does not exist | &&
+ |in the internal table.| ).
+ ENDIF.
+
+out->write( |\n| ).
+
+ IF tab_idx2 <> 0.
+ out->write( |The index of the line with key = { key3 } | &&
+ |is { tab_idx2 } in the internal table.| ).
+ ELSE.
+ out->write( |The line with key = { key3 } does not exist | &&
+ |in the internal table.| ).
+ ENDIF.
+
+out->write( |\n| ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `49) Checking how many lines are in an` &&
+ ` internal table` ) ).
+ DATA(itab_lines) = lines( it_so_sec ).
+
+ out->write( |The internal table consists of { itab_lines } lines.| ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `Processing multiple internal table lines ` &&
+ `sequentially` ) ).
+ out->write( |50) Reading a complete table by sequentially reading all lines\n\n| ).
+
+ "No further addition: All lines are respected.
+ LOOP AT it_so_sec ASSIGNING FIELD-SYMBOL().
+ "Modifying a component to visualize the reading of all lines.
+ -b = 'ZZZ'.
+ ENDLOOP.
+
+ out->write( data = it_so_sec name = `it_so_sec` ).
+
+**********************************************************************
+
+ out->write( zcl_demo_abap_aux=>heading( `51) LOOP AT statements with different targets` ) ).
+
+ "The following examples demonstrate the different targets that
+ "are possible for LOOP AT statements. In the example above,
+ "a field symbol is created inline.
+ "As above, there are no additions to the loop statement, i.e. all lines
+ "are processed.
+
+ DATA(lines_in_table) = lines( it_so_sec ).
+ out->write( |There should be { lines_in_table } iterations per loop.| ).
+ out->write( |\n| ).
+
+ "Target: Existing work area
+ out->write( `---- Loop target: Existing work area ----` ).
+ out->write( |\n| ).
+ DATA wa_lo LIKE LINE OF it_so_sec.
+
+ LOOP AT it_so_sec INTO wa_lo.
+ IF sy-tabix = 1.
+ out->write( |This text is displayed when reaching line { sy-tabix }.| ).
+ ELSEIF sy-tabix = lines_in_table.
+ out->write( |This text is displayed when reaching line { sy-tabix }.| ).
+ ENDIF.
+ ENDLOOP.
+ out->write( |\n| ).
+ out->write( `---- Loop target: Work area created inline ----` ).
+ out->write( |\n| ).
+ LOOP AT it_so_sec INTO DATA(wa_inl).
+ IF sy-tabix = 1.
+ out->write( |This text is displayed when reaching line { sy-tabix }.| ).
+ ELSEIF sy-tabix = lines_in_table.
+ out->write( |This text is displayed when reaching line { sy-tabix }.| ).
+ ENDIF.
+ ENDLOOP.
+ out->write( |\n| ).
+ out->write( `---- Loop target: Existing field symbol ----` ).
+ out->write( |\n| ).
+ FIELD-SYMBOLS LIKE LINE OF it_so_sec.
+
+ LOOP AT it_so_sec ASSIGNING .
+ IF sy-tabix = 1.
+ out->write( |This text is displayed when reaching line { sy-tabix }.| ).
+ ELSEIF sy-tabix = lines_in_table.
+ out->write( |This text is displayed when reaching line { sy-tabix }.| ).
+ ENDIF.
+ ENDLOOP.
+ out->write( |\n| ).
+ out->write( `---- Loop target: Field symbol created inline ----` ).
+ out->write( |\n| ).
+ LOOP AT it_so_sec ASSIGNING FIELD-SYMBOL(