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(). + 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 data reference variable ----` ). + out->write( |\n| ). + DATA dref_lo TYPE REF TO struc1 . + + LOOP AT it_so_sec REFERENCE INTO dref_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: Data reference variable created inline ----` ). + out->write( |\n| ). + LOOP AT it_so_sec REFERENCE INTO DATA(dref_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( zcl_demo_abap_aux=>heading( `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. + + out->write( data = it_so_sec name = `it_so_sec` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( data = it_so_sec name = `it_so_sec` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( |There are { num } lines in the table fulfilling the condition.| ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( data = it_st_em name = `it_st_em` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `STEP addition in LOOP AT statements` ) ). + out->write( |56) Reversing loop order\n\n| ). + + 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. + + out->write( data = it_abc_result name = `it_abc_result` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( data = it_abc_result name = `it_abc_result` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( data = it_abc_result name = `it_abc_result` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `Creating and filling tables using table ` && + `iterations with FOR and VALUE` ) ). + out->write( |59) Retrieving values of one column in an internal table.\n\n| ). + + "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 ) ). + + out->write( data = lv_num_a name = `lv_num_a` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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 ) ). + + out->write( data = lv_num_b name = `lv_num_b` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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 ) ). + + out->write( data = itab_for_2tab name = `itab_for_2tab` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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' ) ). + + out->write( data = it_changed name = `it_changed` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( `Original internal table content ` && + `(it1 and it2 have the same content)` ). + out->write( |\n| ). + out->write( |\n| ). + out->write( data = it1 name = `it1` ). + out->write( |\n| ). + out->write( data = it2 name = `it2` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `64) Sorting by primary table key` ) ). + + "Primary key: component a + SORT it1. + + out->write( data = it1 name = `it1` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( data = it1 name = `it1` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `66) Sorting by primary table key respecting all ` && + `non-numeric fields` ) ). + + "Primary key: standard table key (all non-numeric fields) + SORT it2. + + out->write( data = 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. + "out->write( data = it3 name = `it3` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `67) Sorting by primary table key in ` && + `descending order` ) ). + + "Sorting in descending order and by primary table key + SORT it1 DESCENDING. + + out->write( data = it1 name = `it1` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( data = it1 name = `it1` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `69) Sorting by explicitly specified component (2)` ) ). + + "Sorting by arbitrary, non-key field + SORT it1 BY d DESCENDING. + + out->write( data = it1 name = `it1` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `70) Sorting by multiple explicitly specified` && + ` components` ) ). + + "Sorting by multiple components and specifying the sort order + SORT it1 BY b ASCENDING c DESCENDING. + + out->write( data = it1 name = `it1` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( data = it1 name = `it1` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `72) Modifying internal table content` ) ). + out->write( |Internal table content before modifications\n| ). + out->write( |\n| ). + + "Standard table + out->write( data = it_st name = `it_st` ). + out->write( |\n| ). + + "Sorted table + out->write( data = it_so_sec name = `it_so_sec` ). + out->write( |\n| ). + + "Hashed table + out->write( data = it_ha_sec name = `it_ha_sec` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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' ). + + out->write( data = it_so_sec[ 1 ] name = `it_so_sec[ 1 ]` ). + out->write( |\n| ). + out->write( data = it_st[ 1 ] name = `it_st[ 1 ]` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( data = it_st name = `it_st` ). + 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( `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. + + out->write( data = it_st name = `it_st` ). + 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( `76) Deleting adjacent duplicate entries` ) ). + out->write( `Original table content (restored before` && + ` each of the following examples)` ). + out->write( |\n| ). + out->write( |\n| ). + + 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. + + out->write( data = it_st2 name = `it_st2` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( data = it_st2 name = `it_st2` ). + + it_st2 = it_st. + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `78) Deleting adjacent duplicates by comparing ` && + `all field values` ) ). + + DELETE ADJACENT DUPLICATES FROM it_st2 COMPARING ALL FIELDS. + + out->write( data = it_st2 name = `it_st2` ). + + it_st2 = it_st. + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `79) Deleting adjacent duplicates by comparing ` && + `specific field values` ) ). + + DELETE ADJACENT DUPLICATES FROM it_st2 COMPARING a c. + + out->write( data = it_st2 name = `it_st2` ). + + it_st2 = it_st. + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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. + + out->write( data = it_st2 name = `it_st2` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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 #( ). + + out->write( data = it_st name = `it_st` ). + out->write( |\n| ). + out->write( data = it_st2 name = `it_st2` ). + out->write( |\n| ). + out->write( data = it_str name = `it_str` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `Excursions` ) ). + out->write( |82) Secondary table keys and hashed tables\n\n| ). + + "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. + + out->write( data = int_itab name = `int_itab` ). + out->write( |\n| ). + + 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. + + out->write( data = int_itab name = `int_itab` ). + out->write( |\n| ). + + "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 ]. + + out->write( data = line_of_ht name = `line_of_ht` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `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( ). + + + out->write( data = k1 name = `k1` ). + out->write( |\n| ). + + DATA(k2) = CAST cl_abap_tabledescr( + cl_abap_typedescr=>describe_by_data( + it_inline ) + )->get_keys( ). + + out->write( data = k2 name = `k2` ). + ENDMETHOD. +ENDCLASS. diff --git a/src/zcl_demo_abap_objects.clas.abap b/src/zcl_demo_abap_objects.clas.abap index 4a5f636..0c9a9f8 100644 --- a/src/zcl_demo_abap_objects.clas.abap +++ b/src/zcl_demo_abap_objects.clas.abap @@ -81,7 +81,7 @@ ENDCLASS. -CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. +CLASS zcl_demo_abap_objects IMPLEMENTATION. METHOD hallo_instance_method. @@ -98,11 +98,9 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. METHOD if_oo_adt_classrun~main. - DATA(output) = NEW zcl_demo_abap_display( out ). - - output->display( `ABAP Cheat Sheet Example: ABAP Object Orientation` ). - output->display( `Working with objects and components` ). - output->display( `1) Declaring reference variables` ). + out->write( |ABAP Cheat Sheet Example: ABAP Object Orientation\n\n| ). + out->write( |Working with objects and components\n\n| ). + out->write( |1) Declaring reference variables\n\n| ). "To create an object, a reference variable must be declared. This "variable is also necessary for accessing objects, i. e. objects @@ -124,15 +122,15 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. AND ref1b IS INITIAL AND ref1c IS INITIAL AND ref1d IS INITIAL. - output->display( `The declared reference variables are initial.` ). + out->write( `The declared reference variables are initial.` ). ELSE. - output->display( `One or more of the declared reference ` && + out->write( `One or more of the declared reference ` && `variables are not initial.` ). ENDIF. ********************************************************************** - output->next_section( `2) Creating objects` ). + out->write( zcl_demo_abap_aux=>heading( `2) Creating objects` ) ). "You create an object in the memory of an application by using the "instance operator NEW. In doing so, a new instance of a @@ -154,16 +152,16 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. IF ref2a IS INSTANCE OF local_class AND ref2b IS INSTANCE OF local_class. - output->display( `ref2a and ref2b point to instances ` && + out->write( `ref2a and ref2b point to instances ` && `of the class local_class.` ). ELSE. - output->display( `One or more of the reference variables ` && + out->write( `One or more of the reference variables ` && `do not point to instances of the class local_class.` ). ENDIF. ********************************************************************** - output->next_section( `3) Assigning object references` ). + out->write( zcl_demo_abap_aux=>heading( `3) Assigning object references` ) ). "Without an assignment, the reference variable is empty. "To assign or copy reference variable, use the assignment operator @@ -176,14 +174,14 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. ref3a = ref3b. IF ref3a = ref3b. - output->display( `ref3b has been assigned to ref3a.` ). + out->write( `ref3b has been assigned to ref3a.` ). ELSE. - output->display( `ref3b has not been assigned to ref3a.` ). + out->write( `ref3b has not been assigned to ref3a.` ). ENDIF. ********************************************************************** - output->next_section( `4) Overwriting object references` ). + out->write( zcl_demo_abap_aux=>heading( `4) Overwriting object references` ) ). "An object reference is overwritten when a new object is created "with a reference variable already pointing to an instance. @@ -195,15 +193,16 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. ref4 = NEW #( ). - output->display( input = ref4->no_of_instances name = `ref4->no_of_instances` ). + out->write( data = ref4->no_of_instances name = `ref4->no_of_instances` ). + out->write( |\n| ). ref4 = NEW #( ). - output->display( input = ref4->no_of_instances name = `ref4->no_of_instances` ). + out->write( data = ref4->no_of_instances name = `ref4->no_of_instances` ). ********************************************************************** - output->next_section( `5) Keeping references variables in internal tables` ). + out->write( zcl_demo_abap_aux=>heading( `5) Keeping references variables in internal tables` ) ). "The following code shows that the reference variable is "overwritten in the course of the loop multiple times. @@ -221,11 +220,11 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. itab5 = VALUE #( BASE itab5 ( ref5 ) ). ENDDO. - output->display( input = itab5 name = `itab5` ). + out->write( data = itab5 name = `itab5` ). ********************************************************************** - output->next_section( `6) Clearing object references` ). + out->write( zcl_demo_abap_aux=>heading( `6) Clearing object references` ) ). "Use CLEAR statements to explicitly clear a reference variable. "Since objects use up space in the memory, they should be cleared @@ -240,14 +239,14 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. CLEAR ref6. IF ref6 IS INITIAL. - output->display( `ref6 is initial.` ). + out->write( `ref6 is initial.` ). ELSE. - output->display( `ref6 is not initial.` ). + out->write( `ref6 is not initial.` ). ENDIF. ********************************************************************** - output->next_section( `7) Accessing and using attributes` ). + out->write( zcl_demo_abap_aux=>heading( `7) Accessing and using attributes` ) ). "Instance attributes are accessed using the object component "selector -> via a reference variable. Visible static attributes @@ -271,13 +270,15 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. DATA some_other_int TYPE local_class=>type_i. TYPES int_type TYPE local_class=>type_i. - output->display( input = obj_instance_attr name = `obj_instance_attr` ). - output->display( input = obj_static_attr_obj name = `obj_static_attr_obj` ). - output->display( input = class_static_attr name = `class_static_attr` ). + out->write( data = obj_instance_attr name = `obj_instance_attr` ). + out->write( |\n| ). + out->write( data = obj_static_attr_obj name = `obj_static_attr_obj` ). + out->write( |\n| ). + out->write( data = class_static_attr name = `class_static_attr` ). ********************************************************************** - output->next_section( `8) Calling static and instance methods` ). + out->write( zcl_demo_abap_aux=>heading( `8) Calling static and instance methods` ) ). "Similar to accessing attributes, instance methods are called "using -> via a reference variable. Static methods are called @@ -296,12 +297,14 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. DATA(ref8) = NEW zcl_demo_abap_objects( ). ref8->hallo_instance_method( ). - output->display( input = string name = `string` ). + out->write( data = string name = `string` ). + out->write( |\n| ). "Static methods lcl_demo=>hallo_static_ext( ). - output->display( input = lcl_demo=>string name = `lcl_demo=>string` ). + out->write( data = lcl_demo=>string name = `lcl_demo=>string` ). + out->write( |\n| ). "If methods are within the class where they are called, "the class name can be omitted. @@ -309,12 +312,12 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. hallo_static_method( ). - output->display( input = string name = `string` ). + out->write( data = string name = `string` ). ********************************************************************** - output->next_section( `9) Calling methods: Examples` && - ` with importing parameters` ). + out->write( zcl_demo_abap_aux=>heading( `9) Calling methods: Examples` && + ` with importing parameters` ) ). "The example shows method calls. The methods used have only one or "two importing parameters. @@ -338,29 +341,33 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. "Method with one importing parameter. lcl_demo=>powers_of_two( 4 ). - output->display( input = lcl_demo=>calc_result name = `lcl_demo=>calc_result` ). + out->write( data = lcl_demo=>calc_result name = `lcl_demo=>calc_result` ). + out->write( |\n| ). lcl_demo=>powers_of_two( i_pow = 5 ). - output->display( input = lcl_demo=>calc_result name = `lcl_demo=>calc_result` ). + out->write( data = lcl_demo=>calc_result name = `lcl_demo=>calc_result` ). + out->write( |\n| ). lcl_demo=>powers_of_two( EXPORTING i_pow = 6 ). - output->display( input = lcl_demo=>calc_result name = `lcl_demo=>calc_result` ). + out->write( data = lcl_demo=>calc_result name = `lcl_demo=>calc_result` ). + out->write( |\n| ). "Method with two importing parameters lcl_demo=>addition( i_add1 = 1 i_add2 = 4 ). - output->display( input = lcl_demo=>calc_result name = `lcl_demo=>calc_result` ). + out->write( data = lcl_demo=>calc_result name = `lcl_demo=>calc_result` ). + out->write( |\n| ). lcl_demo=>addition_optional( i_add_mand = 1 ). - output->display( input = lcl_demo=>calc_result name = `lcl_demo=>calc_result` ). + out->write( data = lcl_demo=>calc_result name = `lcl_demo=>calc_result` ). ********************************************************************** - output->next_section( `10) Calling methods: Examples ` && - `with exporting parameters` ). + out->write( zcl_demo_abap_aux=>heading( `10) Calling methods: Examples ` && + `with exporting parameters` ) ). "Note: The methods have exporting parameters defined in the signature, "hence, when calling the method, the ABAP word IMPORTING must be used to @@ -382,12 +389,13 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. lcl_demo=>subtraction( EXPORTING i_sub1 = 10 i_sub2 = 7 IMPORTING e_sub_result = DATA(subtraction_result) ). - output->display( input = hallo name = `hallo` ). - output->display( input = subtraction_result name = `subtraction_result` ). + out->write( data = hallo name = `hallo` ). + out->write( |\n| ). + out->write( data = subtraction_result name = `subtraction_result` ). ********************************************************************** - output->next_section( `11) Calling methods: Example with changing parameter` ). + out->write( zcl_demo_abap_aux=>heading( `11) Calling methods: Example with changing parameter` ) ). "Changing parameters define one or multiple parameters that can "be both imported and exported. They should be reserved for @@ -397,11 +405,11 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. lcl_demo=>square_root( CHANGING i_sqr = num ). - output->display( input = num name = `num` ). + out->write( data = num name = `num` ). ********************************************************************** - output->next_section( `12) Calling methods: Examples with returning parameters` ). + out->write( zcl_demo_abap_aux=>heading( `12) Calling methods: Examples with returning parameters` ) ). "Methods having a returning parameter are called functional methods. "Returning parameters are preferable to exporting parameters since they @@ -420,28 +428,33 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. DATA(mult_result) = lcl_demo=>multiplication( i_mult1 = 4 i_mult2 = 5 ). - output->display( input = mult_result name = `mult_result` ). + out->write( data = mult_result name = `mult_result` ). + out->write( |\n| ). "Comparing a method having exporting parameters doing the same. lcl_demo=>multiplication_exp_param( EXPORTING i_multa = 5 i_multb = 6 IMPORTING e_mult_result = DATA(mult_res_exp) ). - output->display( input = mult_res_exp name = `mult_res_exp` ). + out->write( data = mult_res_exp name = `mult_res_exp` ). + out->write( |\n| ). "Example with a logical expression IF lcl_demo=>multiplication( i_mult1 = 5 i_mult2 = 3 ) < 20. - output->display( |The value is lower than 20.| ). + out->write( |The value is lower than 20.| ). ELSE. - output->display( |The value is greater than 20.| ). + out->write( |The value is greater than 20.| ). ENDIF. + out->write( |\n| ). + "Receiving parameter lcl_demo=>multiplication( EXPORTING i_mult1 = 10 i_mult2 = 11 RECEIVING r_mult_result = DATA(res_received) ). - output->display( input = res_received name = `res_received` ). + out->write( data = res_received name = `res_received` ). + out->write( |\n| ). "Example for method chaining using a global class. DATA(random_no1) = cl_abap_random_int=>create( )->get_next( ). @@ -459,13 +472,15 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. DATA(random_no3) = ref_randnom_no->get_next( ). - output->display( input = random_no1 name = `random_no1` ). - output->display( input = random_no2 name = `random_no2` ). - output->display( input = random_no3 name = `random_no3` ). + out->write( data = random_no1 name = `random_no1` ). + out->write( |\n| ). + out->write( data = random_no2 name = `random_no2` ). + out->write( |\n| ). + out->write( data = random_no3 name = `random_no3` ). ********************************************************************** - output->next_section( `13) Calling methods: Examples with error handling` ). + out->write( zcl_demo_abap_aux=>heading( `13) Calling methods: Examples with error handling` ) ). "The examples show two method calls for a method that includes a "raising parameter. For this method, a class-based exception is @@ -480,18 +495,22 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. i_div2 = 2 ). IF lcl_demo=>string IS INITIAL. - output->display( input = div_result1 name = `div_result1` ). + out->write( data = div_result1 name = `div_result1` ). ELSE. - output->display( |Calculation error: { lcl_demo=>string }| ). + out->write( |Calculation error: { lcl_demo=>string }| ). ENDIF. + out->write( |\n| ). + DATA(div_result2) = lcl_demo=>division( i_div1 = 1 i_div2 = 0 ). IF lcl_demo=>string IS INITIAL. - output->display( input = div_result2 name = `div_result2` ). + out->write( data = div_result2 name = `div_result2` ). ELSE. - output->display( |Calculation error: { lcl_demo=>string }| ). + out->write( |Calculation error: { lcl_demo=>string }| ). ENDIF. + out->write( |\n| ). + "Method with RAISING addition (class-based exceptions) TRY. lcl_demo=>check_daytime( @@ -503,11 +522,11 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. subrc = 33. ENDTRY. - output->display( input = greets name = `greets` ). + out->write( data = greets name = `greets` ). ********************************************************************** - output->next_section( `14) Constructors` ). + out->write( zcl_demo_abap_aux=>heading( `14) Constructors` ) ). "Constructors cannot be explicitly called like other methods. "The examples demonstrate instance and static constructors. @@ -530,36 +549,40 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. TRY. DATA(ref14a) = NEW lcl_constructors( num1 = 10 num2 = 5 ). CATCH cx_sy_zerodivide INTO DATA(error). - output->display( input = error->get_text( ) name = `error->get_text( )` ). + out->write( data = error->get_text( ) name = `error->get_text( )` ). ENDTRY. - output->display( input = ref14a name = `ref14a` ). + out->write( data = ref14a name = `ref14a` ). + out->write( |\n| ). TRY. DATA(ref14b) = NEW lcl_constructors( num1 = 18 num2 = 6 ). CATCH cx_sy_zerodivide INTO error. - output->display( input = error->get_text( ) name = `error->get_text( )` ). + out->write( data = error->get_text( ) name = `error->get_text( )` ). ENDTRY. - output->display( input = ref14b name = `ref14b` ). + out->write( data = ref14b name = `ref14b` ). + out->write( |\n| ). TRY. DATA(ref14c) = NEW lcl_constructors( num1 = 1 num2 = 0 ). CATCH cx_sy_zerodivide INTO error. - output->display( |Error with ref14c: { error->get_text( ) }| ). + out->write( |Error with ref14c: { error->get_text( ) }| ). ENDTRY. - output->display( input = ref14c name = `ref14c` ). + out->write( data = ref14c name = `ref14c` ). + out->write( |\n| ). "Static constructor lcl_constructors=>add_1( ). - output->display( input = lcl_constructors=>stat_text name = `lcl_constructors=>stat_text` ). - output->display( input = lcl_constructors=>stat_number name = `lcl_constructors=>stat_number` ). + out->write( data = lcl_constructors=>stat_text name = `lcl_constructors=>stat_text` ). + out->write( |\n| ). + out->write( data = lcl_constructors=>stat_number name = `lcl_constructors=>stat_number` ). ********************************************************************** - output->next_section( `15) Parameters: Generic types` ). + out->write( zcl_demo_abap_aux=>heading( `15) Parameters: Generic types` ) ). "The use of generic types in method signatures is particularly relevant "for dynamic programming. The code shows various examples of parameters @@ -571,7 +594,8 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. lcl_demo=>generic_data( EXPORTING i_data = int ). - output->display( input = lcl_demo=>some_data->* name = `lcl_demo=>some_data->*` ). + out->write( data = lcl_demo=>some_data->* name = `lcl_demo=>some_data->*` ). + out->write( |\n| ). DATA strtab TYPE TABLE OF string. @@ -579,7 +603,8 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. lcl_demo=>generic_data( EXPORTING i_data = strtab ). - output->display( input = lcl_demo=>some_data->* name = `lcl_demo=>some_data->*` ). + out->write( data = lcl_demo=>some_data->* name = `lcl_demo=>some_data->*` ). + out->write( |\n| ). DATA int_tab TYPE TABLE OF i. @@ -591,15 +616,17 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. lcl_demo=>generic_tab( EXPORTING i_anytab = int_tab ). - output->display( input = lcl_demo=>some_data->* name = `lcl_demo=>some_data->*` ). + out->write( data = lcl_demo=>some_data->* name = `lcl_demo=>some_data->*` ). + out->write( |\n| ). lcl_demo=>generic_tab( EXPORTING i_anytab = c_tab ). - output->display( input = lcl_demo=>some_data->* name = `lcl_demo=>some_data->*` ). + out->write( data = lcl_demo=>some_data->* name = `lcl_demo=>some_data->*` ). + out->write( |\n| ). ********************************************************************** - output->next_section( `16) Inheritance: Method redefinition` ). + out->write( zcl_demo_abap_aux=>heading( `16) Inheritance: Method redefinition` ) ). "The example demonstrates inheritance in a very rudimentary way. "Class 1 is the superclass of class 2 that inherits from class 1. The @@ -624,13 +651,15 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. DATA(third_string) = ref_inh3->get_string( ). - output->display( input = first_string name = `first_string` ). - output->display( input = second_string name = `second_string` ). - output->display( input = third_string name = `third_string` ). + out->write( data = first_string name = `first_string` ). + out->write( |\n| ). + out->write( data = second_string name = `second_string` ). + out->write( |\n| ). + out->write( data = third_string name = `third_string` ). ********************************************************************** - output->next_section( `17) Polymorphism and Casting` ). + out->write( zcl_demo_abap_aux=>heading( `17) Polymorphism and Casting` ) ). "The ref_pol1 object reference variable is created and points to class "lcl_class1, i. e. the superclass. The ref_pol2 object reference @@ -666,12 +695,13 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. ref_pol_super = NEW lcl_class2a( ). - output->display( input = str1 name = `str1` ). - output->display( input = str2 name = `str2` ). + out->write( data = str1 name = `str1` ). + out->write( |\n| ). + out->write( data = str2 name = `str2` ). ********************************************************************** - output->next_section( `18a) Downcast` ). + out->write( zcl_demo_abap_aux=>heading( `18a) Downcast` ) ). "In this example, the possibility of downcasts are checked, i. e. the "assignment of a more generic object reference variable to a specific @@ -770,11 +800,11 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. ENDIF. ENDLOOP. - output->display( input = dc_check name = `dc_check` ). + out->write( data = dc_check name = `dc_check` ). ********************************************************************** - output->next_section( `18b) Excursion RTTI: Downcasts and Method Chaining` ). + out->write( zcl_demo_abap_aux=>heading( `18b) Excursion RTTI: Downcasts and Method Chaining` ) ). "Downcasts particularly play, for example, a role in the context of "retrieving type information using RTTI. Method chaining is handy @@ -790,17 +820,18 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. DATA(rtti_b) = CAST cl_abap_structdescr( rtti_a ). DATA(rtti_c) = rtti_b->components. - output->display( input = rtti_c name = `rtti_c` ). + out->write( data = rtti_c name = `rtti_c` ). + out->write( |\n| ). DATA(rtti_d) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( struct4cast ) )->components. - output->display( input = rtti_d name = `rtti_d` ). + out->write( data = rtti_d name = `rtti_d` ). ********************************************************************** - output->next_section( `19) Interfaces` ). + out->write( zcl_demo_abap_aux=>heading( `19) Interfaces` ) ). "Addressing instance interface components using interface reference variable DATA ref_if1 TYPE REF TO zdemo_abap_objects_interface. @@ -862,26 +893,38 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. DATA(intf_const2) = zcl_demo_abap_objects=>zdemo_abap_objects_interface~const_intf. DATA(intf_const3) = ref_if2->const_intf. - output->display( input = inst_intf_attr_via_iref name = `inst_intf_attr_via_iref` ). - output->display( input = inst_intf_meth_via_iref1 name = `inst_intf_meth_via_iref1` ). - output->display( input = inst_intf_meth_via_iref2 name = `inst_intf_meth_via_iref2` ). - output->display( input = inst_intf_attr_via_cref name = `inst_intf_attr_via_cref` ). - output->display( input = inst_intf_meth_via_cref name = `inst_intf_meth_via_cref` ). + out->write( data = inst_intf_attr_via_iref name = `inst_intf_attr_via_iref` ). + out->write( |\n| ). + out->write( data = inst_intf_meth_via_iref1 name = `inst_intf_meth_via_iref1` ). + out->write( |\n| ). + out->write( data = inst_intf_meth_via_iref2 name = `inst_intf_meth_via_iref2` ). + out->write( |\n| ). + out->write( data = inst_intf_attr_via_cref name = `inst_intf_attr_via_cref` ). + out->write( |\n| ). + out->write( data = inst_intf_meth_via_cref name = `inst_intf_meth_via_cref` ). + out->write( |\n| ). - output->display( input = stat_intf_attr1 name = `stat_intf_attr1` ). - output->display( input = stat_intf_meth1 name = `stat_intf_meth1` ). - output->display( input = stat_intf_meth2 name = `stat_intf_meth2` ). - output->display( input = stat_intf_attr2 name = `stat_intf_attr2` ). - output->display( input = stat_intf_meth3 name = `stat_intf_meth3` ). - output->display( input = stat_intf_meth4 name = `stat_intf_meth4` ). + out->write( data = stat_intf_attr1 name = `stat_intf_attr1` ). + out->write( |\n| ). + out->write( data = stat_intf_meth1 name = `stat_intf_meth1` ). + out->write( |\n| ). + out->write( data = stat_intf_meth2 name = `stat_intf_meth2` ). + out->write( |\n| ). + out->write( data = stat_intf_attr2 name = `stat_intf_attr2` ). + out->write( |\n| ). + out->write( data = stat_intf_meth3 name = `stat_intf_meth3` ). + out->write( |\n| ). + out->write( data = stat_intf_meth4 name = `stat_intf_meth4` ). - output->display( input = intf_const1 name = `intf_const1` ). - output->display( input = intf_const2 name = `intf_const2` ). - output->display( input = intf_const3 name = `intf_const3` ). + out->write( data = intf_const1 name = `intf_const1` ). + out->write( |\n| ). + out->write( data = intf_const2 name = `intf_const2` ). + out->write( |\n| ). + out->write( data = intf_const3 name = `intf_const3` ). ********************************************************************** - output->next_section( `20) Singleton` ). + out->write( zcl_demo_abap_aux=>heading( `20) Singleton` ) ). "The demonstrates an implementation of the singleton design pattern. "A static method allows access to the only object of the class. @@ -904,8 +947,10 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. DATA(timestamp) = obj1->get_timestamp( ). DATA(no_of_instances) = lcl_singleton=>no_of_instances. - output->display( input = timestamp name = `timestamp` ). - output->display( input = no_of_instances name = `no_of_instances` ). + out->write( data = timestamp name = `timestamp` ). + out->write( |\n| ). + out->write( data = no_of_instances name = `no_of_instances` ). + out->write( |\n| ). "Trying to get another instance obj2 = lcl_singleton=>get_instance( ). @@ -914,8 +959,10 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. timestamp = obj2->get_timestamp( ). no_of_instances = lcl_singleton=>no_of_instances. - output->display( input = timestamp name = `timestamp` ). - output->display( input = no_of_instances name = `no_of_instances` ). + out->write( data = timestamp name = `timestamp` ). + out->write( |\n| ). + out->write( data = no_of_instances name = `no_of_instances` ). + out->write( |\n| ). "Trying to get another instance DATA(obj3) = lcl_singleton=>get_instance( ). @@ -924,12 +971,13 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. timestamp = obj3->get_timestamp( ). no_of_instances = lcl_singleton=>no_of_instances. - output->display( input = timestamp name = `timestamp` ). - output->display( input = no_of_instances name = `no_of_instances` ). + out->write( data = timestamp name = `timestamp` ). + out->write( |\n| ). + out->write( data = no_of_instances name = `no_of_instances` ). ********************************************************************** - output->next_section( `21) Factory method in an abstract class` ). + out->write( zcl_demo_abap_aux=>heading( `21) Factory method in an abstract class` ) ). "The example demonstrates a factory method in an abstract class. An "instance is tried to be created two times. The factory method is @@ -938,33 +986,40 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. "is only allowed if the value '1' is passed to the factory method. The "second instance creation fails on purpose. - output->display( `First try: inst_1` ). + out->write( `First try: inst_1` ). + out->write( |\n| ). + out->write( |\n| ). TRY. DATA(inst_1) = lcl_abstract=>factory_method( 1 ). DATA(str_1) = inst_1->return_string( `inst_1` ). - output->display( input = str_1 name = `str_1` ). + out->write( data = str_1 name = `str_1` ). CATCH cx_sy_ref_is_initial INTO DATA(error1). - output->display( |Error message: { error1->get_text( ) }| ). + out->write( |Error message: { error1->get_text( ) }| ). ENDTRY. - output->display( input = lcl_abstract=>message name = `lcl_abstract=>message` ). + out->write( |\n| ). + out->write( data = lcl_abstract=>message name = `lcl_abstract=>message` ). + out->write( |\n| ). - output->display( `Second try: inst_2` ). + out->write( `Second try: inst_2` ). + out->write( |\n| ). TRY. DATA(inst_2) = lcl_abstract=>factory_method( 2 ). DATA(str_2) = inst_2->return_string( `inst_2` ). - output->display( input = str_2 name = `str_2` ). + out->write( data = str_2 name = `str_2` ). CATCH cx_sy_ref_is_initial INTO DATA(error2). - output->display( |Error message: { error2->get_text( ) }| ). + out->write( |Error message: { error2->get_text( ) }| ). ENDTRY. - output->display( input = lcl_abstract=>message name = `lcl_abstract=>message` ). + out->write( |\n| ). + out->write( |\n| ). + out->write( data = lcl_abstract=>message name = `lcl_abstract=>message` ). ********************************************************************** - output->next_section( `22) Friendship: Accessing components of friends` ). + out->write( zcl_demo_abap_aux=>heading( `22) Friendship: Accessing components of friends` ) ). "Classes can grant friendship to other classes and interfaces to enable "the access to protected and private components. However, the friendship @@ -979,11 +1034,11 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. DATA(string_table) = zcl_demo_abap_objects_friend=>get_strings( ). - output->display( input = string_table name = `string_table` ). + out->write( data = string_table name = `string_table` ). ********************************************************************** - output->next_section( `23) Self-reference me` ). + out->write( zcl_demo_abap_aux=>heading( `23) Self-reference me` ) ). "This example demonstrates the use of the self-reference 'me' in an "instance method. The method implementation includes a variable of type @@ -998,12 +1053,13 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. ref_var->me_ref_meth( IMPORTING e1 = DATA(string_without_me) e2 = DATA(string_with_me) ). - output->display( input = string_without_me name = `string_without_me` ). - output->display( input = string_with_me name = `string_with_me` ). + out->write( data = string_without_me name = `string_without_me` ). + out->write( |\n| ). + out->write( data = string_with_me name = `string_with_me` ). ********************************************************************** - output->next_section( `24) Events` ). + out->write( zcl_demo_abap_aux=>heading( `24) Events` ) ). "The example covers the use of instance events. Event handler methods "are registered for a particular instance. Events are raised in a method @@ -1022,7 +1078,7 @@ CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION. "Calling method that raises an event ref_events->greetings( ). - output->display( input = ref_events->greets name = `ref_events->greets` ). + out->write( data = ref_events->greets name = `ref_events->greets` ). ENDMETHOD. diff --git a/src/zcl_demo_abap_prog_flow_logic.clas.abap b/src/zcl_demo_abap_prog_flow_logic.clas.abap index 29be1a7..ecba3ba 100644 --- a/src/zcl_demo_abap_prog_flow_logic.clas.abap +++ b/src/zcl_demo_abap_prog_flow_logic.clas.abap @@ -50,7 +50,7 @@ CLASS zcl_demo_abap_prog_flow_logic DEFINITION PUBLIC SECTION. INTERFACES: if_oo_adt_classrun. -protected section. + PROTECTED SECTION. PRIVATE SECTION. "Structured type for calculation example @@ -95,13 +95,13 @@ protected section. RAISING cx_sy_arithmetic_overflow. CLASS-DATA: exception_text TYPE string, - exception TYPE REF TO cx_root. + exception TYPE REF TO cx_root. ENDCLASS. -CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. +CLASS zcl_demo_abap_prog_flow_logic IMPLEMENTATION. METHOD addition. @@ -214,13 +214,11 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. METHOD if_oo_adt_classrun~main. - DATA(output) = NEW zcl_demo_abap_display( out ). - - output->display( `ABAP Cheat Sheet Example: Program Flow Logic` ). + out->write( |ABAP Cheat Sheet Example: Program Flow Logic\n\n| ). ********************************************************************** - output->display( `1) Control Structure with IF` ). + out->write( |1) Control Structure with IF\n| ). "Simple control structure realized by an IF ... ELSEIF ... ELSE ... ENDIF. "statement. Multiple statement blocks can be included, of which only 1 is @@ -239,22 +237,16 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. DATA(num2) = 7. IF operator = `+`. - - output->display( |The result of { num1 } { operator } { num2 } is { num1 + num2 }. | ). - + out->write( |The result of { num1 } { operator } { num2 } is { num1 + num2 }. | ). ELSEIF operator = `-`. - - output->display( |The result of { num1 } { operator } { num2 } is { num1 - num2 }. | ). - + out->write( |The result of { num1 } { operator } { num2 } is { num1 - num2 }. | ). ELSE. - - output->display( |The operator { operator } is not possible.| ). - + out->write( |The operator { operator } is not possible.| ). ENDIF. ********************************************************************** - output->next_section( `2) IF: Checking sy-subrc` ). + out->write( zcl_demo_abap_aux=>heading( `2) IF: Checking sy-subrc` ) ). "A prominent use case for IF statements: Checking sy-subrc. "In the case below, a FIND statement is used. If there is a finding, @@ -266,18 +258,14 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. FIND to_be_found IN string_to_search. IF sy-subrc = 0. - - output->display( |'{ to_be_found }' was found in the string '{ string_to_search }'.| ). - + out->write( |'{ to_be_found }' was found in the string '{ string_to_search }'.| ). ELSE. - - output->display( |'{ to_be_found }' was not found in the string '{ string_to_search }'.| ). - + out->write( |'{ to_be_found }' was not found in the string '{ string_to_search }'.| ). ENDIF. ********************************************************************** - output->next_section( `3) Excursion: COND Operator` ). + out->write( zcl_demo_abap_aux=>heading( `3) Excursion: COND Operator` ) ). "The conditional operator COND can also be used to implement branches in operand positions "that are based on logical expressions. Such conditional expressions have a result that @@ -294,11 +282,11 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. THEN |It's { syst_time TIME = ISO }. Good night, { sy-uname }.| ELSE |It's { syst_time TIME = ISO }. Hallo, { sy-uname }.| ). - output->display( input = greetings name = `greetings` ). + out->write( data = greetings name = `greetings` ). ********************************************************************** - output->next_section( `4) Expressions and Functions for Conditions` ). + out->write( zcl_demo_abap_aux=>heading( `4) Expressions and Functions for Conditions` ) ). "Control structures are generally controlled by logical expressions that "define conditions for operands. The result of such an expression is either true or false. @@ -432,16 +420,14 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "Table expression AND str_table[ 2 ] = `b`. - - output->display( `All of the logical expressions are true.` ). - + out->write( `All of the logical expressions are true.` ). ELSE. - output->display( `At least one of the logical expressions is false.` ). + out->write( `At least one of the logical expressions is false.` ). ENDIF. ********************************************************************** - output->next_section( `5) Predicate Expression with IS SUPPLIED` ). + out->write( zcl_demo_abap_aux=>heading( `5) Predicate Expression with IS SUPPLIED` ) ). "The predicate expression IS SUPPLIED is available in method implementations "and checks whether a formal parameter of a procedure is filled or requested. @@ -451,15 +437,16 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. DATA(is_supplied) = check_is_supplied( num1 = 123 ). - output->display( input = is_supplied name = `is_supplied` ). + out->write( data = is_supplied name = `is_supplied` ). + out->write( |\n| ). is_supplied = check_is_supplied( num2 = 456 ). - output->display( input = is_supplied name = `is_supplied` ). + out->write( data = is_supplied name = `is_supplied` ). ********************************************************************** - output->next_section( `6) Control Structure with CASE` ). + out->write( zcl_demo_abap_aux=>heading( `6) Control Structure with CASE` ) ). "CASE statements are used for case distinctions. If the content of an operand "specified after WHEN matches the content specified after CASE, the statement @@ -482,16 +469,16 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. CASE op. WHEN '+'. - output->display( |The result of { n1 } { op } { n2 } is { n1 + n2 }. | ). + out->write( |The result of { n1 } { op } { n2 } is { n1 + n2 }. | ). WHEN '-'. - output->display( |The result of { n1 } { op } { n2 } is { n1 - n2 }. | ). + out->write( |The result of { n1 } { op } { n2 } is { n1 - n2 }. | ). WHEN OTHERS. - output->display( |The operator { op } is not possible.| ). + out->write( |The operator { op } is not possible.| ). ENDCASE. ********************************************************************** - output->next_section( `7) CASE TYPE OF` ). + out->write( zcl_demo_abap_aux=>heading( `7) CASE TYPE OF` ) ). "CASE TYPE OF: Checks the type of object reference variables @@ -501,33 +488,35 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. CASE TYPE OF oref_check. WHEN TYPE zcl_demo_abap_prog_flow_logic. - output->display( `Type zcl_demo_abap_prog_flow_logic? True!` ). + out->write( `Type zcl_demo_abap_prog_flow_logic? True!` ). WHEN TYPE if_oo_adt_classrun. - output->display( `Type if_oo_adt_classrun? True!` ). + out->write( `Type if_oo_adt_classrun? True!` ). WHEN TYPE zcl_demo_abap_sql. - output->display( `Type zcl_demo_abap_sql? True!` ). + out->write( `Type zcl_demo_abap_sql? True!` ). WHEN OTHERS. - output->display( `Other type.` ). + out->write( `Other type.` ). ENDCASE. + out->write( |\n| ). + "The same logic as above is realized in the following IF statements "using IS INSTANCE OF. "In the example, the type check for if_oo_adt_classrun 'comes first'. "This type is also true for the object reference variable. This class "implements the interface. IF oref_check IS INSTANCE OF if_oo_adt_classrun. - output->display( `Type if_oo_adt_classrun? True!` ). + out->write( `Type if_oo_adt_classrun? True!` ). ELSEIF oref_check IS INSTANCE OF zcl_demo_abap_prog_flow_logic. - output->display( `Type zcl_demo_abap_prog_flow_logic? True!` ). + out->write( `Type zcl_demo_abap_prog_flow_logic? True!` ). ELSEIF oref_check IS INSTANCE OF zcl_demo_abap_sql. - output->display( `Type zcl_demo_abap_sql? True!` ). + out->write( `Type zcl_demo_abap_sql? True!` ). ELSE. - output->display( `Other type.` ). + out->write( `Other type.` ). ENDIF. ********************************************************************** - output->next_section( `8) Excursion: SWITCH Operator` ). + out->write( zcl_demo_abap_aux=>heading( `8) Excursion: SWITCH Operator` ) ). "The conditional operator SWITCH can also be used to make case "distinctions in operand positions. Such conditional expressions have @@ -551,13 +540,13 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. WHEN '12' THEN `December` ELSE `Oops ...` ). - output->display( input = switch_res name = `switch_res` ). + out->write( data = switch_res name = `switch_res` ). ********************************************************************** - output->next_section( `Loops (Iterations)` ). + out->write( zcl_demo_abap_aux=>heading( `Loops (Iterations)` ) ). - output->display( `9) Unconditional Loops with DO` ). + out->write( |9) Unconditional Loops with DO\n| ). "The example demonstrate the restriction of loop passes by specifying "a number (of maximum loop passes) and the TIMES addition in a DO loop. @@ -572,12 +561,13 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. do_sy_index = do_sy_index && sy-index && ` `. ENDDO. - output->display( input = do_counter name = `do_counter` ). - output->display( input = do_sy_index name = `do_sy_index` ). + out->write( data = do_counter name = `do_counter` ). + out->write( |\n| ). + out->write( data = do_sy_index name = `do_sy_index` ). ********************************************************************** - output->next_section( `10) Terminating Loops Completely Using EXIT` ). + out->write( zcl_demo_abap_aux=>heading( `10) Terminating Loops Completely Using EXIT` ) ). "Using the EXIT statement, you can terminate a loop completely. "The program flow resumes after the closing statement of the loop. @@ -593,12 +583,13 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. ENDIF. ENDDO. - output->display( input = do_counter name = `do_counter` ). - output->display( input = do_sy_index name = `do_sy_index` ). + out->write( data = do_counter name = `do_counter` ). + out->write( |\n| ). + out->write( data = do_sy_index name = `do_sy_index` ). ********************************************************************** - output->next_section( `11) Terminating Loop Passes` ). + out->write( zcl_demo_abap_aux=>heading( `11) Terminating Loop Passes` ) ). "CONTINUE: The current loop pass is terminated immediately and the " program flow is continued with the next loop pass. @@ -609,7 +600,6 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. CLEAR: do_counter, do_sy_index. DO. - IF sy-index = 2. "skipped CONTINUE. ENDIF. @@ -621,17 +611,16 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. ENDIF. do_counter += 1. - do_sy_index = do_sy_index && sy-index && ` `. - ENDDO. - output->display( input = do_counter name = `do_counter` ). - output->display( input = do_sy_index name = `do_sy_index` ). + out->write( data = do_counter name = `do_counter` ). + out->write( |\n| ). + out->write( data = do_sy_index name = `do_sy_index` ). ********************************************************************** - output->next_section( `12) Excursion: Terminating Procedures Using RETURN` ). + out->write( zcl_demo_abap_aux=>heading( `12) Excursion: Terminating Procedures Using RETURN` ) ). "RETURN statements immediately terminate the current processing block. "However, according to the guidelines, RETURN should only be used to exit @@ -642,17 +631,18 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. DATA(return1) = meth_with_return( 81 ). - output->display( input = return1 name = `return1` ). + out->write( data = return1 name = `return1` ). + out->write( |\n| ). DATA(return2) = meth_with_return( -9 ). - output->display( input = return2 name = `return2` ). + out->write( data = return2 name = `return2` ). ********************************************************************** - output->next_section( `Conditional Loops with WHILE` ). + out->write( zcl_demo_abap_aux=>heading( `Conditional Loops with WHILE` ) ). - output->display( `13) WHILE Example 1` ). + out->write( |13) WHILE Example 1\n| ). "The following example highlights the setting of sy-index within loop passes. "The value is added to an internal table. The loop iteration stops when @@ -661,16 +651,14 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. DATA int_itab TYPE TABLE OF i. WHILE lines( int_itab ) < 10. - int_itab = VALUE #( BASE int_itab ( sy-index ) ). - ENDWHILE. - output->display( input = int_itab name = `int_itab` ). + out->write( data = int_itab name = `int_itab` ). ********************************************************************** - output->display( `14) WHILE Example 2` ). + out->write( zcl_demo_abap_aux=>heading( `14) WHILE Example 2` ) ). "In the following example, all occurrences of a certain substring "should be replaced by another string. Instead of, for example, using @@ -689,7 +677,6 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. DATA(subrc) = 0. "separate dobj to store the sy-subrc value WHILE subrc = 0. - FIND FIRST OCCURRENCE OF `abap` IN while_string MATCH LENGTH DATA(len) MATCH OFFSET DATA(off) @@ -703,24 +690,22 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. subrc = sy-subrc. IF subrc = 0. - count_occ_via_sy_index = sy-index. "to hold the "To hold the total number of findings from left to right of the string count_occ = count_occ + cnt. - REPLACE SECTION OFFSET off LENGTH len OF while_string WITH `ABAP`. - ENDIF. - ENDWHILE. - output->display( input = count_occ_via_sy_index name = `count_occ_via_sy_index` ). - output->display( input = count_occ name = `count_occ` ). - output->display( input = while_string name = `while_string` ). + out->write( data = count_occ_via_sy_index name = `count_occ_via_sy_index` ). + out->write( |\n| ). + out->write( data = count_occ name = `count_occ` ). + out->write( |\n| ). + out->write( data = while_string name = `while_string` ). ********************************************************************** - output->display( `15) WHILE Example 3` ). + out->write( zcl_demo_abap_aux=>heading( `15) WHILE Example 3` ) ). "The example demonstrates the 3 options for loop terminations "in the context of a WHILE ... ENDWHILE statement. @@ -731,7 +716,6 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. DATA(index) = 0. WHILE index <> 10. - index = sy-index. IF sy-index = 2. "Skips loop pass @@ -745,20 +729,19 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. ENDIF. while_cnt += 1. - while_sy_index = while_sy_index && sy-index && ` `. - ENDWHILE. - output->display( input = while_cnt name = `while_cnt` ). - output->display( input = while_sy_index name = `while_sy_index` ). + out->write( data = while_cnt name = `while_cnt` ). + out->write( |\n| ). + out->write( data = while_sy_index name = `while_sy_index` ). ********************************************************************** - output->next_section( `Loops across Tables` ). + out->write( zcl_demo_abap_aux=>heading( `Loops across Tables` ) ). - output->display( `16) Loop across Internal Table Using LOOP ... ENDLOOP` ). + out->write( |16) Loop across Internal Table Using LOOP ... ENDLOOP\n\n| ). "LOOP ... ENDLOOP statements are meant for loops across internal tables. "For more examples, see the cheat sheet example on internal tables. @@ -802,7 +785,6 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. DATA calc_results TYPE TABLE OF calc_results_struc WITH EMPTY KEY. LOOP AT calc_itab ASSIGNING FIELD-SYMBOL(). - "Method call to calculate and return the result DATA(res) = calc( num1 = -num1 operator = -operator @@ -810,16 +792,14 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "Adding the sy-tabix value to the table, too. res-sy_tabix = sy-tabix. - APPEND res TO calc_results. - ENDLOOP. - output->display( input = calc_results name = `calc_results` ). + out->write( data = calc_results name = `calc_results` ). ********************************************************************** - output->display( `17) SELECT Loop` ). + out->write( zcl_demo_abap_aux=>heading( `17) SELECT Loop` ) ). "SELECT ... ENDSELECT statements loop across the result set of a database access. "For more examples, see the cheat sheet example on ABAP SQL. @@ -849,40 +829,29 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. INTO @DATA(wa). IF sy-subrc = 0. - "Loop pass stored and representing the table index value for the "ABAP SQL statement further down. loop_pass += 1. - IF loop_pass <= 3. - wa-calc_result = wa-num * 5. - ELSEIF loop_pass = 6. - "No calculation for this loop pass. Loop is terminated. EXIT. - ELSE. - wa-calc_result = wa-num * 100. - ENDIF. - "Inserting calculation result in table MODIFY itab_select_loop FROM wa INDEX loop_pass TRANSPORTING calc_result. - ENDIF. - ENDSELECT. - output->display( input = itab_select_loop name = `itab_select_loop` ). + out->write( data = itab_select_loop name = `itab_select_loop` ). ********************************************************************** - output->next_section( `Exception Handling` ). + out->write( zcl_demo_abap_aux=>heading( `Exception Handling` ) ). - output->display( `18) TRY Control Structures` ). + out->write( |18) TRY Control Structures\n\n| ). "TRY control structures are meant for handling catchable exceptions locally "The example shows divisions. The predefined exception class cx_sy_zerodivide @@ -893,26 +862,26 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "left due to the previous erroneous 0 division. TRY. - DATA(div1) = 4 / 2. - output->display( input = div1 name = `div1` ). + out->write( data = div1 name = `div1` ). + out->write( |\n| ). DATA(div2) = 4 / 0. - output->display( input = div2 name = `div2` ). + out->write( data = div2 name = `div2` ). + out->write( |\n| ). DATA(div3) = 9 / 3. - output->display( input = div3 name = `div3` ). + out->write( data = div3 name = `div3` ). + out->write( |\n| ). CATCH cx_sy_zerodivide. - - output->display( `0 division. The exception was caught.` ). - + out->write( `0 division. The exception was caught.` ). + out->write( |\n| ). ENDTRY. "The following example shows a catchable exception that is "raised if a line is not found when using table expressions. TRY. - DATA(line) = str_table[ 12345 ]. "The predefined exception class cx_sy_itab_line_not_found @@ -920,14 +889,12 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "If the exception is not handled, the program is terminated "and the runtime error ITAB_LINE_NOT_FOUND occurs. CATCH cx_sy_itab_line_not_found. - - output->display( `The line was not found. The exception was caught.` ). - + out->write( `The line was not found. The exception was caught.` ). ENDTRY. ********************************************************************** - output->next_section( `19) Multiple CATCH Blocks` ). + out->write( zcl_demo_abap_aux=>heading( `19) Multiple CATCH Blocks` ) ). "It is possible to specify multiple exception classes in a list and "multiple CATCH blocks. @@ -942,35 +909,29 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. int_itab = VALUE #( ( 5 ) ( 0 ) ( 987654321 ) ). LOOP AT int_itab ASSIGNING FIELD-SYMBOL(). - TRY. - - output->display( |--- Calculations with { } ---| ). + out->write( |--- Calculations with { } ---| ). DATA(calc1) = CONV decfloat34( 1 / ). - output->display( input = calc1 name = `calc1` ). + out->write( data = calc1 name = `calc1` ). + out->write( |\n| ). DATA(calc2) = ipow( base = exp = 2 ). - output->display( input = calc2 name = `calc2` ). - - + out->write( data = calc2 name = `calc2` ). + out->write( |\n| ). CATCH cx_sy_arithmetic_overflow lcx_calc_error. - - output->display( `Arithmetic overflow. The exception was caught.` ). - + out->write( `Arithmetic overflow. The exception was caught.` ). CATCH cx_sy_zerodivide lcx_some_error. - - output->display( `0 division. The exception was caught.` ). - + out->write( `0 division. The exception was caught.` ). ENDTRY. - + out->write( |\n| ). ENDLOOP. ********************************************************************** - output->next_section( `20) Using an Exception Class Higher Up in the Inheritance Tree` ). + out->write( zcl_demo_abap_aux=>heading( `20) Using an Exception Class Higher Up in the Inheritance Tree` ) ). "In the following CATCH block, the predefined exception class cx_sy_arithmetic_error "is specified. Both cx_sy_zerodivide and cx_sy_arithmetic_overflow are derived from @@ -980,31 +941,27 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "class is specified. LOOP AT int_itab ASSIGNING FIELD-SYMBOL(). - TRY. - - output->display( |--- Calculations with { } ---| ). + out->write( |--- Calculations with { } ---| ). calc1 = 1 / . - output->display( input = calc1 name = `calc1` ). + out->write( data = calc1 name = `calc1` ). + out->write( |\n| ). calc2 = ipow( base = exp = 2 ). - output->display( input = calc2 name = `calc2` ). - - + out->write( data = calc2 name = `calc2` ). + out->write( |\n| ). CATCH cx_sy_arithmetic_error. - - output->display( `Arithmetic error. The exception was caught.` ). - + out->write( `Arithmetic error. The exception was caught.` ). ENDTRY. - + out->write( |\n| ). ENDLOOP. ********************************************************************** - output->next_section( `21) Storing a Reference to the Exception Object` ). + out->write( zcl_demo_abap_aux=>heading( `21) Storing a Reference to the Exception Object` ) ). "You can use the addition INTO plus an object reference variable to store "a reference to an exception object. It is, for example, relevant to @@ -1017,18 +974,17 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. LOOP AT int_itab ASSIGNING FIELD-SYMBOL(). TRY. - - output->display( |--- Calculations with { } ---| ). + out->write( |--- Calculations with { } ---| ). calc1 = 1 / . - output->display( input = calc1 name = `calc1` ). + out->write( data = calc1 name = `calc1` ). + out->write( |\n| ). calc2 = ipow( base = exp = 2 ). - output->display( input = calc2 name = `calc2` ). - - + out->write( data = calc2 name = `calc2` ). + out->write( |\n| ). CATCH cx_sy_arithmetic_error INTO exception. "Note: "- The object reference variable is of type cx_root. @@ -1037,15 +993,14 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "Retrieving and displaying exception text exception_text = exception->get_text( ). - output->display( input = exception_text name = `exception_text` ). - + out->write( data = exception_text name = `exception_text` ). ENDTRY. - + out->write( |\n| ). ENDLOOP. ********************************************************************** - output->next_section( `22) Raising Exceptions Programmatically` ). + out->write( zcl_demo_abap_aux=>heading( `22) Raising Exceptions Programmatically` ) ). "The following examples demonstrate the ABAP statement RAISE EXCEPTION "using the addition TYPE. Note there are more additions available that @@ -1055,7 +1010,8 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "here. DATA(division) = 0 / 0. - output->display( input = division name = `division` ). + out->write( data = division name = `division` ). + out->write( |\n| ). "In this example, the appropriate exception - the predefined exception "class cx_sy_zerodivide - is raised. @@ -1066,11 +1022,9 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. RAISE EXCEPTION TYPE cx_sy_zerodivide. CATCH cx_sy_zerodivide INTO DATA(error_oref). - exception_text = error_oref->get_text( ). - - output->display( input = exception_text name = `exception_text` ). - + out->write( data = exception_text name = `exception_text` ). + out->write( |\n| ). ENDTRY. "The following example just demonstrates a locally defined @@ -1079,34 +1033,31 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "the tab 'Class-relevant Local Types'. TRY. RAISE EXCEPTION TYPE lcx_some_error. - CATCH lcx_some_error INTO exception. - exception_text = exception->get_text( ). - output->display( `Default exception text for a local exception class:` ). - output->display( input = exception_text name = `exception_text` ). - + out->write( `Default exception text for a local exception class:` ). + out->write( data = exception_text name = `exception_text` ). ENDTRY. ********************************************************************** - output->next_section( `23) Nested TRY Control Structure` ). + out->write( zcl_demo_abap_aux=>heading( `23) Nested TRY Control Structure` ) ). TRY. TRY. RAISE EXCEPTION TYPE lcx_some_error. CATCH lcx_some_error INTO DATA(error_inner_catch). - output->display( `Inner CATCH` ). + out->write( `Inner CATCH` ). RAISE EXCEPTION error_inner_catch. ENDTRY. CATCH lcx_some_error. - output->display( `Outer CATCH` ). + out->write( `Outer CATCH` ). ENDTRY. ********************************************************************** - output->next_section( `24) Raising an Exception in the Context of Conditional Expressions` ). + out->write( zcl_demo_abap_aux=>heading( `24) Raising an Exception in the Context of Conditional Expressions` ) ). "In this example, the optional addition THROW is used in a conditional "expression. A self-defined local exception class is used. @@ -1118,19 +1069,15 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. WHEN number = 2 THEN `two` ELSE THROW lcx_some_error( ) ). - output->display( input = cond_raise name = `cond_raise` ). - + out->write( data = cond_raise name = `cond_raise` ). CATCH lcx_some_error INTO exception. - exception_text = exception->get_text( ). - - output->display( input = exception_text name = `exception_text` ). - + out->write( data = exception_text name = `exception_text` ). ENDTRY. ********************************************************************** - output->next_section( `25) RAISING Parameter in Method Delcarations` ). + out->write( zcl_demo_abap_aux=>heading( `25) RAISING Parameter in Method Delcarations` ) ). "In the following example, a string table is looped across. The table "includes valid and invalid email addresses. The validity is checked @@ -1156,29 +1103,24 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. DATA itab_email_check TYPE TABLE OF struc_email_check WITH EMPTY KEY. LOOP AT str_table ASSIGNING FIELD-SYMBOL(). - TRY. DATA(email_valid) = validate_email( email = ). DATA(exc_raised) = abap_false. - CATCH lcx_invalid_email. - email_valid = abap_false. exc_raised = abap_true. - ENDTRY. APPEND VALUE #( email = is_email_valid = email_valid exception_raised = exc_raised ) TO itab_email_check. - ENDLOOP. - output->display( input = itab_email_check name = `itab_email_check` ). + out->write( data = itab_email_check name = `itab_email_check` ). ********************************************************************** - output->next_section( `Exception Classes Derived from CX_STATIC_CHECK` ). + out->write( zcl_demo_abap_aux=>heading( `26) Exception Classes Derived from CX_STATIC_CHECK` ) ). "Exception Classes of type cx_static_check force users to handle exceptions. "Exceptions that are declared in the method signature make users aware of which @@ -1194,26 +1136,22 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "Method call with a proper exception handling TRY. - DATA(my_user_b) = whats_my_user( get_name = abap_true ). - output->display( input = my_user_b name = `my_user_b` ). + out->write( data = my_user_b name = `my_user_b` ). + out->write( |\n| ). DATA(my_user_c) = whats_my_user( get_name = abap_false ). - output->display( input = my_user_c name = `my_user_c` ). - + out->write( data = my_user_c name = `my_user_c` ). CATCH lcx_static_exc_class INTO exception. - exception_text = exception->get_text( ). - - output->display( input = exception_text name = `exception_texts` ). - + out->write( data = exception_text name = `exception_texts` ). ENDTRY. ********************************************************************** - output->next_section( `Exception Classes Derived from CX_DYNAMIC_CHECK` ). + out->write( zcl_demo_abap_aux=>heading( `27) Exception Classes Derived from CX_DYNAMIC_CHECK` ) ). "Exception Classes derived from cx_dynamic_check are for exceptions that "can be checked and avoided by preconditions. @@ -1237,21 +1175,20 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "there would not be a syntax warning. Actually, you could "prevent a calculation failure by setting appropriate values. TRY. - DATA(res1) = power2_and_sqrt( num = 4 ). - output->display( input = res1 name = `res1` ). + out->write( data = res1 name = `res1` ). + out->write( |\n| ). DATA(res2) = power2_and_sqrt( num = 123456789 ). - output->display( input = res2 name = `res2` ). + out->write( data = res2 name = `res2` ). + out->write( |\n| ). CATCH cx_sy_arithmetic_overflow INTO exception. - exception_text = exception->get_text( ). - - output->display( input = exception_text name = `exception_text` ). - + out->write( data = exception_text name = `exception_text` ). + out->write( |\n| ). ENDTRY. "This TRY control structure demonstrates the following: @@ -1260,47 +1197,47 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "exception is raised - a new exception of type cx_sy_no_handler is raised. In this "case, the attribute 'previous' contains a reference to the original exception. TRY. - DATA(res3) = power2_and_sqrt( num = 16 ). - output->display( input = res3 name = `res3` ). + out->write( data = res3 name = `res3` ). + out->write( |\n| ). DATA(res4) = power2_and_sqrt( num = -1 ). - output->display( input = res4 name = `res4` ). + out->write( data = res4 name = `res4` ). + out->write( |\n| ). - "The specification of the suitable exception class does not help here. - "The error is raised while processing the method. + "The specification of the suitable exception class does not help here. + "The error is raised while processing the method. CATCH cx_sy_arg_out_of_domain INTO exception. - exception_text = exception->get_text( ). - output->display( input = exception_text name = `exception_text` ). - + out->write( data = exception_text name = `exception_text` ). + out->write( |\n| ). CATCH cx_sy_no_handler INTO exception. - exception_text = exception->get_text( ). - output->display( input = exception_text name = `exception_text` ). + out->write( data = exception_text name = `exception_text` ). + out->write( |\n| ). "Attribute 'previous' "In this case, the information of the actual runtime error is provided: "Here, it is COMPUTE_SQRT_DOMAIN. - output->display( input = exception->previous name = `exception->previous` ). + out->write( data = exception->previous name = `exception->previous` ). + out->write( |\n| ). "For demo purposes, RTTI is used here to retrieve the relative name of the type, "i. e. the exception class that was raised. DATA(relative_name) = cl_abap_typedescr=>describe_by_object_ref( exception->previous )->get_relative_name( ). - output->display( input = relative_name name = `relative_name` ). - + out->write( data = relative_name name = `relative_name` ). ENDTRY. ********************************************************************** "Excursion: Runtime Errors and Terminating Programs - output->next_section( `Excursion: Runtime Errors and Terminating Programs` ). + out->write( zcl_demo_abap_aux=>heading( `28) Excursion: Runtime Errors and Terminating Programs` ) ). "ASSERT statements are followed by a logical expression. If the expression is false, "the program is terminated and an uncatchable exception is raised resulting in the @@ -1331,13 +1268,10 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. "DATA(is_email_valid) = validate_email( email = `john.doe@email.c##` ). - output->display( `This text is displayed if you left all statements causing a runtime error commented out :)` ). - + out->write( `This text is displayed if you left all statements causing a runtime error commented out :)` ). ENDMETHOD. - METHOD meth_with_return. - IF num >= 0. DATA(sqr_res) = sqrt( num ). ELSE. @@ -1345,19 +1279,14 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. ENDIF. res = `The method call was not terminated. The square root of ` && num && ` is ` && sqr_res. - ENDMETHOD. - METHOD power2_and_sqrt. - - result = |Calculation result:\n{ num } powered by 2 = { ipow( base = num exp = 2 ) }\nSquare root of { num } = { sqrt( num ) }|. - + result = |{ num } powered by 2 = { ipow( base = num exp = 2 ) } / Square root of { num } = { sqrt( num ) }|. ENDMETHOD. METHOD prep_calc_result. - FIND PCRE `-$` IN res. "trailing minus IF sy-subrc = 0. @@ -1374,30 +1303,23 @@ CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION. REPLACE `.0` IN res WITH ``. ENDIF. ENDIF. - ENDMETHOD. METHOD validate_email. - IF matches( val = email pcre = `\w+(\.\w+)*@(\w+\.)+(\w{2,4})` ). is_valid_email = abap_true. ELSE. RAISE EXCEPTION TYPE lcx_invalid_email. - ENDIF. - ENDMETHOD. - METHOD whats_my_user. - IF get_name = abap_true. name = sy-uname. ELSE. RAISE EXCEPTION TYPE lcx_static_exc_class. ENDIF. - ENDMETHOD. ENDCLASS. diff --git a/src/zcl_demo_abap_rap_draft_ln_m.clas.abap b/src/zcl_demo_abap_rap_draft_ln_m.clas.abap index aad288e..a086a4a 100644 --- a/src/zcl_demo_abap_rap_draft_ln_m.clas.abap +++ b/src/zcl_demo_abap_rap_draft_ln_m.clas.abap @@ -72,8 +72,8 @@ * The calculation ID which represents the key of the instance has an * initial value. Only when you save the instance to the database, the * final key is set. -* The effect of side effects can be explored as follows: Make an entry -* in an input field, click another input field (e.g. to make a new entry +* The effect of side effects can be explored as follows: Make an entry +* in an input field, click another input field (e.g. to make a new entry * there), and check how the value for the result changes. * * ----------------------------- NOTE ----------------------------------- @@ -146,12 +146,9 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. METHOD if_oo_adt_classrun~main. - DATA(output) = NEW zcl_demo_abap_display( out ). - - output->display( `ABAP Cheat Sheet Example: RAP Calculator Using Managed, ` && - `Draft-Enabled RAP BO (Late Numbering)` ). - output->display( `1) Creating Instances and ` && - `Saving to the database` ). + out->write( `ABAP Cheat Sheet Example: RAP Calculator Using Managed, ` && + |Draft-Enabled RAP BO (Late Numbering)\n\n| ). + out->write( |1) Creating Instances and Saving to the database\n| ). "Creating instances; draft indicator %is_draft is enabled MODIFY ENTITY zdemo_abap_rap_draft_m @@ -175,26 +172,29 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. "Displaying responses only if FAILED and REPORTED "response parameters are not initial IF f IS NOT INITIAL OR r IS NOT INITIAL. - output->display( `Responses after MODIFY operation` ). + out->write( `Responses after MODIFY operation` ). + out->write( |\n| ). IF m IS NOT INITIAL. - output->display( input = m name = `m` ). + out->write( data = m name = `m` ). + out->write( |\n| ). ENDIF. IF f IS NOT INITIAL. - output->display( input = f name = `f` ).. + out->write( data = f name = `f` ). + out->write( |\n| ). ENDIF. IF r IS NOT INITIAL. - output->display( input = r name = `r` ). + out->write( data = r name = `r` ). + out->write( |\n| ). ENDIF. - ENDIF. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving draft table entries @@ -229,7 +229,7 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving draft table entries @@ -248,29 +248,28 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. INTO TABLE @DATA(db_tab_root_after_act). "Displaying entries - output->display( `1a) Draft and database tables before ` && - `ACTIVATE action` ). - output->display( `Draft table before activation` ). - output->display( input = draft_parent_before_act name = `draft_parent_before_act` ). - - - output->display( `Database table before activation` ). - output->display( input = db_tab_root_before_act name = `db_tab_root_before_act` ). - - - output->next_section( `1b) Draft and database tables after ` && - `ACTIVATE action` ). - output->display( `Draft table after activation` ). - output->display( input = draft_parent_afer_act name = `draft_parent_afer_act` ). - - - output->display( `Database table after activation` ). - output->display( input = db_tab_root_after_act name = `db_tab_root_after_act` ). + out->write( |1a) Draft and database tables before ACTIVATE action\n| ). + out->write( `Draft table before activation` ). + out->write( |\n| ). + out->write( data = draft_parent_before_act name = `draft_parent_before_act` ). + out->write( |\n| ). + out->write( `Database table before activation` ). + out->write( |\n| ). + out->write( data = db_tab_root_before_act name = `db_tab_root_before_act` ). + out->write( zcl_demo_abap_aux=>heading( `1b) Draft and database tables after ` && + `ACTIVATE action` ) ). + out->write( `Draft table after activation` ). + out->write( |\n| ). + out->write( data = draft_parent_afer_act name = `draft_parent_afer_act` ). + out->write( |\n| ). + out->write( `Database table after activation` ). + out->write( |\n| ). + out->write( data = db_tab_root_after_act name = `db_tab_root_after_act` ). ********************************************************************** - output->next_section( `2) Creating Invalid Instances` ). + out->write( zcl_demo_abap_aux=>heading( `2) Creating Invalid Instances` ) ). "Purposely creating invalid instances; "draft indicator %is_draft is enabled @@ -291,18 +290,22 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. "Displaying responses only if FAILED and REPORTED "response parameters are not initial. IF f IS NOT INITIAL OR r IS NOT INITIAL. - output->display( input = `Responses after MODIFY operation` ). + out->write( data = `Responses after MODIFY operation` ). + out->write( |\n| ). IF m IS NOT INITIAL. - output->display( input = m name = `m` ). + out->write( data = m name = `m` ). + out->write( |\n| ). ENDIF. IF f IS NOT INITIAL. - output->display( input = f name = `f` ).. + out->write( data = f name = `f` ). + out->write( |\n| ). ENDIF. IF r IS NOT INITIAL. - output->display( input = r name = `r` ). + out->write( data = r name = `r` ). + out->write( |\n| ). ENDIF. ENDIF. @@ -310,7 +313,7 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving draft table entries @@ -328,7 +331,6 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. ORDER BY id INTO TABLE @db_tab_root_before_act. - "Filling the derived type for the ACTIVATE method by "getting %pid values; here, another table is filled for later use LOOP AT m-calc @@ -350,18 +352,22 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. "Displaying responses only if FAILED and REPORTED "response parameters are not initial. IF f IS NOT INITIAL OR r IS NOT INITIAL. - output->display( input = `Responses after MODIFY operation` ). + out->write( data = `Responses after MODIFY operation` ). + out->write( |\n| ). IF m IS NOT INITIAL. - output->display( input = m name = `m` ). + out->write( data = m name = `m` ). + out->write( |\n| ). ENDIF. IF f IS NOT INITIAL. - output->display( input = f name = `f` ).. + out->write( data = f name = `f` ). + out->write( |\n| ). ENDIF. IF r IS NOT INITIAL. - output->display( input = r name = `r` ). + out->write( data = r name = `r` ). + out->write( |\n| ). ENDIF. ENDIF. @@ -369,7 +375,7 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving draft table entries @@ -388,29 +394,29 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. INTO TABLE @db_tab_root_after_act. "Displaying entries - output->next_section( `2a) Draft and database tables before ` && - `ACTIVATE action` ). - output->display( `Draft table before activation` ). - output->display( input = draft_parent_before_act name = `draft_parent_before_act` ). - - - output->display( `Database table before activation` ). - output->display( input = db_tab_root_before_act name = `db_tab_root_before_act` ). - - - output->next_section( `2b) Draft and database tables after ` && - `ACTIVATE action` ). - output->display( `Draft table after activation` ). - output->display( input = draft_parent_afer_act name = `draft_parent_afer_act` ). - - - output->display( `Database table after activation` ). - output->display( input = db_tab_root_after_act name = `db_tab_root_after_act` ). + out->write( zcl_demo_abap_aux=>heading( `2a) Draft and database tables before ` && + `ACTIVATE action` ) ). + out->write( `Draft table before activation` ). + out->write( |\n| ). + out->write( data = draft_parent_before_act name = `draft_parent_before_act` ). + out->write( |\n| ). + out->write( `Database table before activation` ). + out->write( |\n| ). + out->write( data = db_tab_root_before_act name = `db_tab_root_before_act` ). + out->write( zcl_demo_abap_aux=>heading( `2b) Draft and database tables after ` && + `ACTIVATE action` ) ). + out->write( `Draft table after activation` ). + out->write( |\n| ). + out->write( data = draft_parent_afer_act name = `draft_parent_afer_act` ). + out->write( |\n| ). + out->write( `Database table after activation` ). + out->write( |\n| ). + out->write( data = db_tab_root_after_act name = `db_tab_root_after_act` ). ********************************************************************** - output->next_section( `3) Correcting and Updating Invalid Instances` ). + out->write( zcl_demo_abap_aux=>heading( `3) Correcting and Updating Invalid Instances` ) ). "Preparing the derived type for the read operation to "retrieve the field values; the draft indicator is enabled @@ -458,7 +464,7 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. MODIFY ENTITY zdemo_abap_rap_draft_m @@ -470,7 +476,7 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving draft table entries @@ -489,20 +495,18 @@ CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION. INTO TABLE @db_tab_root_after_act. "Displaying entries - output->display( input = `Draft and database tables after ` && + out->write( data = `Draft and database tables after ` && `ACTIVATE action` ). - - output->display( `Draft table after activation` ). - output->display( input = draft_parent_afer_act name = `draft_parent_afer_act` ). - - - output->display( `Database table after activation` ). - output->display( input = db_tab_root_after_act name = `db_tab_root_after_act` ). - - + out->write( |\n| ). + out->write( `Draft table after activation` ). + out->write( |\n| ). + out->write( data = draft_parent_afer_act name = `draft_parent_afer_act` ). + out->write( |\n| ). + out->write( `Database table after activation` ). + out->write( |\n| ). + out->write( data = db_tab_root_after_act name = `db_tab_root_after_act` ). ENDMETHOD. - METHOD initialize_dbtabs. DELETE FROM zdemo_abap_tabca. DELETE FROM zdemo_abap_draft. diff --git a/src/zcl_demo_abap_rap_ext_num_m.clas.abap b/src/zcl_demo_abap_rap_ext_num_m.clas.abap index 70b7835..b117980 100644 --- a/src/zcl_demo_abap_rap_ext_num_m.clas.abap +++ b/src/zcl_demo_abap_rap_ext_num_m.clas.abap @@ -70,12 +70,13 @@ CLASS zcl_demo_abap_rap_ext_num_m DEFINITION CLASS-METHODS: class_constructor. -protected section. + PROTECTED SECTION. PRIVATE SECTION. CLASS-DATA: failed TYPE RESPONSE FOR FAILED zdemo_abap_rap_ro_m, reported TYPE RESPONSE FOR REPORTED zdemo_abap_rap_ro_m, - mapped TYPE RESPONSE FOR MAPPED zdemo_abap_rap_ro_m. + mapped TYPE RESPONSE FOR MAPPED zdemo_abap_rap_ro_m, + op TYPE string. CLASS-METHODS: initialize_dbtabs, "If there are entries in the response parameters following EML @@ -88,7 +89,7 @@ ENDCLASS. -CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. +CLASS zcl_demo_abap_rap_ext_num_m IMPLEMENTATION. METHOD class_constructor. @@ -100,9 +101,6 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. CLEAR errors. LOOP AT failed-root ASSIGNING FIELD-SYMBOL(). - - DATA op TYPE string. - CASE if_abap_behv=>mk-on. WHEN -%op-%create. op = `create operation`. @@ -123,7 +121,6 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. ELSE `key = ` && -key_field ) && `: Fail cause ` && -%fail-cause && ` for ` && op && `.` TO errors. - ENDLOOP. IF failed-child IS NOT INITIAL. @@ -134,7 +131,6 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. && -%fail-cause && `.` TO errors. ENDLOOP. ENDIF. - ENDMETHOD. @@ -169,23 +165,18 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. METHOD fill_db_tab. - MODIFY zdemo_abap_rapt1 FROM TABLE @( VALUE #( ( key_field = 4 field1 = 'ggg' field2 = 'hhh' field3 = 40 field4 = 41 ) ) ). - ENDMETHOD. METHOD if_oo_adt_classrun~main. - DATA(output) = NEW zcl_demo_abap_display( out ). - - output->display( `ABAP Cheat Sheet Example: RAP BO Operations Using a Managed ` && - `RAP BO` ). + out->write( |ABAP Cheat Sheet Example: RAP BO Operations Using a Managed RAP BO\n\n| ). ********************************************************************** * @@ -193,7 +184,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. * ********************************************************************** - output->display( `1) Create operation` ). + out->write( |1) Create operation\n\n| ). "Adding an entry to the database table to provoke an error for the "EML create request. @@ -247,7 +238,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -256,26 +247,30 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. ORDER BY key_field INTO TABLE @DATA(tab_root). - output->display( input = tab_root name = `tab_root` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). "Displaying response information IF mapped-root IS NOT INITIAL. - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root entity)` ). - - output->display( input = mapped-root name = `mapped-root` ). + out->write( |\n| ). + out->write( data = mapped-root name = `mapped-root` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -284,7 +279,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. * ********************************************************************** - output->next_section( `2) Update operation` ). + out->write( zcl_demo_abap_aux=>heading( `2) Update operation` ) ). ********************************************************************** * Notes: @@ -340,7 +335,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -349,26 +344,30 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. ORDER BY key_field INTO TABLE @tab_root. - output->display( input = tab_root name = `tab_root` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). "Displaying response information IF mapped-root IS NOT INITIAL. - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root entity)` ). - - output->display( input = mapped-root name = `mapped-root` ). + out->write( |\n| ). + out->write( data = mapped-root name = `mapped-root` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -377,7 +376,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. * ********************************************************************** - output->next_section( `3) Delete operation` ). + out->write( zcl_demo_abap_aux=>heading( `3) Delete operation` ) ). ********************************************************************** * Notes: @@ -413,7 +412,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -422,26 +421,30 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. ORDER BY key_field INTO TABLE @tab_root. - output->display( input = tab_root name = `tab_root` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). "Displaying response information IF mapped-root IS NOT INITIAL. - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root entity)` ). - - output->display( input = mapped-root name = `mapped-root` ). + out->write( |\n| ). + out->write( data = mapped-root name = `mapped-root` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -450,7 +453,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. * ********************************************************************** - output->next_section( `4) Action execution: mutliply_by_2` ). + out->write( zcl_demo_abap_aux=>heading( `4) Action execution: mutliply_by_2` ) ). ********************************************************************** * Notes: @@ -487,7 +490,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -496,26 +499,30 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. ORDER BY key_field INTO TABLE @tab_root. - output->display( input = tab_root name = `tab_root` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). "Displaying response information IF mapped-root IS NOT INITIAL. - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root entity)` ). - - output->display( input = mapped-root name = `mapped-root` ). + out->write( |\n| ). + out->write( data = mapped-root name = `mapped-root` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -524,7 +531,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. * ********************************************************************** - output->next_section( `5) Create-by-association operation (from parent to child)` ). + out->write( zcl_demo_abap_aux=>heading( `5) Create-by-association operation (from parent to child)` ) ). ********************************************************************** * Notes: @@ -593,7 +600,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -607,27 +614,32 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. ORDER BY key_field, key_ch INTO TABLE @DATA(tab_child). - output->display( input = tab_root name = `tab_root` ). - output->display( input = tab_child name = `tab_child` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). + out->write( data = tab_child name = `tab_child` ). + out->write( |\n| ). "Displaying response information IF mapped IS NOT INITIAL. - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root and child entity)` ). - - output->display( input = mapped name = `mapped` ). + out->write( |\n| ). + out->write( data = mapped name = `mapped` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -636,7 +648,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. * ********************************************************************** - output->next_section( `6) Validation val` ). + out->write( zcl_demo_abap_aux=>heading( `6) Validation val` ) ). ********************************************************************** * Notes: @@ -684,7 +696,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. REPORTED DATA(reported_late). IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -693,26 +705,30 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. ORDER BY key_field INTO TABLE @tab_root. - output->display( input = tab_root name = `tab_root` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). "Displaying response information IF mapped IS NOT INITIAL. - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root and child entity)` ). - - output->display( input = mapped name = `mapped` ). + out->write( |\n| ). + out->write( data = mapped name = `mapped` ). + out->write( |\n| ). ENDIF. IF failed_late IS NOT INITIAL. - output->display( `Entries in FAILED LATE response parameter` ). - - output->display( input = failed_late name = `failed_late` ). + out->write( `Entries in FAILED LATE response parameter` ). + out->write( |\n| ). + out->write( data = failed_late name = `failed_late` ). + out->write( |\n| ). ENDIF. IF reported_late IS NOT INITIAL. - output->display( `Entries in REPORTED LATE response parameter` ). - - output->display( input = reported_late name = `reported_late` ). + out->write( `Entries in REPORTED LATE response parameter` ). + out->write( |\n| ). + out->write( data = reported_late name = `reported_late` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -721,7 +737,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. * ********************************************************************** - output->next_section( `7) Read operation (root entity)` ). + out->write( zcl_demo_abap_aux=>heading( `7) Read operation (root entity)` ) ). ********************************************************************** * Notes: @@ -747,18 +763,21 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. REPORTED reported. "Displaying the read result - output->display( input = result name = `result` ). + out->write( data = result name = `result` ). + out->write( |\n| ). "Displaying response information IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************* @@ -767,7 +786,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. * ********************************************************************** - output->next_section( `8) Read operation (child entity)` ). + out->write( zcl_demo_abap_aux=>heading( `8) Read operation (child entity)` ) ). ********************************************************************** * Notes: @@ -790,19 +809,22 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. REPORTED reported. "Displaying read result - output->display( input = read_ch name = `read_ch` ). + out->write( data = read_ch name = `read_ch` ). + out->write( |\n| ). "Displaying response information IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -811,7 +833,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. * ********************************************************************** - output->next_section( `9) Read-by-association operation (from parent to child)` ). + out->write( zcl_demo_abap_aux=>heading( `9) Read-by-association operation (from parent to child)` ) ). ********************************************************************** * Notes: @@ -835,19 +857,23 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. REPORTED reported. "Displaying read result and association links - output->display( input = rba_result name = `rba_result` ). - output->display( input = association_links name = `association_links` ). + out->write( data = rba_result name = `rba_result` ). + out->write( |\n| ). + out->write( data = association_links name = `association_links` ). + out->write( |\n| ). "Displaying response information IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -856,7 +882,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. * ********************************************************************** - output->next_section( `10) Read-by-association operation (from child to parent)` ). + out->write( zcl_demo_abap_aux=>heading( `10) Read-by-association operation (from child to parent)` ) ). ********************************************************************** * Notes: @@ -881,19 +907,23 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. REPORTED reported. "Displaying read result and association links - output->display( input = rba_parent name = `rba_parent` ). - output->display( input = association_links_parent name = `association_links_parent` ). + out->write( data = rba_parent name = `rba_parent` ). + out->write( |\n| ). + out->write( data = association_links_parent name = `association_links_parent` ). + out->write( |\n| ). "Displaying response information IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -903,8 +933,8 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. * ********************************************************************** - output->next_section( `11) Excursion: Read and read-by-association ` && - `operations using dynamic EML` ). + out->write( zcl_demo_abap_aux=>heading( `11) Excursion: Read and read-by-association ` && + `operations using dynamic EML` ) ). DATA: op_tab TYPE abp_behv_retrievals_tab, read_dyn TYPE TABLE FOR READ IMPORT zdemo_abap_rap_ro_m, @@ -956,16 +986,19 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION. READ ENTITIES OPERATIONS op_tab. - output->display( `Read result (root)` ). - output->display( input = read_dyn_result name = `read_dyn_result` ). - output->display( `Read result (read-by-association)` ). - output->display( input = rba_dyn_result name = `rba_dyn_result` ). - output->display( `Links` ). - output->display( input = rba_dyn_link name = `rba_dyn_link` ). - + out->write( `Read result (root)` ). + out->write( |\n| ). + out->write( data = read_dyn_result name = `read_dyn_result` ). + out->write( |\n| ). + out->write( `Read result (read-by-association)` ). + out->write( |\n| ). + out->write( data = rba_dyn_result name = `rba_dyn_result` ). + out->write( |\n| ). + out->write( `Links` ). + out->write( |\n| ). + out->write( data = rba_dyn_link name = `rba_dyn_link` ). ENDMETHOD. - METHOD initialize_dbtabs. DELETE FROM zdemo_abap_rapt1. DELETE FROM zdemo_abap_rapt2. diff --git a/src/zcl_demo_abap_rap_ext_num_u.clas.abap b/src/zcl_demo_abap_rap_ext_num_u.clas.abap index c277626..c2048d8 100644 --- a/src/zcl_demo_abap_rap_ext_num_u.clas.abap +++ b/src/zcl_demo_abap_rap_ext_num_u.clas.abap @@ -79,7 +79,8 @@ protected section. CLASS-DATA: failed TYPE RESPONSE FOR FAILED zdemo_abap_rap_ro_u, reported TYPE RESPONSE FOR REPORTED zdemo_abap_rap_ro_u, - mapped TYPE RESPONSE FOR MAPPED zdemo_abap_rap_ro_u. + mapped TYPE RESPONSE FOR MAPPED zdemo_abap_rap_ro_u, + op TYPE string. CLASS-METHODS: initialize_dbtabs, "If there are entries in the response parameters following EML @@ -104,9 +105,6 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. CLEAR errors. LOOP AT failed-root ASSIGNING FIELD-SYMBOL(). - - DATA op TYPE string. - CASE if_abap_behv=>mk-on. WHEN -%op-%create. op = `create operation`. @@ -131,7 +129,6 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. ELSE `key = ` && -key_field ) && `: Fail cause ` && -%fail-cause && ` for ` && op && `.` TO errors. - ENDLOOP. IF failed-child IS NOT INITIAL. @@ -147,7 +144,6 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. ENDLOOP. ENDIF. - ENDMETHOD. @@ -195,10 +191,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. METHOD if_oo_adt_classrun~main. - DATA(output) = NEW zcl_demo_abap_display( out ). - - output->display( `ABAP Cheat Sheet Example: RAP BO Operations Using an ` && - `Unmanaged RAP BO (External Numbering)` ). + out->write( |ABAP Cheat Sheet Example: RAP BO Operations Using an Unmanaged RAP BO (External Numbering)\n\n| ). ********************************************************************** * @@ -206,7 +199,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * ********************************************************************** - output->display( `1) Create Operation` ). + out->write( |1) Create Operation\n\n| ). "Adding an entry to the database table to provoke an error for the "EML create request. @@ -257,7 +250,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -266,26 +259,30 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. ORDER BY key_field INTO TABLE @DATA(tab_root). - output->display( input = tab_root name = `tab_root` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). "Displaying response information IF mapped-root IS NOT INITIAL. - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root entity)` ). - - output->display( input = mapped-root name = `mapped-root` ). + out->write( |\n| ). + out->write( data = mapped-root name = `mapped-root` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -294,7 +291,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * ********************************************************************** - output->next_section( `2) Update Operation` ). + out->write( zcl_demo_abap_aux=>heading( `2) Update Operation` ) ). ********************************************************************** * Notes: @@ -350,7 +347,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -359,26 +356,30 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. ORDER BY key_field INTO TABLE @tab_root. - output->display( input = tab_root name = `tab_root` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). "Displaying response information IF mapped-root IS NOT INITIAL. - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root entity)` ). - - output->display( input = mapped-root name = `mapped-root` ). + out->write( |\n| ). + out->write( data = mapped-root name = `mapped-root` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -387,7 +388,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * ********************************************************************** - output->next_section( `3) Delete Operation` ). + out->write( zcl_demo_abap_aux=>heading( `3) Delete Operation` ) ). ********************************************************************** * Notes: @@ -428,7 +429,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -437,26 +438,30 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. ORDER BY key_field INTO TABLE @tab_root. - output->display( input = tab_root name = `tab_root` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). "Displaying response information IF mapped-root IS NOT INITIAL. - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root entity)` ). - - output->display( input = mapped-root name = `mapped-root` ). + out->write( |\n| ). + out->write( data = mapped-root name = `mapped-root` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -465,7 +470,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * ********************************************************************** - output->next_section( `4) Executing Action mutliply_by_2` ). + out->write( zcl_demo_abap_aux=>heading( `4) Executing Action mutliply_by_2` ) ). ********************************************************************** * Notes: @@ -502,7 +507,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -511,26 +516,30 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. ORDER BY key_field INTO TABLE @tab_root. - output->display( input = tab_root name = `tab_root` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). "Displaying response information IF mapped-root IS NOT INITIAL. - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root entity)` ). - - output->display( input = mapped-root name = `mapped-root` ). + out->write( |\n| ). + out->write( data = mapped-root name = `mapped-root` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -539,7 +548,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * ********************************************************************** - output->next_section( `5) Executing Action mutliply_by_3` ). + out->write( zcl_demo_abap_aux=>heading( `5) Executing Action mutliply_by_3` ) ). ********************************************************************** * Notes: @@ -579,7 +588,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -588,28 +597,30 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. ORDER BY key_field INTO TABLE @tab_root. - output->display( input = tab_root name = `tab_root` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). "Displaying response information IF mapped-root IS NOT INITIAL. - - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root entity)` ). - - output->display( input = mapped-root name = `mapped-root` ). + out->write( |\n| ). + out->write( data = mapped-root name = `mapped-root` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). - + out->write( `Entries in REPORTED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). +out->write( |\n| ). ENDIF. ********************************************************************** @@ -618,7 +629,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * ********************************************************************** - output->next_section( `6) Executing ACTION set_z` ). + out->write( zcl_demo_abap_aux=>heading( `6) Executing ACTION set_z` ) ). ********************************************************************** * Notes: @@ -656,7 +667,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -665,28 +676,30 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. ORDER BY key_field INTO TABLE @tab_root. - output->display( input = tab_root name = `tab_root` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). "Displaying response information IF mapped-root IS NOT INITIAL. - - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root entity)` ). - - output->display( input = mapped-root name = `mapped-root` ). + out->write( |\n| ). + out->write( data = mapped-root name = `mapped-root` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). - + out->write( `Entries in REPORTED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). +out->write( |\n| ). ENDIF. ********************************************************************** @@ -695,7 +708,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * ********************************************************************** - output->next_section( `7) Create-by-Association Operation (from Root to Child Entity)` ). + out->write( zcl_demo_abap_aux=>heading( `7) Create-by-Association Operation (from Root to Child Entity)` ) ). ********************************************************************** * Notes: @@ -763,7 +776,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. COMMIT ENTITIES. IF sy-subrc <> 0. - output->display( `An issue occurred in the RAP save sequence.` ). + out->write( `An issue occurred in the RAP save sequence.` ). ENDIF. "Retrieving and displaying database content @@ -777,27 +790,32 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. ORDER BY key_field, key_ch INTO TABLE @DATA(tab_child). - output->display( input = tab_root name = `tab_root` ). - output->display( input = tab_child name = `tab_child` ). + out->write( data = tab_root name = `tab_root` ). + out->write( |\n| ). + out->write( data = tab_child name = `tab_child` ). + out->write( |\n| ). "Displaying response information IF mapped IS NOT INITIAL. - output->display( `Entries in MAPPED response parameter ` && + out->write( `Entries in MAPPED response parameter ` && `(root and child entity)` ). - - output->display( input = mapped name = `mapped` ). +out->write( |\n| ). + out->write( data = mapped name = `mapped` ). + out->write( |\n| ). ENDIF. IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -806,7 +824,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * ********************************************************************** - output->next_section( `8) Read Operation (Root Entity)` ). + out->write( zcl_demo_abap_aux=>heading( `8) Read Operation (Root Entity)` ) ). ********************************************************************** * Notes: @@ -831,18 +849,21 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. REPORTED reported. "Displaying the read result and response information - output->display( input = result name = `result` ). + out->write( data = result name = `result` ). + out->write( |\n| ). IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). + out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************* @@ -851,7 +872,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * ********************************************************************** - output->next_section( `9) Read Operation (Child Entity)` ). + out->write( zcl_demo_abap_aux=>heading( `9) Read Operation (Child Entity)` ) ). ********************************************************************** * Notes: @@ -874,19 +895,21 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. REPORTED reported. "Displaying read result - output->display( input = read_ch name = `read_ch` ). + out->write( data = read_ch name = `read_ch` ). "Displaying response information IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -895,7 +918,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * ********************************************************************** - output->next_section( `10) Read-by-Association Operation (from Parent to Child)` ). + out->write( zcl_demo_abap_aux=>heading( `10) Read-by-Association Operation (from Parent to Child)` ) ). ********************************************************************** * Notes: @@ -919,20 +942,24 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. REPORTED reported. "Displaying read result and association links - output->display( input = rba_result name = `rba_result` ). - output->display( input = association_links name = `association_links` ). + out->write( data = rba_result name = `rba_result` ). + out->write( |\n| ). + out->write( data = association_links name = `association_links` ). + out->write( |\n| ). "Displaying response information IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -941,7 +968,7 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * ********************************************************************** - output->next_section( `11) Read-by-Association Operation (from Child to Parent)` ). + out->write( zcl_demo_abap_aux=>heading( `11) Read-by-Association Operation (from Child to Parent)` ) ). ********************************************************************** * Notes: @@ -966,20 +993,24 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. REPORTED reported. "Displaying read result and association links - output->display( input = rba_parent name = `rba_parent` ). - output->display( input = association_links_parent name = `association_links_parent` ). + out->write( data = rba_parent name = `rba_parent` ). + out->write( |\n| ). + out->write( data = association_links_parent name = `association_links_parent` ). + out->write( |\n| ). "Displaying response information IF failed IS NOT INITIAL. - output->display( `Entries in FAILED response parameter` ). - - output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( `Entries in FAILED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ). + out->write( |\n| ). ENDIF. IF reported IS NOT INITIAL. - output->display( `Entries in REPORTED response parameter` ). - - output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( `Entries in REPORTED response parameter` ). +out->write( |\n| ). + out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ). + out->write( |\n| ). ENDIF. ********************************************************************** @@ -992,9 +1023,8 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. * links are returned. The parameter for RESULT will be empty. ********************************************************************** - output->next_section( `12) Excursion: Read and read-by-association ` && - `operations using dynamic EML` ). - +out->write( zcl_demo_abap_aux=>heading( `12) Excursion: Read and read-by-association ` && + `operations using dynamic EML` ) ). DATA: op_tab TYPE abp_behv_retrievals_tab, read_dyn TYPE TABLE FOR READ IMPORT zdemo_abap_rap_ro_u, @@ -1031,8 +1061,9 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. field_ch1 = if_abap_behv=>mk-on field_ch2 = if_abap_behv=>mk-on ) ) ). - output->display( `Result if FULL parameter is ` && + out->write( `Result if FULL parameter is ` && `not flagged for RBA` ). +out->write( |\n| ). op_tab = VALUE #( ( op = if_abap_behv=>op-r-read @@ -1049,12 +1080,15 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. READ ENTITIES OPERATIONS op_tab. - output->display( input = read_dyn_result name = `read_dyn_result` ). - output->display( input = rba_dyn_result name = `rba_dyn_result` ). - output->display( input = rba_dyn_link name = `rba_dyn_link` ). - - output->display( `Result if FULL parameter is ` && + out->write( data = read_dyn_result name = `read_dyn_result` ). + out->write( |\n| ). + out->write( data = rba_dyn_result name = `rba_dyn_result` ). + out->write( |\n| ). + out->write( data = rba_dyn_link name = `rba_dyn_link` ). + out->write( |\n| ). + out->write( `Result if FULL parameter is ` && `flagged for RBA` ). +out->write( |\n| ). op_tab = VALUE #( ( op = if_abap_behv=>op-r-read @@ -1071,10 +1105,12 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION. READ ENTITIES OPERATIONS op_tab. - output->display( input = read_dyn_result name = `read_dyn_result` ). - output->display( input = rba_dyn_result name = `rba_dyn_result` ). - output->display( input = rba_dyn_link name = `rba_dyn_link` ). - + out->write( data = read_dyn_result name = `read_dyn_result` ). + out->write( |\n| ). + out->write( data = rba_dyn_result name = `rba_dyn_result` ). + out->write( |\n| ). + out->write( data = rba_dyn_link name = `rba_dyn_link` ). + out->write( |\n| ). ENDMETHOD. diff --git a/src/zcl_demo_abap_sql.clas.abap b/src/zcl_demo_abap_sql.clas.abap index d613e61..7569bdc 100644 --- a/src/zcl_demo_abap_sql.clas.abap +++ b/src/zcl_demo_abap_sql.clas.abap @@ -48,7 +48,7 @@ CLASS zcl_demo_abap_sql DEFINITION CLASS-METHODS: class_constructor. -protected section. + PROTECTED SECTION. PRIVATE SECTION. CLASS-METHODS: select_from_dbtab. @@ -61,23 +61,20 @@ ENDCLASS. -CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. +CLASS zcl_demo_abap_sql 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: ABAP SQL` ). - output->display( `Using SELECT for multiple purposes` ). - output->display( `1) Reading a single row from database table ` && - `into a structure` ). + out->write( |ABAP Cheat Sheet Example: ABAP SQL\n\n| ). + out->write( |Using SELECT for multiple purposes\n| ). + out->write( |1) Reading a single row from database table into a structure\n\n| ). "Note that, although it is optional, a WHERE clause should always be "specified for performance reasons and to restrict the read result. @@ -98,8 +95,10 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid = 'AA' AND connid = '17' INTO @DATA(struct_1a). - output->display( input = struct name = `struct` ). - output->display( input = struct_1a name = `struct_1a` ). + out->write( data = struct name = `struct` ). + out->write( |\n| ). + out->write( data = struct_1a name = `struct_1a` ). + out->write( |\n| ). "Reading selected fields @@ -125,13 +124,15 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid = 'DL' AND connid = '106' INTO CORRESPONDING FIELDS OF @struct_1d. - output->display( input = struct_1b name = `struct_1b` ). - output->display( input = struct_1c name = `struct_1c` ). - output->display( input = struct_1d name = `struct_1d` ). + out->write( data = struct_1b name = `struct_1b` ). + out->write( |\n| ). + out->write( data = struct_1c name = `struct_1c` ). + out->write( |\n| ). + out->write( data = struct_1d name = `struct_1d` ). ********************************************************************** - output->next_section( `2) Reading mutliple rows into an internal table` ). + out->write( zcl_demo_abap_aux=>heading( `2) Reading mutliple rows into an internal table` ) ). "Reading all fields into an existing internal table SELECT FROM zdemo_abap_flsch @@ -156,13 +157,15 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid = 'AZ' INTO CORRESPONDING FIELDS OF TABLE @itab_2b. - output->display( input = itab name = `itab` ). - output->display( input = itab_2a name = `itab_2a` ). - output->display( input = itab_2b name = `itab_2b` ). + out->write( data = itab name = `itab` ). + out->write( |\n| ). + out->write( data = itab_2a name = `itab_2a` ). + out->write( |\n| ). + out->write( data = itab_2b name = `itab_2b` ). ********************************************************************** - output->next_section( `3) SELECT loop: Sequentially reading multiple rows` ). + out->write( zcl_demo_abap_aux=>heading( `3) SELECT loop: Sequentially reading multiple rows` ) ). "In the example below, the individual rows that are read are "modified before they are appended to an internal table. @@ -187,12 +190,12 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ENDIF. ENDSELECT. - output->display( input = itab3 name = `itab3` ). + out->write( data = itab3 name = `itab3` ). ********************************************************************** - output->next_section( `4) INTO CORRESPONDING FIELDS OF: Reading into existing` && - ` target variables that have a line type not matching the type of the data source` ). + out->write( zcl_demo_abap_aux=>heading( `4) INTO CORRESPONDING FIELDS OF: Reading into existing` && + ` target variables that have a line type not matching the type of the data source` ) ). "Note: The addition CORRESPONDING FIELDS OF is needed when using "an existing variable to read data into, otherwise a type @@ -224,18 +227,18 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid = 'AZ' INTO CORRESPONDING FIELDS OF TABLE @itab4. - output->display( input = struc4 name = `struc4` ). - output->display( input = itab4 name = `itab4` ). + out->write( data = struc4 name = `struc4` ). + out->write( |\n| ). + out->write( data = itab4 name = `itab4` ). ********************************************************************** - output->next_section( `Clause variations and additions in SELECT statements` ). + out->write( zcl_demo_abap_aux=>heading( `Clause variations and additions in SELECT statements` ) ). "SELECT/FROM clause variants - output->display( 'SELECT/FROM clause variants' ). + out->write( |SELECT/FROM clause variants\n| ). - output->display( `5) Checking the existence of a row in ` && - `a database table` ). + out->write( |5) Checking the existence of a row in a database table\n| ). "Instead of @abap_true, you could also use 'X' in the example below. @@ -245,14 +248,14 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. INTO @DATA(exists). IF exists = abap_true. - output->display( `A line was found.` ). + out->write( `A line was found.` ). ELSE. - output->display( `Nothing found.` ). + out->write( `Nothing found.` ). ENDIF. ********************************************************************** - output->next_section( `6) DISTINCT addition: Removing duplicative rows from the result set` ). + out->write( zcl_demo_abap_aux=>heading( `6) DISTINCT addition: Removing duplicative rows from the result set` ) ). "The example shows the comparison of statements with and without "the use of DISTINCT. When used without DISTINCT, the result @@ -273,12 +276,13 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. cityto = 'NEW YORK' INTO TABLE @DATA(itab_6b). - output->display( input = itab_6a name = `itab_6a` ). - output->display( input = itab_6b name = `itab_6b` ). + out->write( data = itab_6a name = `itab_6a` ). + out->write( |\n| ). + out->write( data = itab_6b name = `itab_6b` ). ********************************************************************** - output->next_section( `7) SELECT list variants` ). + out->write( zcl_demo_abap_aux=>heading( `7) SELECT list variants` ) ). "Example 1: All fields SELECT * FROM zdemo_abap_flsch @@ -341,21 +345,27 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. "Example 7: Alias for the data source SELECT ds~carrid, ds~connid - FROM zdemo_abap_flsch as ds + FROM zdemo_abap_flsch AS ds WHERE carrid = 'JL' INTO TABLE @DATA(itab_7g). - output->display( input = itab_7a name = `itab_7a` ). - output->display( input = itab_7b name = `itab_7b` ). - output->display( input = itab_7c name = `itab_7c` ). - output->display( input = itab_7d name = `itab_7d` ). - output->display( input = itab_7e name = `itab_7e` ). - output->display( input = itab_7f name = `itab_7f` ). - output->display( input = itab_7g name = `itab_7g` ). + out->write( data = itab_7a name = `itab_7a` ). + out->write( |\n| ). + out->write( data = itab_7b name = `itab_7b` ). + out->write( |\n| ). + out->write( data = itab_7c name = `itab_7c` ). + out->write( |\n| ). + out->write( data = itab_7d name = `itab_7d` ). + out->write( |\n| ). + out->write( data = itab_7e name = `itab_7e` ). + out->write( |\n| ). + out->write( data = itab_7f name = `itab_7f` ). + out->write( |\n| ). + out->write( data = itab_7g name = `itab_7g` ). ********************************************************************** - output->next_section( `8) Reading from an internal table using SELECT` ). + out->write( zcl_demo_abap_aux=>heading( `8) Reading from an internal table using SELECT` ) ). "Note: The internal table from which to be read must be specified "as host variable. The internal table should have an explicitly @@ -376,12 +386,12 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid = 'AA' INTO TABLE @DATA(itab_read2). - output->display( input = itab_read2 name = `itab_read2` ). + out->write( data = itab_read2 name = `itab_read2` ). ********************************************************************** - output->next_section( 'INTO clause variants' ). - output->display( `9) UP TO: Limiting the number of returned table rows` ). + out->write( zcl_demo_abap_aux=>heading( 'INTO clause variants' ) ). + out->write( |9) UP TO: Limiting the number of returned table rows\n\n| ). "Restricting the absolute number of returned table rows "by specifying a number n in the addition UP TO n ROWS. @@ -400,11 +410,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. INTO TABLE @DATA(itab_up) UP TO 2 ROWS. - output->display( input = itab_up name = `itab_up` ). + out->write( data = itab_up name = `itab_up` ). ********************************************************************** - output->display( `10) OFFSET: Returning only the table rows after a row with a specified count from the result set` ). + out->write( zcl_demo_abap_aux=>heading( `10) OFFSET: Returning only the table rows after a row with a specified count from the result set` ) ). "In the example, data of all flights are retrieved, except for the 2 flights "with the shortest flight time. @@ -416,7 +426,8 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ORDER BY fltime ASCENDING INTO TABLE @DATA(itab_no_off). - output->display( input = itab_no_off name = `itab_no_off` ). + out->write( data = itab_no_off name = `itab_no_off` ). + out->write( |\n| ). SELECT * FROM zdemo_abap_flsch @@ -425,11 +436,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. INTO TABLE @DATA(itab_w_off) OFFSET 2. - output->display( input = itab_w_off name = `itab_w_off` ). + out->write( data = itab_w_off name = `itab_w_off` ). ********************************************************************** - output->next_section( `11) Reading into individual elementary data objects` ). + out->write( zcl_demo_abap_aux=>heading( `11) Reading into individual elementary data objects` ) ). "The field list and the INTO list must have the "same number of elements. @@ -459,11 +470,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ENDIF. ENDSELECT. - output->display( input = itab_ind name = `itab_ind` ). + out->write( data = itab_ind name = `itab_ind` ). ********************************************************************** - output->next_section( `12) Appending the result set to an existing internal table` ). + out->write( zcl_demo_abap_aux=>heading( `12) Appending the result set to an existing internal table` ) ). "APPEDNING TABLE @@ -476,7 +487,8 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid = 'JL' APPENDING TABLE @itab_up. - output->display( input = itab_up name = `itab_up` ). + out->write( data = itab_up name = `itab_up` ). + out->write( |\n| ). "APPENDING CORRESPONDING FIELDS OF TABLE @@ -502,11 +514,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid = 'JL' APPENDING CORRESPONDING FIELDS OF TABLE @itab_corr. - output->display( input = itab_corr name = `itab_corr` ). + out->write( data = itab_corr name = `itab_corr` ). ********************************************************************** - output->next_section( `13) Reading into packages of a specified number of rows` ). + out->write( zcl_demo_abap_aux=>heading( `13) Reading into packages of a specified number of rows` ) ). "After PACKAGE SIZE, the number of rows is specified denoting the number "of rows to be inserted in the target object per iteration The internal @@ -534,12 +546,13 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ENDIF. ENDSELECT. - output->display( input = pack_table name = `pack_table` ). - output->display( input = itab_pack name = `itab_pack` ). + out->write( data = pack_table name = `pack_table` ). + out->write( |\n| ). + out->write( data = itab_pack name = `itab_pack` ). ********************************************************************** - output->next_section( `14) Specifying an anonymous data object as target object` ). + out->write( zcl_demo_abap_aux=>heading( `14) Specifying an anonymous data object as target object` ) ). SELECT * FROM zdemo_abap_flsch @@ -547,12 +560,12 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. INTO TABLE NEW @DATA(dref) UP TO 2 ROWS. - output->display( input = dref->* name = `dref->*` ). + out->write( data = dref->* name = `dref->*` ). ********************************************************************** - output->next_section( `Excursion: ABAP SQL - Operands and Expressions` ). - output->display( `15) SQL operands` ). + out->write( zcl_demo_abap_aux=>heading( `Excursion: ABAP SQL - Operands and Expressions` ) ). + out->write( |15) SQL operands\n\n| ). "SQL operands are elementary operands in an ABAP SQL statement. "Can be database table or view columns, a literal, host variables @@ -583,9 +596,9 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. char`X` AS flag, "Typed literal - @upto as num, "Host variable + @upto AS num, "Host variable - @( cl_abap_context_info=>get_system_date( ) ) as date "Host expression + @( cl_abap_context_info=>get_system_date( ) ) AS date "Host expression WHERE carrid = 'LH' "Untyped literal AND countryfr = char`DE` "Typed literal @@ -599,15 +612,15 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. "UP TO @upto ROWS. "Host variable "UP TO @( 10 - 7 ) ROWS. "Host expression - output->display( input = sql_operands name = `sql_operands` ). + out->write( data = sql_operands name = `sql_operands` ). ********************************************************************** - output->next_section( `16) Numeric functions ` ). + out->write( zcl_demo_abap_aux=>heading( `16) Numeric functions ` ) ). - "You can use built-in functions in ABAP SQL. - "Result: Value with the associated dictionary type. - "Arguments of the functions: Cover one or more SQL expressions. + "You can use built-in functions in ABAP SQL. + "Result: Value with the associated dictionary type. + "Arguments of the functions: Cover one or more SQL expressions. SELECT SINGLE carrname, @@ -639,11 +652,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid = 'AA' INTO @DATA(numeric_functions). - output->display( input = numeric_functions name = `numeric_functions` ). + out->write( data = numeric_functions name = `numeric_functions` ). ********************************************************************** - output->next_section( `17) String functions` ). + out->write( zcl_demo_abap_aux=>heading( `17) String functions` ) ). SELECT SINGLE carrid, "LH @@ -746,11 +759,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid = 'LH' INTO @DATA(string_functions). - output->display( input = string_functions name = `string_functions` ). + out->write( data = string_functions name = `string_functions` ). ********************************************************************** - output->next_section( `18) Special functions` ). + out->write( zcl_demo_abap_aux=>heading( `18) Special functions` ) ). SELECT SINGLE carrid, @@ -795,20 +808,21 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid = 'AA' INTO @DATA(special_functions). - "Retrieving type information using RTTI to demonstrate the effect - "of type conversions like to_clob etc. - "type_kind: g (character string with variable length), - "C (character string of fixed length), X (binary), y (byte string) - DATA(components) = CAST cl_abap_structdescr( - cl_abap_typedescr=>describe_by_data( special_functions ) - )->components. + "Retrieving type information using RTTI to demonstrate the effect + "of type conversions like to_clob etc. + "type_kind: g (character string with variable length), + "C (character string of fixed length), X (binary), y (byte string) + DATA(components) = CAST cl_abap_structdescr( + cl_abap_typedescr=>describe_by_data( special_functions ) + )->components. - output->display( input = components name = `components` ). - output->display( input = special_functions name = `special_functions` ). + out->write( data = components name = `components` ). + out->write( |\n| ). + out->write( data = special_functions name = `special_functions` ). ********************************************************************** - output->next_section( `19) Aggregate Expressions` ). + out->write( zcl_demo_abap_aux=>heading( `19) Aggregate Expressions` ) ). "Consist of aggregate functions and aggregate the values of "multiple rows of the result set of a query into a single value. @@ -846,11 +860,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. GROUP BY carrid INTO TABLE @DATA(agg_exp). - output->display( input = agg_exp name = `agg_exp` ). + out->write( data = agg_exp name = `agg_exp` ). ********************************************************************** - output->next_section( `20) More SQL Expressions` ). + out->write( zcl_demo_abap_aux=>heading( `20) More SQL Expressions` ) ). "Arithmetic expressions to perform arithmetic calculations "Cast expressions to convert the value of operands to a dedicated @@ -907,11 +921,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid = 'AA' INTO @DATA(more_sql_expr). - output->display( input = more_sql_expr name = `more_sql_expr` ). + out->write( data = more_sql_expr name = `more_sql_expr` ). ********************************************************************** - output->next_section( `21) Window expressions (1)` ). + out->write( zcl_demo_abap_aux=>heading( `21) Window expressions (1)` ) ). "A simple window is constructed in the OVER clause, "window functions - here aggregate functions - are applied. @@ -926,13 +940,13 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ORDER BY carrid INTO TABLE @DATA(win). - DELETE ADJACENT DUPLICATES FROM win COMPARING ALL FIELDS. + DELETE ADJACENT DUPLICATES FROM win COMPARING ALL FIELDS. - output->display( input = win name = `win` ). + out->write( data = win name = `win` ). ********************************************************************** - output->next_section( `22) Window expressions (2)` ). + out->write( zcl_demo_abap_aux=>heading( `22) Window expressions (2)` ) ). SELECT carrid, currency, fldate, "Sorts the rows by some columns and counts the number of rows from @@ -980,12 +994,12 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. FROM zdemo_abap_fli INTO TABLE @DATA(win_order). - output->display( input = win_order name = `win_order` ). + out->write( data = win_order name = `win_order` ). ********************************************************************** - output->next_section( `SQL conditions` ). - output->display( `23) SQL conditions (1)` ). + out->write( zcl_demo_abap_aux=>heading( `SQL conditions` ) ). + out->write( |23) SQL conditions (1)\n\n| ). "The example demonstrates a WHERE clause with =, >, <, <=, >=, AND SELECT * FROM zdemo_abap_fli @@ -996,11 +1010,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. AND seatsmax_b >= 30 "or GE INTO TABLE @DATA(itab_comp_op). - output->display( input = itab_comp_op name = `itab_comp_op` ). + out->write( data = itab_comp_op name = `itab_comp_op` ). ********************************************************************** - output->next_section( `24) SQL conditions (2)` ). + out->write( zcl_demo_abap_aux=>heading( `24) SQL conditions (2)` ) ). "The example demonstrates a WHERE clause with "BETWEEN, NOT BETWEEN, OR @@ -1010,11 +1024,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. OR price NOT BETWEEN 100 AND 1500 INTO TABLE @DATA(it_sql_cond). - output->display( input = it_sql_cond name = `it_sql_cond` ). + out->write( data = it_sql_cond name = `it_sql_cond` ). ********************************************************************** - output->next_section( `25) SQL conditions (3)` ). + out->write( zcl_demo_abap_aux=>heading( `25) SQL conditions (3)` ) ). "The example demonstrates a WHERE clause with character literals: "- LIKE '%FRAN%': Condition is true if the column cityfrom contains @@ -1033,14 +1047,13 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. INTO TABLE @DATA(itab_like_in). - output->display( input = itab_like_in name = `itab_like_in` ). + out->write( data = itab_like_in name = `itab_like_in` ). ********************************************************************** - output->next_section( `Further clauses in SELECT statements` ). + out->write( zcl_demo_abap_aux=>heading( `Further clauses in SELECT statements` ) ). - output->display( `26) GROUP BY: Combining groups of table rows ` && - `in the result set` ). + out->write( |26) GROUP BY: Combining groups of table rows in the result set\n\n| ). "In the example, the database table rows that have the same content "in column CARRID are combined. The lowest and highest values in "column PRICE are determined for each of these groups and placed @@ -1057,12 +1070,12 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. GROUP BY carrid INTO TABLE @DATA(itab_gr). - output->display( input = itab_gr name = `itab_gr` ). + out->write( data = itab_gr name = `itab_gr` ). ********************************************************************** - output->next_section( `27) HAVING: Limiting the number of rows` && - ` in groups in the result set` ). + out->write( zcl_demo_abap_aux=>heading( `27) HAVING: Limiting the number of rows` && + ` in groups in the result set` ) ). "The addition HAVING limits the number of rows in groups in the "result set of a query by using a logical expression on these rows. @@ -1077,12 +1090,12 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. HAVING SUM( fltime ) > 100 INTO TABLE @DATA(itab_hav). - output->display( input = itab_hav name = `itab_hav` ). + out->write( data = itab_hav name = `itab_hav` ). ********************************************************************** - output->next_section( `28) ORDER BY: Sorting the result set by ` && - `specified columns` ). + out->write( zcl_demo_abap_aux=>heading( `28) ORDER BY: Sorting the result set by ` && + `specified columns` ) ). "The following example shows the ordering of the result set based "on the content of the primary key of the data source. You can also @@ -1106,13 +1119,14 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. INTO TABLE @DATA(itab_ord2) UP TO 3 ROWS. - output->display( input = itab_ord1 name = `itab_ord1` ). - output->display( input = itab_ord2 name = `itab_ord2` ). + out->write( data = itab_ord1 name = `itab_ord1` ). + out->write( |\n| ). + out->write( data = itab_ord2 name = `itab_ord2` ). ********************************************************************** - output->next_section( `WHERE clause variants: Selecting data by evaluating the content of other tables` ). - output->display( `29) FOR ALL ENTRIES addition` ). + out->write( zcl_demo_abap_aux=>heading( `WHERE clause variants: Selecting data by evaluating the content of other tables` ) ). + out->write( |29) FOR ALL ENTRIES addition\n\n| ). "In the example, only those entries should be read from the "database table if entries exist in the internal table that meet @@ -1128,7 +1142,7 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. INTO TABLE @DATA(cond_tab). IF ( 0 < lines( cond_tab ) ). - SELECT carrid, connid, cityfrom, cityto "#EC CI_NO_TRANSFORM + SELECT carrid, connid, cityfrom, cityto "#EC CI_NO_TRANSFORM FROM zdemo_abap_flsch FOR ALL ENTRIES IN @cond_tab WHERE carrid = @cond_tab-carrid @@ -1136,11 +1150,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. INTO TABLE @DATA(itab_forall). ENDIF. - output->display( input = itab_forall name = `itab_forall` ). + out->write( data = itab_forall name = `itab_forall` ). ********************************************************************** - output->next_section( `30) Checking the result set of a subquery` ). + out->write( zcl_demo_abap_aux=>heading( `30) Checking the result set of a subquery` ) ). "In the example, all available flights leaving from a city with "FRAN in the name (San Francisco, Frankfurt) existing in another @@ -1157,12 +1171,12 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ORDER BY carrid, connid, fldate INTO TABLE @DATA(itab_sub). - output->display( input = itab_sub name = `itab_sub` ). + out->write( data = itab_sub name = `itab_sub` ). ********************************************************************** - output->next_section( `Combining Data of Multiple Database Tables` ). - output->display( `31) Inner join` ). + out->write( zcl_demo_abap_aux=>heading( `Combining Data of Multiple Database Tables` ) ). + out->write( |31) Inner join\n\n| ). "Result set: "- Columns of the rows in the result set of the left side with the columns " of the rows in the result set of the right side are joined into a single @@ -1189,12 +1203,13 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ORDER BY p~carrid INTO TABLE @DATA(itab_in2). - output->display( input = itab_in1 name = `itab_in1` ). - output->display( input = itab_in2 name = `itab_in2` ). + out->write( data = itab_in1 name = `itab_in1` ). + out->write( |\n| ). + out->write( data = itab_in2 name = `itab_in2` ). ********************************************************************** - output->next_section( `32) Left outer join` ). + out->write( zcl_demo_abap_aux=>heading( `32) Left outer join` ) ). "Result set: "- Same result set as the inner join. @@ -1216,11 +1231,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ORDER BY s~carrid INTO TABLE @DATA(itab_lo). - output->display( input = itab_lo name = `itab_lo` ). + out->write( data = itab_lo name = `itab_lo` ). ********************************************************************** - output->next_section( `33) Merging the result sets of multiple queries into a single result set using UNION` ). + out->write( zcl_demo_abap_aux=>heading( `33) Merging the result sets of multiple queries into a single result set using UNION` ) ). "Effect: The rows of the result set of the query after UNION are "inserted into the result set of the query in front of UNION. @@ -1244,11 +1259,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ORDER BY carrname DESCENDING, connid, cityfrom, cityto INTO TABLE @DATA(itab_union). - output->display( input = itab_union name = `itab_union` ). + out->write( data = itab_union name = `itab_union` ). ********************************************************************** - output->next_section( `34) Common Table Expressions (CTE) (1)` ). + out->write( zcl_demo_abap_aux=>heading( `34) Common Table Expressions (CTE) (1)` ) ). "The result sets of both common table expressions +connections "and +sum_seats are merged in the subquery of the CTE +result in @@ -1281,11 +1296,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ORDER BY name, connection INTO TABLE @DATA(itab_cte). - output->display( input = itab_cte name = `itab_cte` ). + out->write( data = itab_cte name = `itab_cte` ). ********************************************************************** - output->next_section( `35) CTE and a SELECT Loop (2)` ). + out->write( zcl_demo_abap_aux=>heading( `35) CTE and a SELECT Loop (2)` ) ). "The example shows a WITH statement, whose main query creates a "tabular result set. Since the data is written into work area "rather than to an internal table, a SELECT loop is opened, which @@ -1301,12 +1316,13 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE s~carrid = 'LH' INTO @DATA(wa_cte_loop) UP TO 3 ROWS. - output->display( input = wa_cte_loop name = `wa_cte_loop` ). + out->write( data = wa_cte_loop name = `wa_cte_loop` ). + out->write( |\n| ). ENDWITH. ********************************************************************** - output->next_section( `Changing data in database tables` ). + out->write( zcl_demo_abap_aux=>heading( `Changing data in database tables` ) ). "Deleting database table to work with DELETE FROM zdemo_abap_carr. @@ -1324,7 +1340,7 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ********************************************************************** - output->display( `36) INSERT: Inserting individual line into a database table` ). + out->write( |36) INSERT: Inserting individual line into a database table\n\n| ). "Inserting from an existing structure INSERT INTO zdemo_abap_carr VALUES @row1. @@ -1341,11 +1357,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. select_from_dbtab( ). - output->display( input = itab_res name = `itab_res` ). + out->write( data = itab_res name = `itab_res` ). ********************************************************************** - output->next_section( `37) INSERT: Inserting multiple rows into a database table` ). + out->write( zcl_demo_abap_aux=>heading( `37) INSERT: Inserting multiple rows into a database table` ) ). "Creating and filling an internal table DATA itab_insert TYPE TABLE OF zdemo_abap_carr. @@ -1375,11 +1391,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. url = 'http://www.qantas.com.au' ) ) ). select_from_dbtab( ). - output->display( input = itab_res name = `itab_res` ). + out->write( data = itab_res name = `itab_res` ). ********************************************************************** - output->next_section( `38) INSERT: Inserting multiple rows into a database table accepting duplicate keys` ). + out->write( zcl_demo_abap_aux=>heading( `38) INSERT: Inserting multiple rows into a database table accepting duplicate keys` ) ). "ACCEPTING DUPLICATE KEYS addition: To avoid a runtime error when "inserting entries from an internal table having duplicate keys, @@ -1403,12 +1419,13 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. DATA(subrc) = sy-subrc. select_from_dbtab( ). - output->display( input = itab_res name = `itab_res` ). - output->display( input = subrc name = `subrc` ). + out->write( data = itab_res name = `itab_res` ). + out->write( |\n| ). + out->write( data = subrc name = `subrc` ). ********************************************************************** - output->next_section( `39) INSERT: Using a subquery` ). + out->write( zcl_demo_abap_aux=>heading( `39) INSERT: Using a subquery` ) ). "The purpose of this abstract example is just to visualize that "subqueries are possible in INSERT statements. In the example, @@ -1423,11 +1440,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. connid = '0400' ). select_from_dbtab( ). - output->display( input = itab_res name = `itab_res` ). + out->write( data = itab_res name = `itab_res` ). ********************************************************************** - output->next_section( `40) UPDATE: Changing content of existing rows` ). + out->write( zcl_demo_abap_aux=>heading( `40) UPDATE: Changing content of existing rows` ) ). "Creating and filling structure "In the case below, all field values except the key field are updated. @@ -1455,11 +1472,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. UPDATE zdemo_abap_carr FROM TABLE @itab_update. select_from_dbtab( ). - output->display( input = itab_res name = `itab_res` ). + out->write( data = itab_res name = `itab_res` ). ********************************************************************** - output->next_section( `41) UPDATE: Changing values of specific fields in all table rows` ). + out->write( zcl_demo_abap_aux=>heading( `41) UPDATE: Changing values of specific fields in all table rows` ) ). "Using the SET addition, you can change the values of specific "fields in all table rows without overwriting existing values in @@ -1472,13 +1489,13 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. WHERE carrid <> 'UA' AND carrid <> 'ET'. select_from_dbtab( ). - output->display( input = itab_res name = `itab_res` ). + out->write( data = itab_res name = `itab_res` ). ********************************************************************** - output->next_section( `42) INDICATORS addition to UPDATE statements: ` && + out->write( zcl_demo_abap_aux=>heading( `42) INDICATORS addition to UPDATE statements: ` && `Changing values of specific fields without overwriting ` && - `existing values of other fields ` ). + `existing values of other fields ` ) ). "Example: "- Structured type is created with WITH INDICATORS addition @@ -1510,11 +1527,11 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. INDICATORS SET STRUCTURE comp_ind. select_from_dbtab( ). - output->display( input = itab_res name = `itab_res` ). + out->write( data = itab_res name = `itab_res` ). ********************************************************************** - output->next_section( `43) MODIFY: Inserting and changing rows` ). + out->write( zcl_demo_abap_aux=>heading( `43) MODIFY: Inserting and changing rows` ) ). "The example only uses host expressions. "Modifying an entry based on a row. Here, a new entry is created in @@ -1547,12 +1564,13 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. dbcnt = dbcnt + sy-dbcnt. select_from_dbtab( ). - output->display( input = itab_res name = `itab_res` ). - output->display( |{ dbcnt } table rows were modified.| ). + out->write( data = itab_res name = `itab_res` ). + out->write( |\n| ). + out->write( |{ dbcnt } table rows were modified.| ). ********************************************************************** - output->next_section( `44) DELETE: Deleting table rows` ). + out->write( zcl_demo_abap_aux=>heading( `44) DELETE: Deleting table rows` ) ). "Note that you specify the key fields only. "Deleting an entry based on a row. Here, the example uses a @@ -1568,25 +1586,25 @@ CLASS ZCL_DEMO_ABAP_SQL IMPLEMENTATION. ( carrid = 'LH' ) ) ). select_from_dbtab( ). - output->display( input = itab_res name = `itab_res` ). + out->write( data = itab_res name = `itab_res` ). ********************************************************************** - output->next_section( `45) DELETE: Deleting table rows based on a condition` ). + out->write( zcl_demo_abap_aux=>heading( `45) DELETE: Deleting table rows based on a condition` ) ). DELETE FROM zdemo_abap_carr WHERE currcode <> 'EUR'. select_from_dbtab( ). - output->display( input = itab_res name = `itab_res` ). + out->write( data = itab_res name = `itab_res` ). ********************************************************************** - output->next_section( `46) DELETE: Delete complete table` ). + out->write( zcl_demo_abap_aux=>heading( `46) DELETE: Delete complete table` ) ). DELETE FROM zdemo_abap_carr. select_from_dbtab( ). - output->display( input = itab_res name = `itab_res` ). + out->write( data = itab_res name = `itab_res` ). ENDMETHOD. diff --git a/src/zcl_demo_abap_sql_group_by.clas.abap b/src/zcl_demo_abap_sql_group_by.clas.abap index e92cd5f..b753dca 100644 --- a/src/zcl_demo_abap_sql_group_by.clas.abap +++ b/src/zcl_demo_abap_sql_group_by.clas.abap @@ -61,29 +61,27 @@ CLASS ZCL_DEMO_ABAP_SQL_GROUP_BY IMPLEMENTATION. METHOD class_constructor. "Fill 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: Grouping Internal Tables` ). + out->write( |ABAP Cheat Sheet Example: Grouping Internal Tables\n\n| ). SELECT * FROM zdemo_abap_flsch INTO TABLE @DATA(fli_tab). - output->display( `1) Representative Binding` ). - output->display( `1a) Grouping by one column` ). + out->write( |1) Representative Binding\n| ). + out->write( |1a) Grouping by one column\n| ). LOOP AT fli_tab INTO wa GROUP BY wa-carrid. - output->display( wa-carrid ). + out->write( wa-carrid ). ENDLOOP. - output->next_section( `1b) Members of one column groups` ). + out->write( zcl_demo_abap_aux=>heading( `1b) Members of one column groups` ) ). LOOP AT fli_tab INTO wa GROUP BY wa-carrid. @@ -92,18 +90,20 @@ CLASS ZCL_DEMO_ABAP_SQL_GROUP_BY IMPLEMENTATION. members = VALUE #( BASE members ( member ) ). ENDLOOP. - output->display( members ). + out->write( members ). + out->write( |\n| ). ENDLOOP. - output->next_section( `1c) Grouping by two columns` ). + out->write( zcl_demo_abap_aux=>heading( `1c) Grouping by two columns` ) ). LOOP AT fli_tab INTO wa GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ). - output->display( |{ wa-carrid } { wa-airpfrom }| ). + out->write( |{ wa-carrid } { wa-airpfrom }| ). + out->write( |\n| ). ENDLOOP. - output->next_section( `1d) Members of two column groups` ). + out->write( zcl_demo_abap_aux=>heading( `1d) Members of two column groups` ) ). LOOP AT fli_tab INTO wa GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ). @@ -112,20 +112,22 @@ CLASS ZCL_DEMO_ABAP_SQL_GROUP_BY IMPLEMENTATION. members = VALUE #( BASE members ( member ) ). ENDLOOP. - output->display( members ). + out->write( members ). + out->write( |\n| ). ENDLOOP. - output->next_section( `2) Group Key Binding` ). - output->display( `2a) Grouping by one column` ). + out->write( zcl_demo_abap_aux=>heading( `2) Group Key Binding` ) ). + out->write( |2a) Grouping by one column\n| ). LOOP AT fli_tab INTO wa GROUP BY wa-carrid INTO DATA(key). - output->display( key ). + out->write( key ). + out->write( |\n| ). ENDLOOP. - output->next_section( `2b) Members of one column groups` ). + out->write( zcl_demo_abap_aux=>heading( `2b) Members of one column groups` ) ). LOOP AT fli_tab INTO wa GROUP BY wa-carrid @@ -135,19 +137,21 @@ CLASS ZCL_DEMO_ABAP_SQL_GROUP_BY IMPLEMENTATION. members = VALUE #( BASE members ( member ) ). ENDLOOP. - output->display( members ). + out->write( members ). + out->write( |\n| ). ENDLOOP. - output->next_section( `2c) Grouping by two columns` ). + out->write( zcl_demo_abap_aux=>heading( `2c) Grouping by two columns` ) ). LOOP AT fli_tab INTO wa GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ) INTO DATA(keys). - output->display( keys ). + out->write( keys ). + out->write( |\n| ). ENDLOOP. - output->next_section( `2d) Members of two column groups` ). + out->write( zcl_demo_abap_aux=>heading( `2d) Members of two column groups` ) ). LOOP AT fli_tab INTO wa GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ) @@ -157,10 +161,11 @@ CLASS ZCL_DEMO_ABAP_SQL_GROUP_BY IMPLEMENTATION. members = VALUE #( BASE members ( member ) ). ENDLOOP. - output->display( members ). + out->write( members ). + out->write( |\n| ). ENDLOOP. - output->next_section( `2e) Two column groups without members` ). + out->write( zcl_demo_abap_aux=>heading( `2e) Two column groups without members` ) ). LOOP AT fli_tab INTO wa GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom @@ -168,7 +173,8 @@ CLASS ZCL_DEMO_ABAP_SQL_GROUP_BY IMPLEMENTATION. WITHOUT MEMBERS INTO DATA(keysplus). - output->display( keysplus ). + out->write( keysplus ). + out->write( |\n| ). ENDLOOP. ENDMETHOD. diff --git a/src/zcl_demo_abap_string_proc.clas.abap b/src/zcl_demo_abap_string_proc.clas.abap index d18fe54..1497fa6 100644 --- a/src/zcl_demo_abap_string_proc.clas.abap +++ b/src/zcl_demo_abap_string_proc.clas.abap @@ -53,15 +53,13 @@ ENDCLASS. -CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. +CLASS zcl_demo_abap_string_proc IMPLEMENTATION. METHOD if_oo_adt_classrun~main. - DATA(output) = NEW zcl_demo_abap_display( out ). - - output->display( `ABAP Cheat Sheet Example: String Processing` ). - output->display( `1) Creating Strings and Assigning Values` ). + out->write( |ABAP Cheat Sheet Example: String Processing\n\n| ). + out->write( |1) Creating Strings and Assigning Values\n\n| ). "Data object declarations providing default values DATA: flag TYPE c LENGTH 1 VALUE 'X', "Single quotes @@ -114,14 +112,17 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "Note the conversion result of str_a5 above (i to string) DATA(str_a8) = str_a4 && ` ` && str_a5 && `!`. - output->display( input = str_a3 name = `str_a3` ). - output->display( input = char_a2 name = `char_a2` ). - output->display( input = str_a7 name = `str_a7` ). - output->display( input = str_a8 name = `str_a8` ). + out->write( data = str_a3 name = `str_a3` ). + out->write( |\n| ). + out->write( data = char_a2 name = `char_a2` ). + out->write( |\n| ). + out->write( data = str_a7 name = `str_a7` ). + out->write( |\n| ). + out->write( data = str_a8 name = `str_a8` ). ********************************************************************** - output->next_section( `2) Chaining Strings` ). + out->write( zcl_demo_abap_aux=>heading( `2) Chaining Strings` ) ). DATA(str_b1) = `Hallo`. DATA(str_b2) = `how`. @@ -136,12 +137,13 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. DATA(str_b5) = `AB` & `AP `. - output->display( input = str_b4 name = `str_b4` ). - output->display( input = char_b1 name = `char_b1` ). + out->write( data = str_b4 name = `str_b4` ). + out->write( |\n| ). + out->write( data = char_b1 name = `char_b1` ). ********************************************************************** - output->next_section( `3a) String Templates (1): Constructing Strings` ). + out->write( zcl_demo_abap_aux=>heading( `3a) String Templates (1): Constructing Strings` ) ). "The expression must be convertible to a string. A blank (not "within the curly brackets) means a blank in the resulting string. @@ -151,18 +153,19 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. DATA(str_c4) = |{ str_c1 } { sy-uname }, | && |{ str_c2 } { str_c3 } you?|. - output->display( input = str_c4 name = `str_c4` ). + out->write( data = str_c4 name = `str_c4` ). ********************************************************************** - output->next_section( `3b) String Templates (2): Control Characters` ). + out->write( zcl_demo_abap_aux=>heading( `3b) String Templates (2): Control Characters` ) ). "Interpretation of character combinations as control characters "\n interpreted as a line break DATA(str_c5) = |{ str_c1 }\n{ sy-uname },| && |\n{ str_c2 }\n{ str_c3 }\nyou?|. - output->display( input = str_c5 name = `str_c5` ). + out->write( data = str_c5 name = `str_c5` ). + out->write( |\n| ). "Excursion: Class CL_ABAP_CHAR_UTILITIES provides attributes and methods as utilities for string processing. "See the class documentation. @@ -176,19 +179,21 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. DATA(str_c11) = |{ str_c1 }\r\n{ sy-uname }|. ASSERT str_c10 = str_c11. - output->display( input = str_c6 name = `str_c6` ). - output->display( input = str_c7 name = `str_c7` ). - output->display( input = str_c8 name = `str_c8` ). - output->display( input = str_c9 name = `str_c9` ). + out->write( data = str_c6 name = `str_c6` ). + out->write( |\n| ). + out->write( data = str_c7 name = `str_c7` ). + out->write( |\n| ). + out->write( data = str_c8 name = `str_c8` ). + out->write( |\n| ). + out->write( data = str_c9 name = `str_c9` ). ********************************************************************** - output->next_section( `4) String Templates (3): Formatting Options` ). + out->write( zcl_demo_abap_aux=>heading( `4) String Templates (3): Formatting Options` ) ). "Time, date - DATA(str_d1) = - |Date: { cl_abap_context_info=>get_system_date( ) DATE = USER }\n| && - |Time: { cl_abap_context_info=>get_system_time( ) TIME = ISO }\n| && - |Timestamp: { utclong_current( ) TIMESTAMP = SPACE }|. + DATA(str_d1a) = |Date: { cl_abap_context_info=>get_system_date( ) DATE = USER }|. + DATA(str_d1b) = |Time: { cl_abap_context_info=>get_system_time( ) TIME = ISO }|. + DATA(str_d1c) = |Timestamp: { utclong_current( ) TIMESTAMP = SPACE }|. "Upper, lower case DATA(str_d2) = |AbCdEfG|. @@ -211,21 +216,35 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "Escaping \|{} in string templates DATA(str_d14) = |\\ \| \{ \}|. - output->display( input = str_d1 name = `str_d1` ). - output->display( input = str_d3 name = `str_d3` ). - output->display( input = str_d4 name = `str_d4` ). - output->display( input = str_d5 name = `str_d5` ). - output->display( input = str_d6 name = `str_d6` ). - output->display( input = str_d7 name = `str_d7` ). - output->display( input = str_d8 name = `str_d8` ). - output->display( input = str_d9 name = `str_d9` ). - output->display( input = str_d10 name = `str_d10` ). - output->display( input = str_d11 name = `str_d11` ). - output->display( input = str_d14 name = `str_d14` ). + out->write( data = str_d1a name = `str_d1a` ). + out->write( |\n| ). + out->write( data = str_d1b name = `str_d1b` ). + out->write( |\n| ). + out->write( data = str_d1c name = `str_d1c` ). + out->write( |\n| ). + out->write( data = str_d3 name = `str_d3` ). + out->write( |\n| ). + out->write( data = str_d4 name = `str_d4` ). + out->write( |\n| ). + out->write( data = str_d5 name = `str_d5` ). + out->write( |\n| ). + out->write( data = str_d6 name = `str_d6` ). + out->write( |\n| ). + out->write( data = str_d7 name = `str_d7` ). + out->write( |\n| ). + out->write( data = str_d8 name = `str_d8` ). + out->write( |\n| ). + out->write( data = str_d9 name = `str_d9` ). + out->write( |\n| ). + out->write( data = str_d10 name = `str_d10` ). + out->write( |\n| ). + out->write( data = str_d11 name = `str_d11` ). + out->write( |\n| ). + out->write( data = str_d14 name = `str_d14` ). ********************************************************************** - output->next_section( `5) Determining the Length of Strings` ). + out->write( zcl_demo_abap_aux=>heading( `5) Determining the Length of Strings` ) ). DATA(str_e1) = `abc def ghi `. DATA(char_e1) = 'abc def ghi '. @@ -259,16 +278,21 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. int_e2 += 1. ENDDO. - output->display( input = length_e1 name = `length_e1` ). - output->display( input = length_e2 name = `length_e2` ). - output->display( input = length_e3 name = `length_e3` ). - output->display( input = length_e4 name = `length_e4` ). - output->display( input = int_e1 name = `int_e1` ). - output->display( input = int_e2 name = `int_e2` ). + out->write( data = length_e1 name = `length_e1` ). + out->write( |\n| ). + out->write( data = length_e2 name = `length_e2` ). + out->write( |\n| ). + out->write( data = length_e3 name = `length_e3` ). + out->write( |\n| ). + out->write( data = length_e4 name = `length_e4` ). + out->write( |\n| ). + out->write( data = int_e1 name = `int_e1` ). + out->write( |\n| ). + out->write( data = int_e2 name = `int_e2` ). ********************************************************************** - output->next_section( `6) Concatenating Strings` ). + out->write( zcl_demo_abap_aux=>heading( `6) Concatenating Strings` ) ). DATA(str_f1) = `Hallo`. DATA(str_f2) = `world`. @@ -321,23 +345,35 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "sep parameter specifying the separation sign DATA(alphabet5) = concat_lines_of( table = itab_g sep = `,` ). - output->display( input = str_f3 name = `str_f3` ). - output->display( input = str_f4 name = `str_f4` ). - output->display( input = str_f5 name = `str_f5` ). - output->display( input = str_f6 name = `str_f6` ). - output->display( input = str_f7 name = `str_f7` ). - output->display( input = str_f8 name = `str_f8` ). - output->display( input = char_f4 name = `char_f4` ). - output->display( input = char_f5 name = `char_f5` ). - output->display( input = alphabet1 name = `alphabet1` ). - output->display( input = alphabet2 name = `alphabet2` ). - output->display( input = alphabet3 name = `alphabet3` ). - output->display( input = alphabet4 name = `alphabet4` ). - output->display( input = alphabet5 name = `alphabet5` ). + out->write( data = str_f3 name = `str_f3` ). + out->write( |\n| ). + out->write( data = str_f4 name = `str_f4` ). + out->write( |\n| ). + out->write( data = str_f5 name = `str_f5` ). + out->write( |\n| ). + out->write( data = str_f6 name = `str_f6` ). + out->write( |\n| ). + out->write( data = str_f7 name = `str_f7` ). + out->write( |\n| ). + out->write( data = str_f8 name = `str_f8` ). + out->write( |\n| ). + out->write( data = char_f4 name = `char_f4` ). + out->write( |\n| ). + out->write( data = char_f5 name = `char_f5` ). + out->write( |\n| ). + out->write( data = alphabet1 name = `alphabet1` ). + out->write( |\n| ). + out->write( data = alphabet2 name = `alphabet2` ). + out->write( |\n| ). + out->write( data = alphabet3 name = `alphabet3` ). + out->write( |\n| ). + out->write( data = alphabet4 name = `alphabet4` ). + out->write( |\n| ). + out->write( data = alphabet5 name = `alphabet5` ). ********************************************************************** - output->next_section( `7) Splitting Strings` ). + out->write( zcl_demo_abap_aux=>heading( `7) Splitting Strings` ) ). DATA(str_g1) = `Hallo,world,12345`. @@ -381,21 +417,30 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. ENDTRY. ENDDO. - output->display( input = str_g2 name = `str_g2` ). - output->display( input = str_g3 name = `str_g3` ). - output->display( input = str_g4 name = `str_g4` ). - output->display( input = str_g5 name = `str_g5` ). - output->display( input = str_g6 name = `str_g6` ). - output->display( input = itab_g1 name = `itab_g1` ). - output->display( input = str_g7 name = `str_g7` ). - output->display( input = str_g8 name = `str_g8` ). - output->display( input = itab_g2 name = `itab_g2` ). - output->display( input = seg_nom name = `seg_nom` ). + out->write( data = str_g2 name = `str_g2` ). + out->write( |\n| ). + out->write( data = str_g3 name = `str_g3` ). + out->write( |\n| ). + out->write( data = str_g4 name = `str_g4` ). + out->write( |\n| ). + out->write( data = str_g5 name = `str_g5` ). + out->write( |\n| ). + out->write( data = str_g6 name = `str_g6` ). + out->write( |\n| ). + out->write( data = itab_g1 name = `itab_g1` ). + out->write( |\n| ). + out->write( data = str_g7 name = `str_g7` ). + out->write( |\n| ). + out->write( data = str_g8 name = `str_g8` ). + out->write( |\n| ). + out->write( data = itab_g2 name = `itab_g2` ). + out->write( |\n| ). + out->write( data = seg_nom name = `seg_nom` ). ********************************************************************** - output->next_section( `Modifying Strings` ). - output->display( `8) Transforming to Lower and Upper Case` ). + out->write( zcl_demo_abap_aux=>heading( `Modifying Strings` ) ). + out->write( |8) Transforming to Lower and Upper Case\n\n| ). DATA(str_h1) = `It's a string`. DATA(str_h2) = str_h1. @@ -426,18 +471,25 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. DATA(str_h9) = from_mixed( val = `someGreatString` sep = ` ` case = 'a' min = 4 ). - output->display( input = str_h3 name = `str_h3` ). - output->display( input = str_h4 name = `str_h4` ). - output->display( input = str_h1 name = `str_h1` ). - output->display( input = str_h2 name = `str_h2` ). - output->display( input = str_h6 name = `str_h6` ). - output->display( input = str_h7 name = `str_h7` ). - output->display( input = str_h8 name = `str_h8` ). - output->display( input = str_h9 name = `str_h9` ). + out->write( data = str_h3 name = `str_h3` ). + out->write( |\n| ). + out->write( data = str_h4 name = `str_h4` ). + out->write( |\n| ). + out->write( data = str_h1 name = `str_h1` ). + out->write( |\n| ). + out->write( data = str_h2 name = `str_h2` ). + out->write( |\n| ). + out->write( data = str_h6 name = `str_h6` ). + out->write( |\n| ). + out->write( data = str_h7 name = `str_h7` ). + out->write( |\n| ). + out->write( data = str_h8 name = `str_h8` ). + out->write( |\n| ). + out->write( data = str_h9 name = `str_h9` ). ********************************************************************** - output->next_section( `9) Shifting Content in Strings` ). + out->write( zcl_demo_abap_aux=>heading( `9) Shifting Content in Strings` ) ). DATA(str_i1) = `hallo`. DATA(str_i2) = str_i1. @@ -506,28 +558,43 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. DATA(str_i15) = shift_right( val = str_i12 ). "Same effect as above - output->display( `SHIFT statements:` ). - output->display( input = str_i2 name = `str_i2` ). - output->display( input = str_i3 name = `str_i3` ). - output->display( input = str_i4 name = `str_i4` ). - output->display( input = char_i1 name = `char_i1` ). - output->display( input = str_i5 name = `str_i5` ). - output->display( input = char_i2 name = `char_i2` ). - output->display( input = char_i3 name = `char_i3` ). - output->display( input = str_i6 name = `str_i6` ). - output->display( input = str_i7 name = `str_i7` ). + out->write( |SHIFT statements:\n\n| ). + out->write( data = str_i2 name = `str_i2` ). + out->write( |\n| ). + out->write( data = str_i3 name = `str_i3` ). + out->write( |\n| ). + out->write( data = str_i4 name = `str_i4` ). + out->write( |\n| ). + out->write( data = char_i1 name = `char_i1` ). + out->write( |\n| ). + out->write( data = str_i5 name = `str_i5` ). + out->write( |\n| ). + out->write( data = char_i2 name = `char_i2` ). + out->write( |\n| ). + out->write( data = char_i3 name = `char_i3` ). + out->write( |\n| ). + out->write( data = str_i6 name = `str_i6` ). + out->write( |\n| ). + out->write( data = str_i7 name = `str_i7` ). + out->write( |\n| ). - output->display( `String functions:` ). - output->display( input = str_i9 name = `str_i9` ). - output->display( input = str_i10 name = `str_i10` ). - output->display( input = str_i11 name = `str_i11` ). - output->display( input = str_i13 name = `str_i13` ). - output->display( input = str_i14 name = `str_i14` ). - output->display( input = str_i15 name = `str_i15` ). + out->write( |String functions:\n\n| ). + out->write( |\n| ). + out->write( data = str_i9 name = `str_i9` ). + out->write( |\n| ). + out->write( data = str_i10 name = `str_i10` ). + out->write( |\n| ). + out->write( data = str_i11 name = `str_i11` ). + out->write( |\n| ). + out->write( data = str_i13 name = `str_i13` ). + out->write( |\n| ). + out->write( data = str_i14 name = `str_i14` ). + out->write( |\n| ). + out->write( data = str_i15 name = `str_i15` ). ********************************************************************** - output->next_section( `10) Condensing Strings` ). + out->write( zcl_demo_abap_aux=>heading( `10) Condensing Strings` ) ). DATA(char_j1) = ' some text '. DATA(char_j2) = ' some more text '. @@ -589,29 +656,38 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. from = `Z` to = ` abc` ). - output->display( `CONDENSE statements:` ). - output->display( input = char_j1 name = `char_j1` ). - output->display( input = char_j2 name = `char_j2` ). - output->display( input = char_j3 name = `char_j3` ). - output->display( input = str_j name = `str_j` ). - output->next_section( `String function condense:` ). - output->display( input = str_j2 name = `str_j2` ). - output->display( input = str_j3 name = `str_j3` ). - output->display( input = str_j4 name = `str_j4` ). - output->display( input = str_j6 name = `str_j6` ). - output->display( input = str_j7 name = `str_j7` ). + out->write( |CONDENSE statements:\n| ). + out->write( |\n| ). + out->write( data = char_j1 name = `char_j1` ). + out->write( |\n| ). + out->write( data = char_j2 name = `char_j2` ). + out->write( |\n| ). + out->write( data = char_j3 name = `char_j3` ). + out->write( |\n| ). + out->write( data = str_j name = `str_j` ). + out->write( |\n| ). + out->write( zcl_demo_abap_aux=>heading( `String function condense:` ) ). + out->write( data = str_j2 name = `str_j2` ). + out->write( |\n| ). + out->write( data = str_j3 name = `str_j3` ). + out->write( |\n| ). + out->write( data = str_j4 name = `str_j4` ). + out->write( |\n| ). + out->write( data = str_j6 name = `str_j6` ). + out->write( |\n| ). + out->write( data = str_j7 name = `str_j7` ). ********************************************************************** - output->next_section( `11) Reversing Strings` ). + out->write( zcl_demo_abap_aux=>heading( `11) Reversing Strings` ) ). DATA(str_k) = reverse( `ollah` ). - output->display( input = str_k name = `str_k` ). + out->write( data = str_k name = `str_k` ). ********************************************************************** - output->next_section( `12) Inserting Substrings into Strings` ). + out->write( zcl_demo_abap_aux=>heading( `12) Inserting Substrings into Strings` ) ). DATA(str_l1) = `abcghi`. @@ -624,13 +700,15 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. DATA(str_l4) = `def` && str_l1. - output->display( input = str_l2 name = `str_l2` ). - output->display( input = str_l3 name = `str_l3` ). - output->display( input = str_l4 name = `str_l4` ). + out->write( data = str_l2 name = `str_l2` ). + out->write( |\n| ). + out->write( data = str_l3 name = `str_l3` ). + out->write( |\n| ). + out->write( data = str_l4 name = `str_l4` ). ********************************************************************** - output->next_section( `13) Overlaying Content` ). + out->write( zcl_demo_abap_aux=>heading( `13) Overlaying Content` ) ). DATA(incl) = '==============================CP'. DATA(cl_name) = 'CL_SOME_CLASS '. @@ -645,12 +723,13 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "occur in the operand are replaced. Note that this is case-sensitive. OVERLAY t1 WITH t2 ONLY 'ab'. - output->display( input = cl_name name = `cl_name` ). - output->display( input = t1 name = `t1` ). + out->write( data = cl_name name = `cl_name` ). + out->write( |\n| ). + out->write( data = t1 name = `t1` ). ********************************************************************** - output->next_section( `14) Processing Substrings` ). + out->write( zcl_demo_abap_aux=>heading( `14) Processing Substrings` ) ). DATA(str_m1) = `Lorem ipsum dolor sit amet`. @@ -713,25 +792,36 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "aa1bb2aa3b DATA(str_m13) = substring_to( val = str_m8 sub = `3b` ). - output->display( input = str_m2 name = `str_m2` ). - output->display( input = str_m3 name = `str_m3` ). - output->display( input = str_m4 name = `str_m4` ). - output->display( input = str_m5 name = `str_m5` ). - output->display( input = str_m6 name = `str_m6` ). - output->display( input = str_m7 name = `str_m7` ). - output->display( input = char_m2 name = `char_m2` ). - output->display( input = char_m3 name = `char_m3` ). - output->display( input = str_m9 name = `str_m9` ). - output->display( input = str_m10 name = `str_m10` ). - output->display( input = str_m11 name = `str_m11` ). - output->display( input = str_m12 name = `str_m12` ). - output->display( input = str_m13 name = `str_m13` ). + out->write( data = str_m2 name = `str_m2` ). + out->write( |\n| ). + out->write( data = str_m3 name = `str_m3` ). + out->write( |\n| ). + out->write( data = str_m4 name = `str_m4` ). + out->write( |\n| ). + out->write( data = str_m5 name = `str_m5` ). + out->write( |\n| ). + out->write( data = str_m6 name = `str_m6` ). + out->write( |\n| ). + out->write( data = str_m7 name = `str_m7` ). + out->write( |\n| ). + out->write( data = char_m2 name = `char_m2` ). + out->write( |\n| ). + out->write( data = char_m3 name = `char_m3` ). + out->write( |\n| ). + out->write( data = str_m9 name = `str_m9` ). + out->write( |\n| ). + out->write( data = str_m10 name = `str_m10` ). + out->write( |\n| ). + out->write( data = str_m11 name = `str_m11` ). + out->write( |\n| ). + out->write( data = str_m12 name = `str_m12` ). + out->write( |\n| ). + out->write( data = str_m13 name = `str_m13` ). ********************************************************************** - output->next_section( `Searching and Replacing in Strings` ). - output->display( `15) Searching Specific Characters in Strings ` && - `Using Comparison Operators and String Functions` ). + out->write( zcl_demo_abap_aux=>heading( `Searching and Replacing in Strings` ) ). + out->write( |15) Searching Specific Characters in Strings Using Comparison Operators and String Functions\n| ). DATA(str_n1) = `cheers`. @@ -740,46 +830,52 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "If nothing is found, sy-fdpos contains the length of the string. "Note that position 0 stands for the very first position. IF str_n1 CA `aeiou`. - output->display( |CA: str_n1 contains any of the characters. | && + out->write( |CA: str_n1 contains any of the characters. | && |The position of the first found character is { sy-fdpos }.| ). + out->write( |\n| ). ELSE. - output->display( |CA: str_n1 does not contain any of the characters. | && + out->write( |CA: str_n1 does not contain any of the characters. | && |The length of str_n1 is { sy-fdpos }.| ). + out->write( |\n| ). ENDIF. "NA (contains not any) IF str_n1 NA `xyz`. - output->display( |NA: str_n1 does not contain any of the characters.| && - |The length of str_n1 is { sy-fdpos }.| - ). + out->write( |NA: str_n1 does not contain any of the characters.| && + |The length of str_n1 is { sy-fdpos }.| ). + out->write( |\n| ). ELSE. - output->display( |NA: str_n1 contains any of the characters. | && + out->write( |NA: str_n1 contains any of the characters. | && |The position of the first found character is { sy-fdpos }.| ). + out->write( |\n| ). ENDIF. "Determining if a string is exclusively composed of a certain "character set IF str_n1 CO `rs`. - output->display( |CO: str_n1 contains only the characters. | + out->write( |CO: str_n1 contains only the characters. | && |The length of str_n1 is { sy-fdpos }.| ). + out->write( |\n| ). ELSE. - output->display( |CO: str_n1 does not contain only the characters. | + out->write( |CO: str_n1 does not contain only the characters. | && |Offset of the first character in str_n1 that is not | && |contained in the second operand: { sy-fdpos }.| ). + out->write( |\n| ). ENDIF. "Negation of CO IF str_n1 CN `chers`. - output->display( |CN: str_n1 does not contain only the characters. | + out->write( |CN: str_n1 does not contain only the characters. | && |Offset of the first character in str_n1 that is | - && |not contained in the second operand: { sy-fdpos }.| - ). + && |not contained in the second operand: { sy-fdpos }.| ). + out->write( |\n| ). ELSE. - output->display( |CN: str_n1 contains only the characters. | + out->write( |CN: str_n1 contains only the characters. | && |The length of str_n1 is { sy-fdpos }.| ). + out->write( |\n| ). ENDIF. - "String functions + "String functions DATA(str_n2) = `Pieces of cakes.`. "find_end returns the sum of the offset of the occurrence @@ -807,21 +903,31 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. DATA(res_n12) = count_any_not_of( val = str_n2 sub = `fP` ). DATA(res_n13) = count_any_not_of( val = str_n2 sub = `Piecs ofak.` ). - output->display( input = res_n3 name = `res_n3` ). - output->display( input = res_n4 name = `res_n4` ). - output->display( input = res_n5 name = `res_n5` ). - output->display( input = res_n6 name = `res_n6` ). - output->display( input = res_n7 name = `res_n7` ). - output->display( input = res_n8 name = `res_n8` ). - output->display( input = res_n9 name = `res_n9` ). - output->display( input = res_n10 name = `res_n10` ). - output->display( input = res_n11 name = `res_n11` ). - output->display( input = res_n12 name = `res_n12` ). - output->display( input = res_n13 name = `res_n13` ). + out->write( data = res_n3 name = `res_n3` ). + out->write( |\n| ). + out->write( data = res_n4 name = `res_n4` ). + out->write( |\n| ). + out->write( data = res_n5 name = `res_n5` ). + out->write( |\n| ). + out->write( data = res_n6 name = `res_n6` ). + out->write( |\n| ). + out->write( data = res_n7 name = `res_n7` ). + out->write( |\n| ). + out->write( data = res_n8 name = `res_n8` ). + out->write( |\n| ). + out->write( data = res_n9 name = `res_n9` ). + out->write( |\n| ). + out->write( data = res_n10 name = `res_n10` ). + out->write( |\n| ). + out->write( data = res_n11 name = `res_n11` ). + out->write( |\n| ). + out->write( data = res_n12 name = `res_n12` ). + out->write( |\n| ). + out->write( data = res_n13 name = `res_n13` ). ********************************************************************** - output->next_section( `16) Replacing Specific Characters in Strings` ). + out->write( zcl_demo_abap_aux=>heading( `16) Replacing Specific Characters in Strings` ) ). DATA(str_o1) = `___abc_def_____ghi_`. @@ -845,14 +951,16 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "...Zbc.def.....Yhi. TRANSLATE str_o1 USING `_.aZgY`. - output->display( input = str_o2 name = `str_o2` ). - output->display( input = str_o3 name = `str_o3` ). - output->display( input = str_o1 name = `str_o1` ). + out->write( data = str_o2 name = `str_o2` ). + out->write( |\n| ). + out->write( data = str_o3 name = `str_o3` ). + out->write( |\n| ). + out->write( data = str_o1 name = `str_o1` ). ********************************************************************** - output->next_section( `Searching for Substrings in Strings` ). - output->display( `17) Substring Search: Simple Search Using Comparison Operators` ). + out->write( zcl_demo_abap_aux=>heading( `Searching for Substrings in Strings` ) ). + out->write( |17) Substring Search: Simple Search Using Comparison Operators\n| ). DATA(str_p1) = `cheers`. @@ -861,26 +969,30 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "If the substring is not found, sy-fdpos contains the length of the "searched string. IF str_p1 CS `rs`. - output->display( |CS: The string contains the substring. | + out->write( |CS: The string contains the substring. | && |The offset is { sy-fdpos }.| ). + out->write( |\n| ). ELSE. - output->display( |CS: The string does not contain the substring. | + out->write( |CS: The string does not contain the substring. | && |The length of the string is { sy-fdpos }.| ). + out->write( |\n| ). ENDIF. "NS (contains no string) IF str_p1 NS `abc`. - output->display( |NS: The string does not contain the substring. | + out->write( |NS: The string does not contain the substring. | && |The length of the string is { sy-fdpos }.| ). + out->write( |\n| ). ELSE. - output->display( |NS: The string contains the substring. | + out->write( |NS: The string contains the substring. | && |The offset is { sy-fdpos }.| ). + out->write( |\n| ). ENDIF. ********************************************************************** - output->next_section( `18) Substring Search in Strings ` && - `Using FIND Statements` ). + out->write( zcl_demo_abap_aux=>heading( `18) Substring Search in Strings ` && + `Using FIND Statements` ) ). "The code examples demonstrate different additions. DATA(str_qa) = `She sells seashells by the seashore.`. @@ -890,20 +1002,25 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. FIND `se` IN str_qa. IF sy-subrc = 0. - output->display( `'se' found in the string` ). + out->write( `'se' found in the string` ). ELSE. - output->display( `'se' not found in the string` ). + out->write( `'se' not found in the string` ). ENDIF. + out->write( |\n| ). + "Addition SUBSTRING is optional FIND SUBSTRING `hi` IN str_qa. IF sy-subrc = 0. - output->display( `'hi' Found in the string` ). + out->write( `'hi' Found in the string` ). ELSE. - output->display( `'hi' not found in the string` ). + out->write( `'hi' not found in the string` ). ENDIF. + out->write( |\n| ). + out->write( |\n| ). + "The following examples use the additions MATCH COUNT and MATCH OFFSET "to determine the number of occurrences and offset and for display purposes. @@ -981,27 +1098,42 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. RESULTS DATA(res_q16) IGNORING CASE. - output->display( input = cnt_q1 name = `cnt_q1` ). - output->display( input = off_q2 name = `off_q2` ). - output->display( input = cnt_q3 name = `cnt_q3` ). - output->display( input = off_q4 name = `off_q4` ). - output->display( input = cnt_q5 name = `cnt_q5` ). - output->display( input = off_q6 name = `off_q6` ). - output->display( input = cnt_q7 name = `cnt_q7` ). - output->display( input = off_q8 name = `off_q8` ). - output->display( input = cnt_q9 name = `cnt_q9` ). - output->display( input = off_q10 name = `off_q10` ). - output->display( input = cnt_q11 name = `cnt_q11` ). - output->display( input = off_q12 name = `off_q12` ). - output->display( input = off_q13 name = `off_q13` ). - output->display( input = len_q14 name = `len_q14` ). - output->display( input = res_q15 name = `res_q15` ). - output->display( input = res_q16 name = `res_q16` ). + out->write( data = cnt_q1 name = `cnt_q1` ). + out->write( |\n| ). + out->write( data = off_q2 name = `off_q2` ). + out->write( |\n| ). + out->write( data = cnt_q3 name = `cnt_q3` ). + out->write( |\n| ). + out->write( data = off_q4 name = `off_q4` ). + out->write( |\n| ). + out->write( data = cnt_q5 name = `cnt_q5` ). + out->write( |\n| ). + out->write( data = off_q6 name = `off_q6` ). + out->write( |\n| ). + out->write( data = cnt_q7 name = `cnt_q7` ). + out->write( |\n| ). + out->write( data = off_q8 name = `off_q8` ). + out->write( |\n| ). + out->write( data = cnt_q9 name = `cnt_q9` ). + out->write( |\n| ). + out->write( data = off_q10 name = `off_q10` ). + out->write( |\n| ). + out->write( data = cnt_q11 name = `cnt_q11` ). + out->write( |\n| ). + out->write( data = off_q12 name = `off_q12` ). + out->write( |\n| ). + out->write( data = off_q13 name = `off_q13` ). + out->write( |\n| ). + out->write( data = len_q14 name = `len_q14` ). + out->write( |\n| ). + out->write( data = res_q15 name = `res_q15` ). + out->write( |\n| ). + out->write( data = res_q16 name = `res_q16` ). ********************************************************************** - output->next_section( `19) Substring Search in Internal Tables ` && - `Using FIND ... IN TABLE Statements` ). + out->write( zcl_demo_abap_aux=>heading( `19) Substring Search in Internal Tables ` && + `Using FIND ... IN TABLE Statements` ) ). DATA(str_table_r) = VALUE string_table( ( `aZbzZ` ) ( `cdZze` ) ( `Zzzf` ) ( `ghz` ) ). @@ -1029,16 +1161,20 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. MATCH LENGTH DATA(len_r5) RESPECTING CASE. - output->display( input = res_r1 name = `res_r1` ). - output->display( input = res_r2 name = `res_r2` ). - output->display( input = line_r3 name = `line_r3` ). - output->display( input = off_r4 name = `off_r4` ). - output->display( input = len_r5 name = `len_r5` ). + out->write( data = res_r1 name = `res_r1` ). + out->write( |\n| ). + out->write( data = res_r2 name = `res_r2` ). + out->write( |\n| ). + out->write( data = line_r3 name = `line_r3` ). + out->write( |\n| ). + out->write( data = off_r4 name = `off_r4` ). + out->write( |\n| ). + out->write( data = len_r5 name = `len_r5` ). ********************************************************************** - output->next_section( `20) Substring Search in Strings ` && - `Using the String Function find` ). + out->write( zcl_demo_abap_aux=>heading( `20) Substring Search in Strings ` && + `Using the String Function find` ) ). DATA(str_s) = `Pieces of cakes.`. @@ -1073,29 +1209,41 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. DATA(res_s11) = find( val = str_s sub = `e` off = 5 len = 7 ). DATA(res_s12) = find( val = str_s sub = `e` len = 2 ). - output->display( input = res_s1 name = `res_s1` ). - output->display( input = res_s2 name = `res_s2` ). - output->display( input = res_s3 name = `res_s3` ). - output->display( input = res_s4 name = `res_s4` ). - output->display( input = res_s5 name = `res_s5` ). - output->display( input = res_s6 name = `res_s6` ). - output->display( input = res_s7 name = `res_s7` ). - output->display( input = res_s8 name = `res_s8` ). - output->display( input = res_s9 name = `res_s9` ). - output->display( input = res_s10 name = `res_s10` ). - output->display( input = res_s11 name = `res_s11` ). - output->display( input = res_s12 name = `res_s12` ). + out->write( data = res_s1 name = `res_s1` ). + out->write( |\n| ). + out->write( data = res_s2 name = `res_s2` ). + out->write( |\n| ). + out->write( data = res_s3 name = `res_s3` ). + out->write( |\n| ). + out->write( data = res_s4 name = `res_s4` ). + out->write( |\n| ). + out->write( data = res_s5 name = `res_s5` ). + out->write( |\n| ). + out->write( data = res_s6 name = `res_s6` ). + out->write( |\n| ). + out->write( data = res_s7 name = `res_s7` ). + out->write( |\n| ). + out->write( data = res_s8 name = `res_s8` ). + out->write( |\n| ). + out->write( data = res_s9 name = `res_s9` ). + out->write( |\n| ). + out->write( data = res_s10 name = `res_s10` ). + out->write( |\n| ). + out->write( data = res_s11 name = `res_s11` ). + out->write( |\n| ). + out->write( data = res_s12 name = `res_s12` ). + out->write( |\n| ). "Demonstrating a false range to be searched TRY. DATA(res_s13) = find( val = str_s sub = `e` off = 5 len = 15 ). CATCH cx_sy_range_out_of_bounds. - output->display( `The exception cx_sy_range_out_of_bounds was raised.` ). + out->write( `The exception cx_sy_range_out_of_bounds was raised.` ). ENDTRY. *********************************************************************** - output->next_section( `21) Replacing Substrings in Strings Using REPLACE Statments` ). + out->write( zcl_demo_abap_aux=>heading( `21) Replacing Substrings in Strings Using REPLACE Statments` ) ). DATA(str_t) = `abap ABAP abap`. DATA(str_t1) = str_t. @@ -1105,27 +1253,31 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "replacing the first occurrence by default. REPLACE `ab` IN str_t1 WITH `##`. - output->display( input = str_t1 name = `str_t1` ). + out->write( data = str_t1 name = `str_t1` ). + out->write( |\n| ). DATA(str_t2) = str_t. "Addition SUBSTRING is optional; same effect as the statement above REPLACE SUBSTRING `ab` IN str_t2 WITH `##`. - output->display( input = str_t2 name = `str_t2` ). + out->write( data = str_t2 name = `str_t2` ). + out->write( |\n| ). DATA(str_t3) = str_t. "Addition FIRST OCCURRENCE OF: Explicit specification to replace the "first occurrence; same effect as the statements above REPLACE FIRST OCCURRENCE OF `ab` IN str_t3 WITH `##`. - output->display( input = str_t3 name = `str_t3` ). + out->write( data = str_t3 name = `str_t3` ). + out->write( |\n| ). DATA(str_t4) = str_t. "Addition ALL OCCURRENCES OF: All occurrences are replaced "Note that the replacement is case-sensitive by default. REPLACE ALL OCCURRENCES OF `ab` IN str_t4 WITH `##`. - output->display( input = str_t4 name = `str_t4` ). + out->write( data = str_t4 name = `str_t4` ). + out->write( |\n| ). DATA(str_t5) = str_t. "Further additional options for advanced evaluation options @@ -1135,7 +1287,8 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. IN str_t5 WITH `##` IGNORING CASE. - output->display( input = str_t5 name = `str_t5` ). + out->write( data = str_t5 name = `str_t5` ). + out->write( |\n| ). DATA(str_t6) = str_t. "REPLACEMENT COUNT addition @@ -1144,8 +1297,10 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. REPLACEMENT COUNT DATA(cnt_t7) IGNORING CASE. - output->display( input = str_t6 name = `str_t6` ). - output->display( input = cnt_t7 name = `cnt_t7` ). + out->write( data = str_t6 name = `str_t6` ). + out->write( |\n| ). + out->write( data = cnt_t7 name = `cnt_t7` ). + out->write( |\n| ). DATA(str_t8) = str_t. "REPLACEMENT OFFSET and LENGTH additions @@ -1156,10 +1311,14 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. REPLACEMENT LENGTH DATA(len_t11) IGNORING CASE. - output->display( input = str_t8 name = `str_t8` ). - output->display( input = cnt_t9 name = `cnt_t9` ). - output->display( input = off_t10 name = `off_t10` ). - output->display( input = len_t11 name = `len_t11` ). + out->write( data = str_t8 name = `str_t8` ). + out->write( |\n| ). + out->write( data = cnt_t9 name = `cnt_t9` ). + out->write( |\n| ). + out->write( data = off_t10 name = `off_t10` ). + out->write( |\n| ). + out->write( data = len_t11 name = `len_t11` ). + out->write( |\n| ). DATA(str_t12) = str_t. "SECTION ... OF addition: Replacing within a specified area @@ -1171,10 +1330,14 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. REPLACEMENT LENGTH DATA(len_t15) IGNORING CASE. - output->display( input = str_t12 name = `str_t12` ). - output->display( input = cnt_t13 name = `cnt_t13` ). - output->display( input = off_t14 name = `off_t14` ). - output->display( input = len_t15 name = `len_t15` ). + out->write( data = str_t12 name = `str_t12` ). + out->write( |\n| ). + out->write( data = cnt_t13 name = `cnt_t13` ). + out->write( |\n| ). + out->write( data = off_t14 name = `off_t14` ). + out->write( |\n| ). + out->write( data = len_t15 name = `len_t15` ). + out->write( |\n| ). DATA(str_t16) = str_t. "RESULTS additions with ... @@ -1185,8 +1348,10 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. RESULTS DATA(tab_t17) IGNORING CASE. - output->display( input = str_t16 name = `str_t16` ). - output->display( input = tab_t17 name = `tab_t17` ). + out->write( data = str_t16 name = `str_t16` ). + out->write( |\n| ). + out->write( data = tab_t17 name = `tab_t17` ). + out->write( |\n| ). DATA(str_t18) = str_t. "... FIRST OCCURRENCE OF @@ -1196,12 +1361,13 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. RESULTS DATA(struc_t19) IGNORING CASE. - output->display( input = str_t18 name = `str_t18` ). - output->display( input = struc_t19 name = `struc_t19` ). + out->write( data = str_t18 name = `str_t18` ). + out->write( |\n| ). + out->write( data = struc_t19 name = `struc_t19` ). *********************************************************************** - output->next_section( `21) Position-Based Replacements with REPLACE SECTION ... OF` ). + out->write( zcl_demo_abap_aux=>heading( `21) Position-Based Replacements with REPLACE SECTION ... OF` ) ). DATA(str_u) = `abap ABAP abap`. DATA(str_u1) = str_u. @@ -1209,23 +1375,25 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "OFFSET and LENGTH specified REPLACE SECTION OFFSET 5 LENGTH 4 OF str_u1 WITH `#`. - output->display( input = str_u1 name = `str_u1` ). + out->write( data = str_u1 name = `str_u1` ). + out->write( |\n| ). DATA(str_u2) = str_u. "Only OFFSET specified, LENGTH: up to the end of the string REPLACE SECTION OFFSET 5 OF str_u2 WITH `#`. - output->display( input = str_u2 name = `str_u2` ). + out->write( data = str_u2 name = `str_u2` ). + out->write( |\n| ). DATA(str_u3) = str_u. "Only LENGTH specified, OFFSET: starting from the leftmost position REPLACE SECTION LENGTH 6 OF str_u3 WITH `#`. - output->display( input = str_u3 name = `str_u3` ). + out->write( data = str_u3 name = `str_u3` ). *********************************************************************** - output->next_section( `22) Replacements in Internal Tables with REPLACE ... IN TABLE` ). + out->write( zcl_demo_abap_aux=>heading( `22) Replacements in Internal Tables with REPLACE ... IN TABLE` ) ). DATA(tab_v) = VALUE string_table( ( `aZbzZ` ) ( `cdZze` ) ( `Zzzf` ) ( `ghz` ) ). DATA(tab_v1) = tab_v. @@ -1238,8 +1406,10 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. RESULTS DATA(res_v2) RESPECTING CASE. - output->display( input = tab_v1 name = `tab_v1` ). - output->display( input = res_v2 name = `res_v2` ). + out->write( data = tab_v1 name = `tab_v1` ). + out->write( |\n| ). + out->write( data = res_v2 name = `res_v2` ). + out->write( |\n| ). DATA(tab_v3) = tab_v. "Replacing the first occurrence in a table @@ -1250,8 +1420,10 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. RESULTS DATA(res_v4) RESPECTING CASE. - output->display( input = tab_v3 name = `tab_v3` ). - output->display( input = res_v4 name = `res_v4` ). + out->write( data = tab_v3 name = `tab_v3` ). + out->write( |\n| ). + out->write( data = res_v4 name = `res_v4` ). + out->write( |\n| ). DATA(tab_v5) = tab_v. "Restricting the search range in an internal table @@ -1261,7 +1433,8 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. WITH `#` RESPECTING CASE. - output->display( input = tab_v5 name = `tab_v5` ). + out->write( data = tab_v5 name = `tab_v5` ). + out->write( |\n| ). DATA(tab_v6) = tab_v. "Offsets can be optionally specified (also only the offset of start or end line possible) @@ -1271,11 +1444,11 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. WITH `#` RESPECTING CASE. - output->display( input = tab_v6 name = `tab_v6` ). + out->write( data = tab_v6 name = `tab_v6` ). *********************************************************************** - output->next_section( `23) Replacing Substrings in Strings Using the String Function replace` ). + out->write( zcl_demo_abap_aux=>heading( `23) Replacing Substrings in Strings Using the String Function replace` ) ). DATA(str_w) = `abap ABAP abap`. @@ -1315,21 +1488,30 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "- Result: Value specified for 'with' is appended to the end of the string DATA(str_w_10) = replace( val = str_w with = `#` off = strlen( str_w ) ). - output->display( input = str_w_1 name = `str_w_1` ). - output->display( input = str_w_2 name = `str_w_2` ). - output->display( input = str_w_3 name = `str_w_3` ). - output->display( input = str_w_4 name = `str_w_4` ). - output->display( input = str_w_5 name = `str_w_5` ). - output->display( input = str_w_6 name = `str_w_6` ). - output->display( input = str_w_7 name = `str_w_7` ). - output->display( input = str_w_8 name = `str_w_8` ). - output->display( input = str_w_9 name = `str_w_9` ). - output->display( input = str_w_10 name = `str_w_10` ). + out->write( data = str_w_1 name = `str_w_1` ). + out->write( |\n| ). + out->write( data = str_w_2 name = `str_w_2` ). + out->write( |\n| ). + out->write( data = str_w_3 name = `str_w_3` ). + out->write( |\n| ). + out->write( data = str_w_4 name = `str_w_4` ). + out->write( |\n| ). + out->write( data = str_w_5 name = `str_w_5` ). + out->write( |\n| ). + out->write( data = str_w_6 name = `str_w_6` ). + out->write( |\n| ). + out->write( data = str_w_7 name = `str_w_7` ). + out->write( |\n| ). + out->write( data = str_w_8 name = `str_w_8` ). + out->write( |\n| ). + out->write( data = str_w_9 name = `str_w_9` ). + out->write( |\n| ). + out->write( data = str_w_10 name = `str_w_10` ). *********************************************************************** - output->next_section( `Pattern-Based Searching and Replacing in Strings` ). - output->display( `24) Simple Pattern-Based Searching ` && + out->write( zcl_demo_abap_aux=>heading( `Pattern-Based Searching and Replacing in Strings` ) ). + out->write( `24) Simple Pattern-Based Searching ` && `Using Logical Operators` ). DATA(str_x) = `abc_def_ghi`. @@ -1344,26 +1526,28 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "the offset of the first finding. Otherwise, it contains the length "of the searched string. IF str_x CP `*f#_*`. - output->display( |CP: The string covers the pattern. | + out->write( |CP: The string covers the pattern. | && |The offset is { sy-fdpos }.| ). ELSE. - output->display( |CP: The string does not cover the pattern. | + out->write( |CP: The string does not cover the pattern. | && |The length of the string is { sy-fdpos }.| ). ENDIF. + out->write( |\n| ). + "NP (does not conform to pattern) IF str_x NP `i+`. - output->display( |NP: The string does not cover the pattern. | + out->write( |NP: The string does not cover the pattern. | && |The length of the string is { sy-fdpos }.| ). ELSE. - output->display( |NP: The string covers the pattern. | + out->write( |NP: The string covers the pattern. | && |The offset is { sy-fdpos }.| ). ENDIF. *********************************************************************** - output->next_section( `25) Complex Searching Using ` && - `Regular Expressions` ). + out->write( zcl_demo_abap_aux=>heading( `25) Complex Searching Using ` && + `Regular Expressions` ) ). DATA(str_y) = `Cathy's black cat was fast asleep on the mat. ` && `Later that day, the cat played with Matt.`. @@ -1475,25 +1659,39 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. ENDLOOP. ENDLOOP. - output->display( input = off_y1 name = `off_y1` ). - output->display( input = cnt_y2 name = `cnt_y2` ). - output->display( input = cnt_y3 name = `cnt_y3` ). - output->display( input = str_y4 name = `str_y4` ). - output->display( input = str_y5 name = `str_y5` ). - output->display( input = str_y6 name = `str_y6` ). - output->display( input = subm_y7 name = `subm_y7` ). - output->display( input = subm_y8 name = `subm_y8` ). - output->display( input = cnt_y9 name = `cnt_y9` ). - output->display( input = tab_y10 name = `tab_y10` ). - output->display( input = line_y13 name = `line_y13` ). - output->display( input = off_y14 name = `off_y14` ). - output->display( input = len_y15 name = `len_y15` ). - output->display( input = res_y16 name = `res_y16` ). - output->display( input = tab_y17 name = `tab_y17` ). + out->write( data = off_y1 name = `off_y1` ). + out->write( |\n| ). + out->write( data = cnt_y2 name = `cnt_y2` ). + out->write( |\n| ). + out->write( data = cnt_y3 name = `cnt_y3` ). + out->write( |\n| ). + out->write( data = str_y4 name = `str_y4` ). + out->write( |\n| ). + out->write( data = str_y5 name = `str_y5` ). + out->write( |\n| ). + out->write( data = str_y6 name = `str_y6` ). + out->write( |\n| ). + out->write( data = subm_y7 name = `subm_y7` ). + out->write( |\n| ). + out->write( data = subm_y8 name = `subm_y8` ). + out->write( |\n| ). + out->write( data = cnt_y9 name = `cnt_y9` ). + out->write( |\n| ). + out->write( data = tab_y10 name = `tab_y10` ). + out->write( |\n| ). + out->write( data = line_y13 name = `line_y13` ). + out->write( |\n| ). + out->write( data = off_y14 name = `off_y14` ). + out->write( |\n| ). + out->write( data = len_y15 name = `len_y15` ). + out->write( |\n| ). + out->write( data = res_y16 name = `res_y16` ). + out->write( |\n| ). + out->write( data = tab_y17 name = `tab_y17` ). *********************************************************************** - output->next_section( `26) Replacing Using Regular Expressions` ). + out->write( zcl_demo_abap_aux=>heading( `26) Replacing Using Regular Expressions` ) ). DATA(str_z) = `Cathy's black cat was fast asleep on the mat. ` && `Later that day, the cat played with Matt.`. @@ -1680,39 +1878,67 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. REPLACEMENT COUNT DATA(cnt_z26) IGNORING CASE . - output->display( input = |Original str_z: { str_z }| ). - output->display( input = str_z1 name = `str_z1` ). - output->display( input = str_z2 name = `str_z2` ). - output->display( input = str_z3 name = `str_z3` ). - output->display( input = str_z4 name = `str_z4` ). - output->display( input = str_z5 name = `str_z5` ). - output->display( input = str_z6 name = `str_z6` ). - output->display( input = str_z7 name = `str_z7` ). - output->display( input = str_z8 name = `str_z8` ). - output->display( input = str_z9 name = `str_z9` ). - output->display( input = str_z10 name = `str_z10` ). - output->display( input = str_z11 name = `str_z11` ). - output->display( input = str_z12 name = `str_z12` ). - output->display( input = str_z3 name = `str_z13` ). - output->display( input = |Original str_zb: { str_zb }| ). - output->display( input = str_z15 name = `str_z15` ). - output->display( input = str_z16 name = `str_z16` ). - output->display( input = str_z17 name = `str_z17` ). - output->display( input = str_z18 name = `str_z18` ). - output->display( input = str_z19 name = `str_z19` ). - output->display( input = str_z20 name = `str_z20` ). - output->display( input = str_z21 name = `str_z21` ). - output->display( input = |Original str_zc: { str_zc }| ). - output->display( input = str_z23 name = `str_z23` ). - output->display( input = str_z24 name = `str_z24` ). - output->display( input = str_z25 name = `str_z25` ). - output->display( input = str_zc name = `str_zc` ). - output->display( input = itab_z name = `itab_z` ). - output->display( input = |Number of replacements in itab (cnt_z26): { cnt_z26 }| ). + out->write( data = |Original str_z: { str_z }\n| ). + out->write( |\n| ). + out->write( data = str_z1 name = `str_z1` ). + out->write( |\n| ). + out->write( data = str_z2 name = `str_z2` ). + out->write( |\n| ). + out->write( data = str_z3 name = `str_z3` ). + out->write( |\n| ). + out->write( data = str_z4 name = `str_z4` ). + out->write( |\n| ). + out->write( data = str_z5 name = `str_z5` ). + out->write( |\n| ). + out->write( data = str_z6 name = `str_z6` ). + out->write( |\n| ). + out->write( data = str_z7 name = `str_z7` ). + out->write( |\n| ). + out->write( data = str_z8 name = `str_z8` ). + out->write( |\n| ). + out->write( data = str_z9 name = `str_z9` ). + out->write( |\n| ). + out->write( data = str_z10 name = `str_z10` ). + out->write( |\n| ). + out->write( data = str_z11 name = `str_z11` ). + out->write( |\n| ). + out->write( data = str_z12 name = `str_z12` ). + out->write( |\n| ). + out->write( data = str_z3 name = `str_z13` ). + out->write( |\n| ). + out->write( data = |Original str_zb: { str_zb }\n| ). + out->write( |\n| ). + out->write( data = str_z15 name = `str_z15` ). + out->write( |\n| ). + out->write( data = str_z16 name = `str_z16` ). + out->write( |\n| ). + out->write( data = str_z17 name = `str_z17` ). + out->write( |\n| ). + out->write( data = str_z18 name = `str_z18` ). + out->write( |\n| ). + out->write( data = str_z19 name = `str_z19` ). + out->write( |\n| ). + out->write( data = str_z20 name = `str_z20` ). + out->write( |\n| ). + out->write( data = str_z21 name = `str_z21` ). + out->write( |\n| ). + out->write( data = |Original str_zc: { str_zc }\n| ). + out->write( |\n| ). + out->write( data = str_z23 name = `str_z23` ). + out->write( |\n| ). + out->write( data = str_z24 name = `str_z24` ). + out->write( |\n| ). + out->write( data = str_z25 name = `str_z25` ). + out->write( |\n| ). + out->write( data = str_zc name = `str_zc` ). + out->write( |\n| ). + out->write( data = itab_z name = `itab_z` ). + out->write( |\n| ). + out->write( data = |Number of replacements in itab (cnt_z26): { cnt_z26 }| ). *********************************************************************** - output->next_section( `27) Excursion: System Classes for Regular Expressions` ). + out->write( zcl_demo_abap_aux=>heading( `27) Excursion: System Classes for Regular Expressions` ) ). "Searching for all occurrences DATA(some_string) = `a1 # B2 ? cd . E3`. @@ -1729,13 +1955,15 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. "In the example, result has the type match_result_tab containing the findings. DATA(result1) = matcher_1->find_all( ). - output->display( input = result1 name = `result1` ). + out->write( data = result1 name = `result1` ). + out->write( |\n| ). "You can also use method chaining to save lines of code DATA(result2) = cl_abap_regex=>create_pcre( pattern = `\s\w` "any blank followed by any word character ignore_case = abap_true )->create_matcher( text = some_string )->find_all( ). - output->display( input = result2 name = `result2` ). + out->write( data = result2 name = `result2` ). + out->write( |\n| ). "Retrieving submatches using the 'get_submatch' method DATA str_tab_reg_find TYPE string_table. @@ -1753,7 +1981,7 @@ CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION. ENDDO. ENDIF. - output->display( input = str_tab_reg_find name = `str_tab_reg_find` ). + out->write( data = str_tab_reg_find name = `str_tab_reg_find` ). ENDMETHOD. ENDCLASS. diff --git a/src/zcl_demo_abap_structures.clas.abap b/src/zcl_demo_abap_structures.clas.abap index b95b611..9b42829 100644 --- a/src/zcl_demo_abap_structures.clas.abap +++ b/src/zcl_demo_abap_structures.clas.abap @@ -49,7 +49,7 @@ CLASS zcl_demo_abap_structures DEFINITION CLASS-METHODS: class_constructor. -protected section. + PROTECTED SECTION. PRIVATE SECTION. "Creating structured data types TYPES: "Flat structure @@ -109,14 +109,14 @@ ENDCLASS. -CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. +CLASS zcl_demo_abap_structures IMPLEMENTATION. METHOD class_constructor. initialize_dbtabs( ). fill_deep_structures( ). "Filling demo database tables. - zcl_demo_abap_flight_tables=>fill_dbtabs( ). + zcl_demo_abap_aux=>fill_dbtabs( ). ENDMETHOD. @@ -146,13 +146,11 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. METHOD if_oo_adt_classrun~main. - DATA(output) = NEW zcl_demo_abap_display( out ). - - output->display( `ABAP Cheat Sheet Example: Structures` ). + out->write( |ABAP Cheat Sheet Example: Structures\n\n| ). ********************************************************************** - output->display( `1) Creating structures and structured types` ). + out->write( |1) Creating structures and structured types\n| ). "The following declarations are just included for demonstration purposes "to show how declarations of local structures and structured @@ -215,12 +213,12 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. "Declaring structure inline and populating it using the VALUE operator DATA(struc_inl2) = VALUE lty_struc( num1 = 1 num2 = 2 ). - output->display( `No output for this section. See the code.` ). + out->write( `No output for this section. See the code.` ). ********************************************************************** - output->next_section( `Variants of structures` ). - output->display( `2) Flat structure with default values` ). + out->write( zcl_demo_abap_aux=>heading( `Variants of structures` ) ). + out->write( |2) Flat structure with default values\n\n| ). "Flat structures only contain elementary data types @@ -233,11 +231,11 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. pnum TYPE p LENGTH 8 DECIMALS 2 VALUE '123.45', END OF ls_flat. - output->display( input = ls_flat name = `ls_flat` ). + out->write( data = ls_flat name = `ls_flat` ). ********************************************************************** - output->next_section( `3) Nested structure` ). + out->write( zcl_demo_abap_aux=>heading( `3) Nested structure` ) ). "Nested structures contain at least one structure as component @@ -258,11 +256,11 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. END OF city, END OF ls_nested_address. - output->display( input = ls_nested_address name = `ls_nested_address` ). + out->write( data = ls_nested_address name = `ls_nested_address` ). ********************************************************************** - output->next_section( `4) Deep structure with strings` ). + out->write( zcl_demo_abap_aux=>heading( `4) Deep structure with strings` ) ). "Deep structures contain at least one deep component, for "example, internal tables, strings. @@ -274,11 +272,11 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. city TYPE string VALUE `349875 Botanica`, END OF ls_flat_address. - output->display( input = ls_flat_address name = `ls_flat_address` ). + out->write( data = ls_flat_address name = `ls_flat_address` ). ********************************************************************** - output->next_section( `5) Deep structure with internal table as component` ). + out->write( zcl_demo_abap_aux=>heading( `5) Deep structure with internal table as component` ) ). "Structured type for nested internal table TYPES: BEGIN OF lty_flights, @@ -305,13 +303,12 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. INTO CORRESPONDING FIELDS OF TABLE @ls_flights-lt_flights UP TO 4 ROWS. - output->display( input = ls_flights name = `ls_flights` ). + out->write( data = ls_flights name = `ls_flights` ). ********************************************************************** - output->next_section( `Accessing and populating structures` ). - output->display( `6) Populating structure components` && - ` using the component selector` ). + out->write( zcl_demo_abap_aux=>heading( `Accessing and populating structures` ) ). + out->write( |6) Populating structure components using the component selector\n\n| ). gs_struc-num1 = 1. gs_struc-num2 = 2. @@ -319,12 +316,12 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. gs_struc-char2 = 'bbb'. gs_struc-pnum = '333.33'. - output->display( input = gs_struc name = `gs_struc` ). + out->write( data = gs_struc name = `gs_struc` ). ********************************************************************** - output->next_section( `7) Populating structure components ` && - `using the VALUE operator` ). + out->write( zcl_demo_abap_aux=>heading( `7) Populating structure components ` && + `using the VALUE operator` ) ). "Value assignments by addressing the structure components individually "can be very bulky. Hence, the use of the VALUE operator is @@ -368,14 +365,16 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. cityto = 'New York' airpto = 'JFK' ) ) ). - output->display( input = gs_struc name = `gs_struc` ). - output->display( input = ls_nested_address name = `ls_nested_address` ). - output->display( input = ls_flights name = `ls_flights` ). + out->write( data = gs_struc name = `gs_struc` ). + out->write( |\n| ). + out->write( data = ls_nested_address name = `ls_nested_address` ). + out->write( |\n| ). + out->write( data = ls_flights name = `ls_flights` ). ********************************************************************** - output->next_section( `8) Creating and populating a new structure ` && - `using the VALUE operator` ). + out->write( zcl_demo_abap_aux=>heading( `8) Creating and populating a new structure ` && + `using the VALUE operator` ) ). "In the example below in which a new structure is created by declaring "a variable inline the '#' sign cannot be used before the parentheses @@ -388,12 +387,12 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. char2 = 'hhh' pnum = '555.55' ). - output->display( input = ls_copy name = `ls_copy` ). + out->write( data = ls_copy name = `ls_copy` ). ********************************************************************** - output->next_section( `9) Accessing individual components using the ` && - `component selector` ). + out->write( zcl_demo_abap_aux=>heading( `9) Accessing individual components using the ` && + `component selector` ) ). "Assigning value of individual component to a variable DATA(lv_copy) = gs_struc-num1. @@ -405,14 +404,16 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. "The table line is determined using a table expression. ls_flights-lt_flights[ 1 ]-cityto = 'San Fran'. - output->display( input = lv_copy name = `lv_copy` ). - output->display( input = ls_nested_address-name-first_name name = `ls_nested_address-name-first_name` ). - output->display( input = ls_flights-lt_flights[ 1 ]-cityto name = `ls_flights-lt_flights[ 1 ]-cityto` ). + out->write( data = lv_copy name = `lv_copy` ). + out->write( |\n| ). + out->write( data = ls_nested_address-name-first_name name = `ls_nested_address-name-first_name` ). + out->write( |\n| ). + out->write( data = ls_flights-lt_flights[ 1 ]-cityto name = `ls_flights-lt_flights[ 1 ]-cityto` ). ********************************************************************** - output->next_section( `10) Excursion: Addressing components of a variable` && - ` referring to a structure ` ). + out->write( zcl_demo_abap_aux=>heading( `10) Excursion: Addressing components of a variable` && + ` referring to a structure ` ) ). "Creating a data reference variable. DATA(ref) = NEW gty_struc( ). @@ -426,13 +427,14 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. "The following syntax is also possible but less comfortable. DATA(ref_comp2) = ref->*-char2. - output->display( input = ref_comp1 name = `ref_comp1` ). - output->display( input = ref_comp2 name = `ref_comp2` ). + out->write( data = ref_comp1 name = `ref_comp1` ). + out->write( |\n| ). + out->write( data = ref_comp2 name = `ref_comp2` ). ********************************************************************** - output->next_section( `11) Using structure components for ` && - `data type and data object declarations` ). + out->write( zcl_demo_abap_aux=>heading( `11) Using structure components for ` && + `data type and data object declarations` ) ). TYPES: lty_1 TYPE gty_struc-num1, lty_2 LIKE gs_struc-num2. @@ -440,13 +442,14 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. DATA: lv_num1 TYPE gty_struc-num1 VALUE 123, lv_num2 LIKE gs_struc-num2 VALUE 456. - output->display( input = lv_num1 name = `lv_num1` ). - output->display( input = lv_num2 name = `lv_num2` ). + out->write( data = lv_num1 name = `lv_num1` ). + out->write( |\n| ). + out->write( data = lv_num2 name = `lv_num2` ). ********************************************************************** - output->next_section( `12) Copying content of a structure to another ` && - ` that has the same type using the assignment operator` ). + out->write( zcl_demo_abap_aux=>heading( `12) Copying content of a structure to another ` && + ` that has the same type using the assignment operator` ) ). "Note: In the case below, a MOVE-CORRESPONDING statement as shown "further down would have the same effect: @@ -456,13 +459,13 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. gs_struc_2 = gs_struc. - output->display( input = gs_struc_2 name = `gs_struc_2` ). + out->write( data = gs_struc_2 name = `gs_struc_2` ). ********************************************************************** - output->next_section( `13) Copying content of a structure to another` && + out->write( zcl_demo_abap_aux=>heading( `13) Copying content of a structure to another` && ` that has an incompatible type using` && - ` MOVE-CORRESPONDING statemtns and the CORRESPONDING operator` ). + ` MOVE-CORRESPONDING statemtns and the CORRESPONDING operator` ) ). "Both statements with MOVE-CORRESPONDING and the CORRESPONDING "operator are used to assign identically named components of @@ -486,9 +489,11 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. DATA(gs_struc_diff4) = gs_struc_diff. DATA(gs_struc_diff5) = gs_struc_diff. - output->display( `Original content of structures:` ). - output->display( input = gs_struc name = `gs_struc` ). - output->display( input = gs_struc_diff name = `gs_struc_diff` ). + out->write( |Original content of structures:\n\n| ). + out->write( data = gs_struc name = `gs_struc` ). + out->write( |\n| ). + out->write( data = gs_struc_diff name = `gs_struc_diff` ). + out->write( |\n| ). "Identically named components are moved... "... and the content in nonidentical components of the target @@ -514,28 +519,33 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. gs_struc_diff5 = CORRESPONDING #( BASE ( gs_struc_diff5 ) gs_struc EXCEPT num2 ). - output->display( `Results of statements:` ). - output->display( input = gs_struc_diff name = `gs_struc_diff` ). - output->display( input = gs_struc_diff2 name = `gs_struc_diff2` ). - output->display( input = gs_struc_diff3 name = `gs_struc_diff3` ). - output->display( input = gs_struc_diff4 name = `gs_struc_diff4` ). - output->display( input = gs_struc_diff5 name = `gs_struc_diff5` ). + out->write( |Results of statements:\n\n| ). + out->write( data = gs_struc_diff name = `gs_struc_diff` ). + out->write( |\n| ). + out->write( data = gs_struc_diff2 name = `gs_struc_diff2` ). + out->write( |\n| ). + out->write( data = gs_struc_diff3 name = `gs_struc_diff3` ). + out->write( |\n| ). + out->write( data = gs_struc_diff4 name = `gs_struc_diff4` ). + out->write( |\n| ). + out->write( data = gs_struc_diff5 name = `gs_struc_diff5` ). ********************************************************************** - output->next_section( `14) Copying content of a deep ` && - `structure to another` ). - output->display( 'Original content of deep structures:' ). + out->write( zcl_demo_abap_aux=>heading( `14) Copying content of a deep ` && + `structure to another` ) ). + out->write( |Original content of deep structures:\n\n| ). "Note: The example purposely uses non-fitting components "to emphasize conversion and assignment rules. - output->display( input = gs_deep1 name = `gs_deep1` ). - output->display( input = gs_deep2 name = `gs_deep2` ). + out->write( data = gs_deep1 name = `gs_deep1` ). + out->write( |\n| ). + out->write( data = gs_deep2 name = `gs_deep2` ). ********************************************************************** - output->next_section( `15) MOVE-CORRESPONDING without additions` ). + out->write( zcl_demo_abap_aux=>heading( `15) MOVE-CORRESPONDING without additions` ) ). "Notes on the result: "- Existing content of identically named components is replaced. @@ -553,14 +563,14 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. MOVE-CORRESPONDING gs_deep1 TO gs_deep2. - output->display( input = gs_deep2 name = `gs_deep2` ). + out->write( data = gs_deep2 name = `gs_deep2` ). fill_deep_structures( ). ********************************************************************** - output->next_section( `16) MOVE-CORRESPONDING with the ` && - `EXPANDING NESTED TABLES addition` ). + out->write( zcl_demo_abap_aux=>heading( `16) MOVE-CORRESPONDING with the ` && + `EXPANDING NESTED TABLES addition` ) ). "Notes on the result: "- Existing content of identically named components is replaced. @@ -575,14 +585,14 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. MOVE-CORRESPONDING gs_deep1 TO gs_deep2 EXPANDING NESTED TABLES. - output->display( input = gs_deep2 name = `gs_deep2` ). + out->write( data = gs_deep2 name = `gs_deep2` ). fill_deep_structures( ). ********************************************************************** - output->next_section( `17) MOVE-CORRESPONDING with the` && - ` KEEPING TARGET LINES addition` ). + out->write( zcl_demo_abap_aux=>heading( `17) MOVE-CORRESPONDING with the` && + ` KEEPING TARGET LINES addition` ) ). "Notes on the result: "- Existing content of identically named components is replaced. @@ -599,14 +609,14 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. MOVE-CORRESPONDING gs_deep1 TO gs_deep2 KEEPING TARGET LINES. - output->display( input = gs_deep2 name = `gs_deep2` ). + out->write( data = gs_deep2 name = `gs_deep2` ). fill_deep_structures( ). ********************************************************************** - output->next_section( `18) MOVE-CORRESPONDING with the ` && - `EXPANDING NESTED TABLES KEEPING TARGET LINES addition` ). + out->write( zcl_demo_abap_aux=>heading( `18) MOVE-CORRESPONDING with the ` && + `EXPANDING NESTED TABLES KEEPING TARGET LINES addition` ) ). "Notes on the result: "- Existing content of identically named components is replaced. @@ -624,13 +634,13 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. MOVE-CORRESPONDING gs_deep1 TO gs_deep2 EXPANDING NESTED TABLES KEEPING TARGET LINES. - output->display( input = gs_deep2 name = `gs_deep2` ). + out->write( data = gs_deep2 name = `gs_deep2` ). fill_deep_structures( ). ********************************************************************** - output->next_section( `19) CORRESPONDING operator without additions` ). + out->write( zcl_demo_abap_aux=>heading( `19) CORRESPONDING operator without additions` ) ). "Notes on the result: "- Existing content of identically named components is replaced. @@ -645,14 +655,14 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. gs_deep2 = CORRESPONDING #( gs_deep1 ). - output->display( input = gs_deep2 name = `gs_deep2` ). + out->write( data = gs_deep2 name = `gs_deep2` ). fill_deep_structures( ). ********************************************************************** - output->next_section( `20) CORRESPONDING operator with the` && - ` DEEP addition` ). + out->write( zcl_demo_abap_aux=>heading( `20) CORRESPONDING operator with the` && + ` DEEP addition` ) ). "Notes on the result: "- Existing content of identically named components is replaced. @@ -667,14 +677,14 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. gs_deep2 = CORRESPONDING #( DEEP gs_deep1 ). - output->display( input = gs_deep2 name = `gs_deep2` ). + out->write( data = gs_deep2 name = `gs_deep2` ). fill_deep_structures( ). ********************************************************************** - output->next_section( `21) CORRESPONDING operator with the` && - ` BASE addition` ). + out->write( zcl_demo_abap_aux=>heading( `21) CORRESPONDING operator with the` && + ` BASE addition` ) ). "Notes on the result: "- Existing content of identically named components is replaced. @@ -691,14 +701,14 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. gs_deep2 = CORRESPONDING #( BASE ( gs_deep2 ) gs_deep1 ). - output->display( input = gs_deep2 name = `gs_deep2` ). + out->write( data = gs_deep2 name = `gs_deep2` ). fill_deep_structures( ). ********************************************************************** - output->next_section( `22) CORRESPONDING operator with the ` && - `DEEP BASE addition` ). + out->write( zcl_demo_abap_aux=>heading( `22) CORRESPONDING operator with the ` && + `DEEP BASE addition` ) ). "Notes on the result: "- Existing content of identically named components is replaced. @@ -714,14 +724,14 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. gs_deep2 = CORRESPONDING #( DEEP BASE ( gs_deep2 ) gs_deep1 ). - output->display( input = gs_deep2 name = `gs_deep2` ). + out->write( data = gs_deep2 name = `gs_deep2` ). fill_deep_structures( ). ********************************************************************** - output->next_section( `23) CORRESPONDING operator with the ` && - `APPENDING addition` ). + out->write( zcl_demo_abap_aux=>heading( `23) CORRESPONDING operator with the ` && + `APPENDING addition` ) ). "Notes on the result: "- Existing content of identically named components is replaced. @@ -738,14 +748,14 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. gs_deep2 = CORRESPONDING #( APPENDING ( gs_deep2 ) gs_deep1 ). - output->display( input = gs_deep2 name = `gs_deep2` ). + out->write( data = gs_deep2 name = `gs_deep2` ). fill_deep_structures( ). ********************************************************************** - output->next_section( `24) CORRESPONDING operator with the ` && - `DEEP APPENDING addition` ). + out->write( zcl_demo_abap_aux=>heading( `24) CORRESPONDING operator with the ` && + `DEEP APPENDING addition` ) ). "Notes on the result: "- Existing content of identically named components is replaced. @@ -763,29 +773,29 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. gs_deep2 = CORRESPONDING #( DEEP APPENDING ( gs_deep2 ) gs_deep1 ). - output->display( input = gs_deep2 name = `gs_deep2` ). + out->write( data = gs_deep2 name = `gs_deep2` ). ********************************************************************** - output->next_section( `25) Clearing individual components of a ` && - `structure and the complete structure` ). + out->write( zcl_demo_abap_aux=>heading( `25) Clearing individual components of a ` && + `structure and the complete structure` ) ). "Clearing individual component CLEAR gs_struc-char1. - output->display( input = gs_struc name = `gs_struc` ). + out->write( data = gs_struc name = `gs_struc` ). + out->write( |\n| ). "Clearing the whole structure CLEAR gs_struc. - output->display( input = gs_struc name = `gs_struc` ). + out->write( data = gs_struc name = `gs_struc` ). ********************************************************************** - output->next_section( `Processing structures` ). - output->display( `Reading a row from a database table into a ` && - `structure ...` ). - output->display( `26) ... that has a compatible type` ). + out->write( zcl_demo_abap_aux=>heading( `Processing structures` ) ). + out->write( |Reading a row from a database table into a structure ...\n\n| ). + out->write( |26) ... that has a compatible type\n\n| ). "The first entry that is found according to the WHERE condition is "returned. Instead of creating a structure having a compatible type, @@ -803,12 +813,13 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. WHERE carrid = 'LH' AND connid = '0400' INTO @DATA(ls_flsch2). - output->display( input = ls_flsch1 name = `ls_flsch1` ). - output->display( input = ls_flsch2 name = `ls_flsch2` ). + out->write( data = ls_flsch1 name = `ls_flsch1` ). + out->write( |\n| ). + out->write( data = ls_flsch2 name = `ls_flsch2` ). ********************************************************************** - output->next_section( `27) ... that has a different type` ). + out->write( zcl_demo_abap_aux=>heading( `27) ... that has a different type` ) ). "Creating structure having a different type. DATA: BEGIN OF ls_fli_diff, @@ -826,12 +837,12 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. WHERE carrid = 'JL' AND connid = '0408' INTO CORRESPONDING FIELDS OF @ls_fli_diff. - output->display( input = ls_fli_diff name = `ls_fli_diff` ). + out->write( data = ls_fli_diff name = `ls_fli_diff` ). ********************************************************************** - output->next_section( `Reading a line from an internal table into a structure ...` ). - output->display( `28) ... using a SELECT statement` ). + out->write( zcl_demo_abap_aux=>heading( `Reading a line from an internal table into a structure ...` ) ). + out->write( |28) ... using a SELECT statement\n\n| ). "Creating and filling an internal table to be read from DATA itab TYPE TABLE OF zdemo_abap_flsch WITH EMPTY KEY. @@ -847,11 +858,11 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. WHERE carrid = 'LH' INTO @DATA(ls_select_itab). - output->display( input = ls_select_itab name = `ls_select_itab` ). + out->write( data = ls_select_itab name = `ls_select_itab` ). ********************************************************************** - output->next_section( `29) ... using a READ TABLE statement` ). + out->write( zcl_demo_abap_aux=>heading( `29) ... using a READ TABLE statement` ) ). "The example shows the reading of one line into a work area, field "symbol and a data reference variable, all representing structured @@ -867,24 +878,26 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. "Reading into a data reference variable READ TABLE itab REFERENCE INTO DATA(dref) INDEX 3. - output->display( input = ls_read_table name = `ls_read_table` ). - output->display( input = name = `` ). - output->display( input = dref->* name = `dref->*` ). + out->write( data = ls_read_table name = `ls_read_table` ). + out->write( |\n| ). + out->write( data = name = `` ). + out->write( |\n| ). + out->write( data = dref->* name = `dref->*` ). ********************************************************************** - output->next_section( `30) ... using a table expression` ). + out->write( zcl_demo_abap_aux=>heading( `30) ... using a table expression` ) ). "The line number, that is, the index, is specified in square "brackets. DATA(ls_table_exp) = itab[ 3 ]. - output->display( input = ls_table_exp name = `ls_table_exp` ). + out->write( data = ls_table_exp name = `ls_table_exp` ). ********************************************************************** - output->next_section( `Sequentially reading ...` ). - output->display( `31) ... a row from a database table into a structure` ). + out->write( zcl_demo_abap_aux=>heading( `Sequentially reading ...` ) ). + out->write( |31) ... a row from a database table into a structure\n\n| ). "In the given simple example, the line that is found and returned "in a structure, that is declared inline, is simply added to an @@ -899,11 +912,11 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. ENDIF. ENDSELECT. - output->display( input = itab name = `itab` ). + out->write( data = itab name = `itab` ). ********************************************************************** - output->next_section( `32) ... a line from an internal table into a structure` ). + out->write( zcl_demo_abap_aux=>heading( `32) ... a line from an internal table into a structure` ) ). "The given example covers the reading of a line into a field symbol. "Within the loop, a modification is carried out on a component @@ -913,12 +926,12 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. -carrid = 'XY'. ENDLOOP. - output->display( input = itab name = `itab` ). + out->write( data = itab name = `itab` ). ********************************************************************** - output->next_section( `33) Inserting a single row ` && - `into a database table from a structure` ). + out->write( zcl_demo_abap_aux=>heading( `33) Inserting a single row ` && + `into a database table from a structure` ) ). "The statements in the given example can be considered as "alternatives. The third statement demonstrates that the structure @@ -952,12 +965,12 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. num2 = 7 ) ). select_from_dbtab( ). - output->display( input = gt_tab name = `gt_tab` ). + out->write( data = gt_tab name = `gt_tab` ). ********************************************************************** - output->next_section( `34) Updating a single row ` && - `in a database table from a structure` ). + out->write( zcl_demo_abap_aux=>heading( `34) Updating a single row ` && + `in a database table from a structure` ) ). ls_struc_db = VALUE #( key_field = 2 char1 = 'GGG' @@ -974,13 +987,13 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. num2 = 11 ) ). select_from_dbtab( ). - output->display( input = gt_tab name = `gt_tab` ). + out->write( data = gt_tab name = `gt_tab` ). ********************************************************************** - output->next_section( `35) Updating a single row ` && + out->write( zcl_demo_abap_aux=>heading( `35) Updating a single row ` && `in a database table from a structure without overwriting specific ` && - `components` ). + `components` ) ). "If you want to update a database table row from a structure by "specifying components to be changed without overwriting other @@ -997,12 +1010,12 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. UPDATE zdemo_abap_tab1 FROM @( VALUE #( BASE wa char2 = '###' ) ). select_from_dbtab( ). - output->display( input = gt_tab name = `gt_tab` ). + out->write( data = gt_tab name = `gt_tab` ). ********************************************************************** - output->next_section( `36) Updating or creating a single` && - ` row in a database table from a structure using MODIFY` ). + out->write( zcl_demo_abap_aux=>heading( `36) Updating or creating a single` && + ` row in a database table from a structure using MODIFY` ) ). "You can update or create an individual row in a database table "from a structure using ABAP SQL statements with MODIFY. If a @@ -1039,12 +1052,12 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. num2 = 17 ) ). select_from_dbtab( ). - output->display( input = gt_tab name = `gt_tab` ). + out->write( data = gt_tab name = `gt_tab` ). ********************************************************************** - output->next_section( `36) Adding rows to and updating single rows` && - ` in an internal table from a structure` ). + out->write( zcl_demo_abap_aux=>heading( `36) Adding rows to and updating single rows` && + ` in an internal table from a structure` ) ). "INSERT and MODIFY are ABAP statements in this context, not ABAP SQL "statements. Both INSERT and APPEND add one line (or more) to an @@ -1094,11 +1107,11 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. num1 = 28 num2 = 29 ). - output->display( input = gt_tab name = `gt_tab` ). + out->write( data = gt_tab name = `gt_tab` ). ********************************************************************** - output->next_section( `37) Including structures` ). + out->write( zcl_demo_abap_aux=>heading( `37) Including structures` ) ). "The example shows the inclusion of structured types and data "objects in another structure. First, three structured types as @@ -1146,8 +1159,7 @@ CLASS ZCL_DEMO_ABAP_STRUCTURES IMPLEMENTATION. address-zipcode_city = `349875`. address-name_city = `Botanica`. - output->display( input = address name = `address` ). - + out->write( data = address name = `address` ). ENDMETHOD. diff --git a/src/zcl_demo_abap_unit_test.clas.abap b/src/zcl_demo_abap_unit_test.clas.abap index 543fb10..945e959 100644 --- a/src/zcl_demo_abap_unit_test.clas.abap +++ b/src/zcl_demo_abap_unit_test.clas.abap @@ -57,630 +57,622 @@ CLASS zcl_demo_abap_unit_test DEFINITION PUBLIC CREATE PUBLIC. -PUBLIC SECTION. + PUBLIC SECTION. - INTERFACES: if_oo_adt_classrun. + INTERFACES: if_oo_adt_classrun. - CLASS-METHODS: class_constructor. + CLASS-METHODS: class_constructor. - "Optional parameter for the instance constructor for the purpose of - "constructor injection - METHODS constructor - IMPORTING iref_data_prov TYPE REF TO zdemo_abap_get_data_itf OPTIONAL. + "Optional parameter for the instance constructor for the purpose of + "constructor injection + METHODS constructor + IMPORTING iref_data_prov TYPE REF TO zdemo_abap_get_data_itf OPTIONAL. -PROTECTED SECTION. + PROTECTED SECTION. - TYPES carr_tab TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY. + TYPES carr_tab TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY. - METHODS: select_flight_data IMPORTING carrier TYPE zdemo_abap_fli-carrid - RETURNING VALUE(flight_data) TYPE carr_tab. + METHODS: select_flight_data IMPORTING carrier TYPE zdemo_abap_fli-carrid + RETURNING VALUE(flight_data) TYPE carr_tab. -PRIVATE SECTION. + PRIVATE SECTION. - TYPES: int_tab_so TYPE SORTED TABLE OF i WITH UNIQUE KEY table_line, - int_tab_st TYPE STANDARD TABLE OF i WITH EMPTY KEY, - occ_rate TYPE p LENGTH 4 DECIMALS 2, + TYPES: int_tab_so TYPE SORTED TABLE OF i WITH UNIQUE KEY table_line, + int_tab_st TYPE STANDARD TABLE OF i WITH EMPTY KEY, + occ_rate TYPE p LENGTH 4 DECIMALS 2, - BEGIN OF nums_struc, - num1 TYPE i, - num2 TYPE i, - END OF nums_struc, + BEGIN OF nums_struc, + num1 TYPE i, + num2 TYPE i, + END OF nums_struc, - nums_tab TYPE TABLE OF nums_struc WITH EMPTY KEY. + nums_tab TYPE TABLE OF nums_struc WITH EMPTY KEY. - DATA: seats_table TYPE zdemo_abap_get_data_itf=>carr_tab, - flight_tab TYPE TABLE OF zdemo_abap_fli, + DATA: seats_table TYPE zdemo_abap_get_data_itf=>carr_tab, + flight_tab TYPE TABLE OF zdemo_abap_fli, - "Reference variable for back door injection - "Note: In the example, it is a local interface declared in the - "Local Types tab (the CCIMP include). To make the type known to - "the global class, see the Class-relevant Local Types tab (the CCDEF include). - data_provider_local_itf TYPE REF TO lif_get_data, + "Reference variable for back door injection + "Note: In the example, it is a local interface declared in the + "Local Types tab (the CCIMP include). To make the type known to + "the global class, see the Class-relevant Local Types tab (the CCDEF include). + data_provider_local_itf TYPE REF TO lif_get_data, - "Reference variable for constructor injection - "In the example, the type refers to a global interface. - data_provider_global_itf TYPE REF TO zdemo_abap_get_data_itf, + "Reference variable for constructor injection + "In the example, the type refers to a global interface. + data_provider_global_itf TYPE REF TO zdemo_abap_get_data_itf, - "For demonstrating setter injection - data_provider_setter_inj TYPE REF TO zdemo_abap_get_data_itf, + "For demonstrating setter injection + data_provider_setter_inj TYPE REF TO zdemo_abap_get_data_itf, - "For demonstrating parameter injection - data_provider_param_inj TYPE REF TO zdemo_abap_get_data_itf.. + "For demonstrating parameter injection + data_provider_param_inj TYPE REF TO zdemo_abap_get_data_itf.. - METHODS: - "Calculates the sum of two numbers - "This method demonstrates the use of the setup and teardown methods in the test class. - get_sum IMPORTING key TYPE zdemo_abap_tab1-key_field - char TYPE zdemo_abap_tab1-char1 - RETURNING VALUE(sum) TYPE i, + METHODS: + "Calculates the sum of two numbers + "This method demonstrates the use of the setup and teardown methods in the test class. + get_sum IMPORTING key TYPE zdemo_abap_tab1-key_field + char TYPE zdemo_abap_tab1-char1 + RETURNING VALUE(sum) TYPE i, - "Calculates the common divisors and the greatest common divisor of two numbers - get_common_div_and_gcd IMPORTING a TYPE i - b TYPE i - EXPORTING common_divisors TYPE int_tab_so - gcd TYPE i, + "Calculates the common divisors and the greatest common divisor of two numbers + get_common_div_and_gcd IMPORTING a TYPE i + b TYPE i + EXPORTING common_divisors TYPE int_tab_so + gcd TYPE i, - "Calculates the digit sum of a number - get_digit_sum IMPORTING num TYPE i - RETURNING VALUE(digit_sum) TYPE i, + "Calculates the digit sum of a number + get_digit_sum IMPORTING num TYPE i + RETURNING VALUE(digit_sum) TYPE i, - "Multiple methods that all do the same (they calculate the occupancy rate of flights) - "but serve different demonstration purposes for the ABAP unit tests in the example. - "The method implementations involve a depended-on component (DOC). In this case, - "it is a database access. - "The methods are intentionally implemented in a similar way. Therefore, almost - "all of the following methods will display the same output in the console when the - "class is executed using F9. + "Multiple methods that all do the same (they calculate the occupancy rate of flights) + "but serve different demonstration purposes for the ABAP unit tests in the example. + "The method implementations involve a depended-on component (DOC). In this case, + "it is a database access. + "The methods are intentionally implemented in a similar way. Therefore, almost + "all of the following methods will display the same output in the console when the + "class is executed using F9. - "Method to demonstrate test double injection using inheritance and method redefinition - get_occ_rate_using_meth IMPORTING carrier_id TYPE zdemo_abap_fli-carrid - RETURNING VALUE(occupancy_rate) TYPE occ_rate, + "Method to demonstrate test double injection using inheritance and method redefinition + get_occ_rate_using_meth IMPORTING carrier_id TYPE zdemo_abap_fli-carrid + RETURNING VALUE(occupancy_rate) TYPE occ_rate, - "Method to demonstrate test double injection using test seams - get_occ_rate_test_seam IMPORTING carrier_id TYPE zdemo_abap_fli-carrid - EXPORTING occupancy_rate TYPE occ_rate - num1 TYPE i - num2 TYPE i, + "Method to demonstrate test double injection using test seams + get_occ_rate_test_seam IMPORTING carrier_id TYPE zdemo_abap_fli-carrid + EXPORTING occupancy_rate TYPE occ_rate + num1 TYPE i + num2 TYPE i, - "Method to demonstrate test double injection using back door injection and a local interface - get_occ_rate_local_itf IMPORTING carrier_id TYPE zdemo_abap_fli-carrid - RETURNING VALUE(occupancy_rate) TYPE occ_rate, + "Method to demonstrate test double injection using back door injection and a local interface + get_occ_rate_local_itf IMPORTING carrier_id TYPE zdemo_abap_fli-carrid + RETURNING VALUE(occupancy_rate) TYPE occ_rate, - "Method to demonstrate test double injection using constructor injection and a global interface - get_occ_rate_global_itf IMPORTING carrier_id TYPE zdemo_abap_fli-carrid - RETURNING VALUE(occupancy_rate) TYPE occ_rate, + "Method to demonstrate test double injection using constructor injection and a global interface + get_occ_rate_global_itf IMPORTING carrier_id TYPE zdemo_abap_fli-carrid + RETURNING VALUE(occupancy_rate) TYPE occ_rate, - "Method to demonstrate test double injection using setter injection and a global interface - get_occ_rate_setter_inj IMPORTING carrier_id TYPE zdemo_abap_fli-carrid - RETURNING VALUE(occupancy_rate) TYPE occ_rate, + "Method to demonstrate test double injection using setter injection and a global interface + get_occ_rate_setter_inj IMPORTING carrier_id TYPE zdemo_abap_fli-carrid + RETURNING VALUE(occupancy_rate) TYPE occ_rate, - "Method for setter injection - setter_meth IMPORTING data_prov TYPE REF TO zdemo_abap_get_data_itf, + "Method for setter injection + setter_meth IMPORTING data_prov TYPE REF TO zdemo_abap_get_data_itf, - "Method to demonstrate test double injection using parameter injection and a global interface - "An optional parameter is specified for passing the test double if the method is tested. - get_occ_rate_param_inj IMPORTING carrier_id TYPE zdemo_abap_fli-carrid - data_prov TYPE REF TO zdemo_abap_get_data_itf OPTIONAL - RETURNING VALUE(occupancy_rate) TYPE occ_rate. + "Method to demonstrate test double injection using parameter injection and a global interface + "An optional parameter is specified for passing the test double if the method is tested. + get_occ_rate_param_inj IMPORTING carrier_id TYPE zdemo_abap_fli-carrid + data_prov TYPE REF TO zdemo_abap_get_data_itf OPTIONAL + RETURNING VALUE(occupancy_rate) TYPE occ_rate. ENDCLASS. -CLASS ZCL_DEMO_ABAP_UNIT_TEST IMPLEMENTATION. +CLASS zcl_demo_abap_unit_test IMPLEMENTATION. -METHOD class_constructor. - "Filling demo database tables. - zcl_demo_abap_flight_tables=>fill_dbtabs( ). + METHOD class_constructor. + "Filling demo database tables. + zcl_demo_abap_aux=>fill_dbtabs( ). - "Preparing a demo database table for this example (get_sum method) - DELETE FROM zdemo_abap_tab1. - INSERT zdemo_abap_tab1 FROM @( - VALUE #( key_field = 1 char1 = 'aaa' char2 = 'bbb' num1 = 25 num2 = 75 ) ). -ENDMETHOD. + "Preparing a demo database table for this example (get_sum method) + DELETE FROM zdemo_abap_tab1. + INSERT zdemo_abap_tab1 FROM @( + VALUE #( key_field = 1 char1 = 'aaa' char2 = 'bbb' num1 = 25 num2 = 75 ) ). + ENDMETHOD. -METHOD constructor. + METHOD constructor. - "For demonstrating the back door injection - data_provider_local_itf = NEW lcl_data_prov_local_itf( ). + "For demonstrating the back door injection + data_provider_local_itf = NEW lcl_data_prov_local_itf( ). - "For demonstrating the constructor injection - IF iref_data_prov IS BOUND. - "Note: The parameter is only bound when you run the unit test. - "When you run the unit test and you debug, you will see that iref_data_prov - "has a type reference to LTD_TEST_DATA_GLOBAL_INTF. + "For demonstrating the constructor injection + IF iref_data_prov IS BOUND. + "Note: The parameter is only bound when you run the unit test. + "When you run the unit test and you debug, you will see that iref_data_prov + "has a type reference to LTD_TEST_DATA_GLOBAL_INTF. - data_provider_global_itf = iref_data_prov. + data_provider_global_itf = iref_data_prov. - ELSE. + ELSE. - data_provider_global_itf = NEW lcl_data_prov_glo_itf( ). + data_provider_global_itf = NEW lcl_data_prov_glo_itf( ). - ENDIF. - - "Object creation for the method call in the get_occ_rate_setter_inj method - data_provider_setter_inj = NEW lcl_data_prov_glo_itf( ). - -ENDMETHOD. - - -METHOD get_common_div_and_gcd. - "Calculates the common divisors and the greatest common divisor of two numbers - - CLEAR: common_divisors, gcd. - - CHECK a >= 1. - CHECK b >= 1. - - IF a >= b. - DATA(greater_num) = a. - DATA(lower_num) = b. - ELSE. - greater_num = b. - lower_num = a. - ENDIF. - - "Getting common divisors - DATA(div) = 1. - - WHILE div <= lower_num. - IF lower_num MOD div = 0. - DATA(divisor) = lower_num / div. - INSERT divisor INTO TABLE common_divisors. ENDIF. - div += 1. - ENDWHILE. + "Object creation for the method call in the get_occ_rate_setter_inj method + data_provider_setter_inj = NEW lcl_data_prov_glo_itf( ). - LOOP AT common_divisors ASSIGNING FIELD-SYMBOL(). + ENDMETHOD. - IF greater_num MOD <> 0. - DELETE common_divisors WHERE table_line = . + + METHOD get_common_div_and_gcd. + "Calculates the common divisors and the greatest common divisor of two numbers + + CLEAR: common_divisors, gcd. + + CHECK a >= 1. + CHECK b >= 1. + + IF a >= b. + DATA(greater_num) = a. + DATA(lower_num) = b. + ELSE. + greater_num = b. + lower_num = a. ENDIF. - ENDLOOP. + "Getting common divisors + DATA(div) = 1. - "Extracting the greatest common divisor from the list of common divisors - gcd = common_divisors[ lines( common_divisors ) ]. + WHILE div <= lower_num. + IF lower_num MOD div = 0. + DATA(divisor) = lower_num / div. + INSERT divisor INTO TABLE common_divisors. + ENDIF. -ENDMETHOD. + div += 1. + ENDWHILE. + + LOOP AT common_divisors ASSIGNING FIELD-SYMBOL(). + + IF greater_num MOD <> 0. + DELETE common_divisors WHERE table_line = . + ENDIF. + + ENDLOOP. + + "Extracting the greatest common divisor from the list of common divisors + gcd = common_divisors[ lines( common_divisors ) ]. + + ENDMETHOD. -METHOD get_digit_sum. - "Calculates the digit sum of a number + METHOD get_digit_sum. + "Calculates the digit sum of a number - CLEAR digit_sum. + CLEAR digit_sum. - CHECK num >= 0. + CHECK num >= 0. - DATA(converted_int) = CONV string( num ). - DATA(len) = strlen( converted_int ). + DATA(converted_int) = CONV string( num ). + DATA(len) = strlen( converted_int ). - DO len TIMES. - DATA(idx) = sy-index - 1. - digit_sum = digit_sum + converted_int+idx(1). - ENDDO. + DO len TIMES. + DATA(idx) = sy-index - 1. + digit_sum = digit_sum + converted_int+idx(1). + ENDDO. -ENDMETHOD. + ENDMETHOD. -METHOD get_occ_rate_global_itf. + METHOD get_occ_rate_global_itf. "Method to demonstrate test double injection using constructor injection "and a global interface - DATA total_seatsmax_global_itf TYPE i. - DATA total_seatsocc_global_itf TYPE i. + DATA total_seatsmax_global_itf TYPE i. + DATA total_seatsocc_global_itf TYPE i. - "Assumption: The original code in this method was as follows (the line commented out). - "It was identified as DOC (reading data from a database table). + "Assumption: The original code in this method was as follows (the line commented out). + "It was identified as DOC (reading data from a database table). - "DATA(flight_data) = select_flight_data( carrier = carrier_id ). + "DATA(flight_data) = select_flight_data( carrier = carrier_id ). - "Instead of a method call like above and for a proper unit testing, a global interface - "is provided. - "In the example, an interface method is implemented in a local class in the local types - "tab (CCIMP include): lcl_data_prov_glo_itf + "Instead of a method call like above and for a proper unit testing, a global interface + "is provided. + "In the example, an interface method is implemented in a local class in the local types + "tab (CCIMP include): lcl_data_prov_glo_itf - "When the class is executed using F9, the object used here refers to type lcl_data_prov_glo_itf. - "When the unit test is executed, the object used here refers to type ltd_test_data_global_intf, - "i.e. the local test double is injected. - DATA(flight_data) = data_provider_global_itf->select_flight_data( carrier = carrier_id ). + "When the class is executed using F9, the object used here refers to type lcl_data_prov_glo_itf. + "When the unit test is executed, the object used here refers to type ltd_test_data_global_intf, + "i.e. the local test double is injected. + DATA(flight_data) = data_provider_global_itf->select_flight_data( carrier = carrier_id ). - LOOP AT flight_data ASSIGNING FIELD-SYMBOL(). + LOOP AT flight_data ASSIGNING FIELD-SYMBOL(). - total_seatsmax_global_itf = total_seatsmax_global_itf + -seatsmax. - total_seatsocc_global_itf = total_seatsocc_global_itf + -seatsocc. + total_seatsmax_global_itf = total_seatsmax_global_itf + -seatsmax. + total_seatsocc_global_itf = total_seatsocc_global_itf + -seatsocc. - ENDLOOP. + ENDLOOP. - occupancy_rate = total_seatsocc_global_itf / total_seatsmax_global_itf * 100. + occupancy_rate = total_seatsocc_global_itf / total_seatsmax_global_itf * 100. -ENDMETHOD. + ENDMETHOD. -METHOD get_occ_rate_local_itf. - "Method to demonstrate test double injection using back door - "injection and a local interface + METHOD get_occ_rate_local_itf. + "Method to demonstrate test double injection using back door + "injection and a local interface - DATA total_seatsmax_local_itf TYPE i. - DATA total_seatsocc_local_itf TYPE i. + DATA total_seatsmax_local_itf TYPE i. + DATA total_seatsocc_local_itf TYPE i. - "Assumption: The original code in this method was as follows (the line commented out). - "It was identified as DOC (reading data from a database table). + "Assumption: The original code in this method was as follows (the line commented out). + "It was identified as DOC (reading data from a database table). - "DATA(flight_data) = select_flight_data( carrier = carrier_id ). + "DATA(flight_data) = select_flight_data( carrier = carrier_id ). - "Instead of a method call like above and for a proper unit testing - a global interface - "is not available - a local interface is created, and - "an interface method is implemented. In this example, the local interface is - "created in the local types tab (CCIMP include): lif_get_data - "A local class (lcl_data_prov_local_itf) is also created in the CCIMP include. It - "implements the local interface. + "Instead of a method call like above and for a proper unit testing - a global interface + "is not available - a local interface is created, and + "an interface method is implemented. In this example, the local interface is + "created in the local types tab (CCIMP include): lif_get_data + "A local class (lcl_data_prov_local_itf) is also created in the CCIMP include. It + "implements the local interface. - "When the class is executed using F9, the object used here refers to type lcl_data_prov_local_itf. - "When the unit test is executed, the object used here refers to type ltd_test_data_local_itf, - "i.e. the local test double is injected. - DATA(flight_data) = data_provider_local_itf->select_flight_data( carrier = carrier_id ). + "When the class is executed using F9, the object used here refers to type lcl_data_prov_local_itf. + "When the unit test is executed, the object used here refers to type ltd_test_data_local_itf, + "i.e. the local test double is injected. + DATA(flight_data) = data_provider_local_itf->select_flight_data( carrier = carrier_id ). - LOOP AT flight_data ASSIGNING FIELD-SYMBOL(). + LOOP AT flight_data ASSIGNING FIELD-SYMBOL(). - total_seatsmax_local_itf = total_seatsmax_local_itf + -seatsmax. - total_seatsocc_local_itf = total_seatsocc_local_itf + -seatsocc. + total_seatsmax_local_itf = total_seatsmax_local_itf + -seatsmax. + total_seatsocc_local_itf = total_seatsocc_local_itf + -seatsocc. - ENDLOOP. + ENDLOOP. - occupancy_rate = total_seatsocc_local_itf / total_seatsmax_local_itf * 100. + occupancy_rate = total_seatsocc_local_itf / total_seatsmax_local_itf * 100. -ENDMETHOD. + ENDMETHOD. -METHOD get_occ_rate_param_inj. + METHOD get_occ_rate_param_inj. "This method demonstrates test double injection using parameter injection. - DATA total_seatsmax_param_inj TYPE i. - DATA total_seatsocc_param_inj TYPE i. + DATA total_seatsmax_param_inj TYPE i. + DATA total_seatsocc_param_inj TYPE i. - "Assumption: The original code in this method was as follows (the line commented out). - "It was identified as DOC (reading data from a database table). + "Assumption: The original code in this method was as follows (the line commented out). + "It was identified as DOC (reading data from a database table). - "DATA(flight_data) = select_flight_data( carrier = carrier_id ). + "DATA(flight_data) = select_flight_data( carrier = carrier_id ). - "Instead of a method call like above and for a proper unit testing, a global interface - "is provided. - "In the example, an interface method is implemented in a local class in the local types - "tab (CCIMP include): lcl_data_prov_glo_itf + "Instead of a method call like above and for a proper unit testing, a global interface + "is provided. + "In the example, an interface method is implemented in a local class in the local types + "tab (CCIMP include): lcl_data_prov_glo_itf - "The method has an optional importing parameter. When the unit test is executed, - "the parameter is bound. An object of the test double class is passed in that case. - "Otherwise, when the class is executed using F9, an object of the actual data provider - "is created. - IF data_prov IS BOUND. - data_provider_param_inj = data_prov. - ELSE. - data_provider_param_inj = NEW lcl_data_prov_glo_itf( ). - ENDIF. + "The method has an optional importing parameter. When the unit test is executed, + "the parameter is bound. An object of the test double class is passed in that case. + "Otherwise, when the class is executed using F9, an object of the actual data provider + "is created. + IF data_prov IS BOUND. + data_provider_param_inj = data_prov. + ELSE. + data_provider_param_inj = NEW lcl_data_prov_glo_itf( ). + ENDIF. - DATA(flight_data) = data_provider_param_inj->select_flight_data( carrier = carrier_id ). + DATA(flight_data) = data_provider_param_inj->select_flight_data( carrier = carrier_id ). - LOOP AT flight_data ASSIGNING FIELD-SYMBOL(). + LOOP AT flight_data ASSIGNING FIELD-SYMBOL(). - total_seatsmax_param_inj = total_seatsmax_param_inj + -seatsmax. - total_seatsocc_param_inj = total_seatsocc_param_inj + -seatsocc. + total_seatsmax_param_inj = total_seatsmax_param_inj + -seatsmax. + total_seatsocc_param_inj = total_seatsocc_param_inj + -seatsocc. - ENDLOOP. + ENDLOOP. - occupancy_rate = total_seatsocc_param_inj / total_seatsmax_param_inj * 100. + occupancy_rate = total_seatsocc_param_inj / total_seatsmax_param_inj * 100. -ENDMETHOD. + ENDMETHOD. -METHOD get_occ_rate_setter_inj. + METHOD get_occ_rate_setter_inj. "This method demonstrates test double injection using setting injection. "See the setter_meth method. - DATA total_seatsmax_setter_inj TYPE i. - DATA total_seatsocc_setter_inj TYPE i. + DATA total_seatsmax_setter_inj TYPE i. + DATA total_seatsocc_setter_inj TYPE i. - "Assumption: The original code in this method was as follows (the line commented out). - "It was identified as DOC (reading data from a database table). + "Assumption: The original code in this method was as follows (the line commented out). + "It was identified as DOC (reading data from a database table). - "DATA(flight_data) = select_flight_data( carrier = carrier_id ). + "DATA(flight_data) = select_flight_data( carrier = carrier_id ). - "Instead of a method call like above and for a proper unit testing, a global interface - "is provided. - "In the example, an interface method is implemented in a local class in the local types - "tab (CCIMP include): lcl_data_prov_glo_itf + "Instead of a method call like above and for a proper unit testing, a global interface + "is provided. + "In the example, an interface method is implemented in a local class in the local types + "tab (CCIMP include): lcl_data_prov_glo_itf - "See the comment in the setter_meth method - DATA(flight_data) = data_provider_setter_inj->select_flight_data( carrier = carrier_id ). + "See the comment in the setter_meth method + DATA(flight_data) = data_provider_setter_inj->select_flight_data( carrier = carrier_id ). - LOOP AT flight_data ASSIGNING FIELD-SYMBOL(). + LOOP AT flight_data ASSIGNING FIELD-SYMBOL(). - total_seatsmax_setter_inj = total_seatsmax_setter_inj + -seatsmax. - total_seatsocc_setter_inj = total_seatsocc_setter_inj + -seatsocc. + total_seatsmax_setter_inj = total_seatsmax_setter_inj + -seatsmax. + total_seatsocc_setter_inj = total_seatsocc_setter_inj + -seatsocc. - ENDLOOP. + ENDLOOP. - occupancy_rate = total_seatsocc_setter_inj / total_seatsmax_setter_inj * 100. + occupancy_rate = total_seatsocc_setter_inj / total_seatsmax_setter_inj * 100. -ENDMETHOD. + ENDMETHOD. -METHOD get_occ_rate_test_seam. -"Method to demonstrate test double injection using test seams -"Note: The code is just for demonstration purposes. Of course, the result can be -"achieved more elegantly using SQL expressions, for example. + METHOD get_occ_rate_test_seam. + "Method to demonstrate test double injection using test seams + "Note: The code is just for demonstration purposes. Of course, the result can be + "achieved more elegantly using SQL expressions, for example. + + TEST-SEAM select_flights. + "DOC + SELECT seatsmax, seatsocc + FROM zdemo_abap_fli + WHERE carrid = @carrier_id + INTO CORRESPONDING FIELDS OF TABLE @seats_table. + END-TEST-SEAM. + + DATA total_seatsmax_tm TYPE i. + DATA total_seatsocc_tm TYPE i. + + LOOP AT seats_table ASSIGNING FIELD-SYMBOL(). + + total_seatsmax_tm = total_seatsmax_tm + -seatsmax. + total_seatsocc_tm = total_seatsocc_tm + -seatsocc. + + ENDLOOP. + + occupancy_rate = total_seatsocc_tm / total_seatsmax_tm * 100. + + "Further examples for test seams + DATA(var) = 0. + + "Empty test seam; code is injected during unit test + "Check the output when running the class using F9 and + "the test results when running the unit test. + TEST-SEAM num1. + END-TEST-SEAM. + + IF var = 0. + num1 = 1. + ELSE. + num1 = 999. + ENDIF. + + num2 = 0. + + "Empty injection + "See the test class: The code that is included in the test + "seam should be excluded from the test. Therefore, the + "test injection block in the test class is empty. + "Check the output when running the class using F9 and + "the test results when running the unit test. + TEST-SEAM num2. + num2 = 123. + END-TEST-SEAM. + + ENDMETHOD. + + + METHOD get_occ_rate_using_meth. + "This method demonstrates test double injection using inheritance and method redefinition. + + DATA total_seatsmax_no TYPE i. + DATA total_seatsocc_no TYPE i. + + "During the unit test, the redefined method in the test class is called. + DATA(flight_data) = select_flight_data( carrier = carrier_id ). + + LOOP AT flight_data ASSIGNING FIELD-SYMBOL(). + + total_seatsmax_no = total_seatsmax_no + -seatsmax. + total_seatsocc_no = total_seatsocc_no + -seatsocc. + + ENDLOOP. + + occupancy_rate = total_seatsocc_no / total_seatsmax_no * 100. + + ENDMETHOD. + + + METHOD get_sum. + "The method selects a record from a database table and sums the values + "of two fields, both are of type i. + + SELECT SINGLE + FROM zdemo_abap_tab1 + FIELDS num1 + num2 AS sum + WHERE key_field = @key + AND char1 = @char + INTO @sum. + + ENDMETHOD. + + + METHOD if_oo_adt_classrun~main. + "Note: The example includes a couple of implementations for the methods + "declared above. And by choosing F9 in ADT, you can run the class and check the + "output in the console. + "However, the focus of the example is unit tests. Therefore, check the + "test classes and methods in the test include (Test Classes tab in ADT). + "Choose Ctrl/Cmd + Shift + F10 to launch all tests in the class and check the + "test results in the ABAP Unit tab in ADT. + + out->write( |ABAP Cheat Sheet Example: ABAP Unit Tests\n\n| ). + + out->write( `************************************************************************` ). + out->write( `---> Choose Ctrl/Cmd + Shift + F10 to launch all tests in the class <---` ). + out->write( |************************************************************************\n| ). + + out->write( |1) get_sum Method\n\n| ). + "This method demonstrates the use of the setup and teardown methods in the test class. + + DATA(sum) = get_sum( key = 1 char = 'aaa' ). + + out->write( data = sum name = `sum` ). + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `2) get_common_div_and_gcd Method` ) ). + + "Filling an internal table with numbers on whose bases the common divisors and the + "greatest common divisor are to be calculated + DATA(tab) = VALUE nums_tab( ( num1 = 10 num2 = 20 ) + ( num1 = 100 num2 = 200 ) + ( num1 = 12 num2 = 6 ) + ( num1 = 5 num2 = 1 ) + ( num1 = 50 num2 = 50 ) + ( num1 = 4 num2 = 8 ) ). + + LOOP AT tab ASSIGNING FIELD-SYMBOL(). + DATA(tabix) = sy-tabix. + get_common_div_and_gcd( EXPORTING a = -num1 + b = -num2 + IMPORTING common_divisors = DATA(common_divs) gcd = DATA(gcd) ). + + out->write( |Common divisors of { -num1 } and { -num2 }\n| ). + out->write( |\n| ). + out->write( data = common_divs name = `common_divs` ). + out->write( |\n| ). + out->write( |Greatest common divisor of { -num1 } and { -num2 }: { gcd } | ). + out->write( |\n| ). + IF tabix < lines( tab ). + out->write( `--------------------------` ). + out->write( |\n| ). + ENDIF. + ENDLOOP. + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `3) get_digit_sum Method` ) ). + + "Filling an internal table with numbers on whose bases the digit sum is to be calculated + DATA(tab_i) = VALUE int_tab_so( ( 12 ) + ( 123 ) + ( 3 ) + ( 8246 ) + ( 1001001 ) + ( 0 ) ). + + LOOP AT tab_i ASSIGNING FIELD-SYMBOL(). + DATA(digit_sum) = get_digit_sum( ). + + out->write( |The digit sum of { } is { digit_sum }.| ). + out->write( |\n| ). + ENDLOOP. + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `4) get_occ_rate_using_meth Method` ) ). + "In the test class, this method demonstrates test double injection + "using inheritance and method redefinition. + + "Filling an internal table with carrier ids on whose bases the occupancy + "rate is to be calculated. + DATA(tab_str) = VALUE zdemo_abap_get_data_itf=>carr_tab( ( carrid = 'LH' ) + ( carrid = 'AA' ) + ( carrid = 'DL' ) ). + + LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). + DATA(occupancy_rate) = get_occ_rate_using_meth( -carrid ). + + out->write( |The occupancy rate for airline { -carrid } is { occupancy_rate }%.| ). + out->write( |\n| ). + ENDLOOP. + out->write( zcl_demo_abap_aux=>heading( `5) get_occ_rate_test_seam Method` ) ). + "This method demonstrates test double injection using test seams. + + LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). + get_occ_rate_test_seam( EXPORTING carrier_id = -carrid + IMPORTING occupancy_rate = DATA(occupancy_rate_test_seam) + num1 = DATA(num1) + num2 = DATA(num2) ). + + out->write( |The occupancy rate for airline { -carrid } is { occupancy_rate_test_seam }%.| ). + out->write( |\n| ). + out->write( |num1: { num1 }| ). + out->write( |\n| ). + out->write( |num2: { num2 }| ). + out->write( |\n| ). + ENDLOOP. + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `6) get_occ_rate_local_itf Method` ) ). + "This method demonstrates test double injection using back door + "injection and a local interface. + + LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). + DATA(occupancy_rate_local_itf) = get_occ_rate_local_itf( -carrid ). + + out->write( |The occupancy rate for airline { -carrid } is { occupancy_rate_local_itf }%.| ). + out->write( |\n| ). + ENDLOOP. + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `7) get_occ_rate_global_itf Method` ) ). + "This method demonstrates test double injection using constructor + "injection and a global interface. + + LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). + DATA(occupancy_rate_global_itf) = get_occ_rate_global_itf( -carrid ). + + out->write( |The occupancy rate for airline { -carrid } is { occupancy_rate_global_itf }%.| ). + out->write( |\n| ). + ENDLOOP. + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `8) get_occ_rate_setter_inj Method` ) ). + "This method demonstrates test double injection using setter injection and a global interface. + + LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). + DATA(occupancy_rate_setter_inj) = get_occ_rate_setter_inj( -carrid ). + + out->write( |The occupancy rate for airline { -carrid } is { occupancy_rate_setter_inj }%.| ). + out->write( |\n| ). + ENDLOOP. + +********************************************************************** + + out->write( zcl_demo_abap_aux=>heading( `9) get_occ_rate_param_inj Method` ) ). + "This method demonstrates test double injection using parameter injection and a global interface. + + LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). + DATA(occupancy_rate_param_inj) = get_occ_rate_param_inj( carrier_id = -carrid ). + + out->write( |The occupancy rate for airline { -carrid } is { occupancy_rate_param_inj }%.| ). + out->write( |\n| ). + ENDLOOP. + ENDMETHOD. + + METHOD select_flight_data. + "Method that is identified as DOC in the method implementations above. + "This method is also used for demonstrating test double injection and method redefinition. - TEST-SEAM select_flights. - "DOC SELECT seatsmax, seatsocc FROM zdemo_abap_fli - WHERE carrid = @carrier_id - INTO CORRESPONDING FIELDS OF TABLE @seats_table. - END-TEST-SEAM. + WHERE carrid = @carrier + INTO CORRESPONDING FIELDS OF TABLE @flight_data. + ENDMETHOD. - DATA total_seatsmax_tm TYPE i. - DATA total_seatsocc_tm TYPE i. - LOOP AT seats_table ASSIGNING FIELD-SYMBOL(). + METHOD setter_meth. + "Method to demonstrate the test double injection using setter injection - total_seatsmax_tm = total_seatsmax_tm + -seatsmax. - total_seatsocc_tm = total_seatsocc_tm + -seatsocc. - - ENDLOOP. - - occupancy_rate = total_seatsocc_tm / total_seatsmax_tm * 100. - - "Further examples for test seams - DATA(var) = 0. - - "Empty test seam; code is injected during unit test - "Check the output when running the class using F9 and - "the test results when running the unit test. - TEST-SEAM num1. - END-TEST-SEAM. - - IF var = 0. - num1 = 1. - ELSE. - num1 = 999. - ENDIF. - - num2 = 0. - - "Empty injection - "See the test class: The code that is included in the test - "seam should be excluded from the test. Therefore, the - "test injection block in the test class is empty. - "Check the output when running the class using F9 and - "the test results when running the unit test. - TEST-SEAM num2. - num2 = 123. - END-TEST-SEAM. - -ENDMETHOD. - - -METHOD get_occ_rate_using_meth. - "This method demonstrates test double injection using inheritance and method redefinition. - - DATA total_seatsmax_no TYPE i. - DATA total_seatsocc_no TYPE i. - - "During the unit test, the redefined method in the test class is called. - DATA(flight_data) = select_flight_data( carrier = carrier_id ). - - LOOP AT flight_data ASSIGNING FIELD-SYMBOL(). - - total_seatsmax_no = total_seatsmax_no + -seatsmax. - total_seatsocc_no = total_seatsocc_no + -seatsocc. - - ENDLOOP. - - occupancy_rate = total_seatsocc_no / total_seatsmax_no * 100. - -ENDMETHOD. - - -METHOD get_sum. - "The method selects a record from a database table and sums the values - "of two fields, both are of type i. - - SELECT SINGLE - FROM zdemo_abap_tab1 - FIELDS num1 + num2 AS sum - WHERE key_field = @key - AND char1 = @char - INTO @sum. - -ENDMETHOD. - - -METHOD if_oo_adt_classrun~main. - "Note: The example includes a couple of implementations for the methods - "declared above. And by choosing F9 in ADT, you can run the class and check the - "output in the console. - "However, the focus of the example is unit tests. Therefore, check the - "test classes and methods in the test include (Test Classes tab in ADT). - "Choose Ctrl/Cmd + Shift + F10 to launch all tests in the class and check the - "test results in the ABAP Unit tab in ADT. - - DATA(output) = NEW zcl_demo_abap_display( out ). - - output->display( `ABAP Cheat Sheet Example: ABAP Unit Tests` ). - - output->display( `************************************************************************` ). - output->display( `---> Choose Ctrl/Cmd + Shift + F10 to launch all tests in the class <---` ). - output->display( `************************************************************************` ). - - output->display( `1) get_sum Method` ). - "This method demonstrates the use of the setup and teardown methods in the test class. - - DATA(sum) = get_sum( key = 1 char = 'aaa' ). - - output->display( input = sum name = `sum` ). - -********************************************************************** - - output->next_section( `2) get_common_div_and_gcd Method` ). - - "Filling an internal table with numbers on whose bases the common divisors and the - "greatest common divisor are to be calculated - DATA(tab) = VALUE nums_tab( ( num1 = 10 num2 = 20 ) - ( num1 = 100 num2 = 200 ) - ( num1 = 12 num2 = 6 ) - ( num1 = 5 num2 = 1 ) - ( num1 = 50 num2 = 50 ) - ( num1 = 4 num2 = 8 ) ). - - LOOP AT tab ASSIGNING FIELD-SYMBOL(). - - get_common_div_and_gcd( EXPORTING a = -num1 - b = -num2 - IMPORTING common_divisors = DATA(common_divs) gcd = DATA(gcd) ). - - output->display( |Common divisors of { -num1 } and { -num2 }| ). - - output->display( input = common_divs name = `common_divs` ). - - output->display( |Greatest common divisor of { -num1 } and { -num2 }: { gcd } | ). - - ENDLOOP. - - -********************************************************************** - - output->next_section( `3) get_digit_sum Method` ). - - "Filling an internal table with numbers on whose bases the digit sum is to be calculated - DATA(tab_i) = VALUE int_tab_so( ( 12 ) - ( 123 ) - ( 3 ) - ( 8246 ) - ( 1001001 ) - ( 0 ) ). - - LOOP AT tab_i ASSIGNING FIELD-SYMBOL(). - - DATA(digit_sum) = get_digit_sum( ). - - output->display( |The digit sum of { } is { digit_sum }.| ). - - ENDLOOP. - -********************************************************************** - - output->next_section( `4) get_occ_rate_using_meth Method` ). - "In the test class, this method demonstrates test double injection - "using inheritance and method redefinition. - - "Filling an internal table with carrier ids on whose bases the occupancy - "rate is to be calculated. - DATA(tab_str) = VALUE zdemo_abap_get_data_itf=>carr_tab( ( carrid = 'LH' ) - ( carrid = 'AA' ) - ( carrid = 'DL' ) ). - - LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). - - DATA(occupancy_rate) = get_occ_rate_using_meth( -carrid ). - - output->display( |The occupancy rate for airline { -carrid } is { occupancy_rate }%.| ). - - ENDLOOP. - output->next_section( `5) get_occ_rate_test_seam Method` ). - "This method demonstrates test double injection using test seams. - - LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). - - get_occ_rate_test_seam( EXPORTING carrier_id = -carrid - IMPORTING occupancy_rate = DATA(occupancy_rate_test_seam) - num1 = DATA(num1) - num2 = DATA(num2) ). - - output->display( |The occupancy rate for airline { -carrid } is { occupancy_rate_test_seam }%.| ). - - output->display( |num1: { num1 }| ). - output->display( |num2: { num2 }| ). - - ENDLOOP. - -********************************************************************** - - output->next_section( `6) get_occ_rate_local_itf Method` ). - "This method demonstrates test double injection using back door - "injection and a local interface. - - LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). - - DATA(occupancy_rate_local_itf) = get_occ_rate_local_itf( -carrid ). - - output->display( |The occupancy rate for airline { -carrid } is { occupancy_rate_local_itf }%.| ). - - ENDLOOP. - -********************************************************************** - - output->next_section( `7) get_occ_rate_global_itf Method` ). - "This method demonstrates test double injection using constructor - "injection and a global interface. - - LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). - - DATA(occupancy_rate_global_itf) = get_occ_rate_global_itf( -carrid ). - - output->display( |The occupancy rate for airline { -carrid } is { occupancy_rate_global_itf }%.| ). - - ENDLOOP. - -********************************************************************** - - output->next_section( `8) get_occ_rate_setter_inj Method` ). - "This method demonstrates test double injection using setter injection and a global interface. - - LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). - - DATA(occupancy_rate_setter_inj) = get_occ_rate_setter_inj( -carrid ). - - output->display( |The occupancy rate for airline { -carrid } is { occupancy_rate_setter_inj }%.| ). - - ENDLOOP. - -********************************************************************** - - output->next_section( `9) get_occ_rate_param_inj Method` ). - "This method demonstrates test double injection using parameter injection and a global interface. - - LOOP AT tab_str ASSIGNING FIELD-SYMBOL(). - - DATA(occupancy_rate_param_inj) = get_occ_rate_param_inj( carrier_id = -carrid ). - - output->display( |The occupancy rate for airline { -carrid } is { occupancy_rate_param_inj }%.| ). - - ENDLOOP. - - -ENDMETHOD. - - -METHOD select_flight_data. -"Method that is identified as DOC in the method implementations above. -"This method is also used for demonstrating test double injection and method redefinition. - - SELECT seatsmax, seatsocc - FROM zdemo_abap_fli - WHERE carrid = @carrier - INTO CORRESPONDING FIELDS OF TABLE @flight_data. -ENDMETHOD. - - -METHOD setter_meth. - "Method to demonstrate the test double injection using setter injection - - "When the unit test is executed, an object of the test double class is passed as - "a parameter. Then, the object used here refers to type ltd_test_data_setter_inj, - "i.e. the local test double is injected. - data_provider_setter_inj = data_prov. -ENDMETHOD. + "When the unit test is executed, an object of the test double class is passed as + "a parameter. Then, the object used here refers to type ltd_test_data_setter_inj, + "i.e. the local test double is injected. + data_provider_setter_inj = data_prov. + ENDMETHOD. ENDCLASS.