This commit is contained in:
danrega
2023-11-06 16:54:31 +01:00
parent 4a0fe907de
commit 1c50246e58
22 changed files with 4769 additions and 4294 deletions

View File

@@ -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.

View File

@@ -20,22 +20,24 @@
"! <p class="shorttext synchronized">Class supporting ABAP cheat sheet examples</p>
"! 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.

View File

@@ -3,9 +3,9 @@
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_DISPLAY</CLSNAME>
<CLSNAME>ZCL_DEMO_ABAP_AUX</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Class for ABAP cheat sheet examples</DESCRIPT>
<DESCRIPT>Class supporting ABAP cheat sheet examples</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>

View File

@@ -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.

View File

@@ -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.

View File

@@ -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 } { <fs> } { num2 } = { calc_result }| ).
out->write( |{ num1 } { <fs> } { 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.

View File

@@ -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.
*
***********************************************************************
"! <p class="shorttext synchronized">Class supporting ABAP cheat sheet examples</p>
"! 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.

View File

@@ -39,7 +39,7 @@
* code.
*
***********************************************************************
"! <p class="shorttext synchronized">ABAP Cheat Sheet: Data Types and Data Objects</p>
"! <p class="shorttext synchronized">ABAP cheat sheet: Data Types and Data Objects</p>
"! Example to demonstrate data types and data objects in ABAP.<br>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 <fs_a>.
output->display( input = <fs_a> name = `<fs_a>` ).
out->write( data = <fs_a> name = `<fs_a>` ).
out->write( |\n| ).
ASSIGN do_f_str TO <fs_a>.
output->display( input = <fs_a> name = `<fs_a>` ).
out->write( data = <fs_a> name = `<fs_a>` ).
out->write( |\n| ).
"Generic type data
ASSIGN do_e_c5 TO <fs_b>.
output->display( input = <fs_b> name = `<fs_b>` ).
out->write( data = <fs_b> name = `<fs_b>` ).
out->write( |\n| ).
ASSIGN do_f_str TO <fs_b>.
output->display( input = <fs_b> name = `<fs_b>` ).
out->write( data = <fs_b> name = `<fs_b>` ).
out->write( |\n| ).
ASSIGN itab_a TO <fs_b>.
output->display( input = <fs_b> name = `<fs_b>` ).
out->write( data = <fs_b> name = `<fs_b>` ).
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.

View File

@@ -5,7 +5,7 @@
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_DTYPE_DOBJ</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheets: Data types and data objects</DESCRIPT>
<DESCRIPT>ABAP cheat sheet: Data Types and Data Objects</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_FLIGHT_TABLES</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Class for ABAP cheat sheet examples</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

File diff suppressed because it is too large Load Diff

View File

@@ -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.

View File

@@ -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(<calc>).
"Method call to calculate and return the result
DATA(res) = calc( num1 = <calc>-num1
operator = <calc>-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(<fs_int>).
TRY.
output->display( |--- Calculations with { <fs_int> } ---| ).
out->write( |--- Calculations with { <fs_int> } ---| ).
DATA(calc1) = CONV decfloat34( 1 / <fs_int> ).
output->display( input = calc1 name = `calc1` ).
out->write( data = calc1 name = `calc1` ).
out->write( |\n| ).
DATA(calc2) = ipow( base = <fs_int> 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(<fs_int_inh>).
TRY.
output->display( |--- Calculations with { <fs_int_inh> } ---| ).
out->write( |--- Calculations with { <fs_int_inh> } ---| ).
calc1 = 1 / <fs_int_inh>.
output->display( input = calc1 name = `calc1` ).
out->write( data = calc1 name = `calc1` ).
out->write( |\n| ).
calc2 = ipow( base = <fs_int_inh> 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(<fs_int_into>).
TRY.
output->display( |--- Calculations with { <fs_int_into> } ---| ).
out->write( |--- Calculations with { <fs_int_into> } ---| ).
calc1 = 1 / <fs_int_into>.
output->display( input = calc1 name = `calc1` ).
out->write( data = calc1 name = `calc1` ).
out->write( |\n| ).
calc2 = ipow( base = <fs_int_into> 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(<email>).
TRY.
DATA(email_valid) = validate_email( email = <email> ).
DATA(exc_raised) = abap_false.
CATCH lcx_invalid_email.
email_valid = abap_false.
exc_raised = abap_true.
ENDTRY.
APPEND VALUE #( email = <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.

View File

@@ -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.

View File

@@ -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(<err>).
DATA op TYPE string.
CASE if_abap_behv=>mk-on.
WHEN <err>-%op-%create.
op = `create operation`.
@@ -123,7 +121,6 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION.
ELSE `key = ` && <err>-key_field ) &&
`: Fail cause ` && <err>-%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.
&& <err_ch>-%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.

View File

@@ -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(<err>).
DATA op TYPE string.
CASE if_abap_behv=>mk-on.
WHEN <err>-%op-%create.
op = `create operation`.
@@ -131,7 +129,6 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION.
ELSE `key = ` && <err>-key_field ) &&
`: Fail cause ` && <err>-%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.

View File

@@ -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.

View File

@@ -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.

File diff suppressed because it is too large Load Diff

View File

@@ -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 = <fs1> name = `<fs1>` ).
output->display( input = dref->* name = `dref->*` ).
out->write( data = ls_read_table name = `ls_read_table` ).
out->write( |\n| ).
out->write( data = <fs1> name = `<fs1>` ).
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.
<fs_loop>-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.

File diff suppressed because it is too large Load Diff