Update main branch for ABAP Cloud only

This commit is contained in:
danrega
2023-08-30 14:00:40 +02:00
parent 842cb03da1
commit 51f5bac672
83 changed files with 1814 additions and 1657 deletions

View File

@@ -4,7 +4,6 @@
<asx:values>
<DEVC>
<CTEXT>ABAP Cheat Sheets</CTEXT>
<TPCLASS>X</TPCLASS>
</DEVC>
</asx:values>
</asx:abap>

View File

@@ -16,5 +16,5 @@ ENDCLASS.
CLASS zbp_demo_abap_rap_draft_m IMPLEMENTATION.
CLASS ZBP_DEMO_ABAP_RAP_DRAFT_M IMPLEMENTATION.
ENDCLASS.

View File

@@ -22,19 +22,19 @@
* the example might not fully meet the requirements of the RAP BO contract.
*
* In newer ABAP releases, you can use side effects to trigger data
* changes (in terms of this example, the recalculation of the calculation
* result) and other things based on data changes in UI scenarios with
* changes (in terms of this example, the recalculation of the calculation
* result) and other things based on data changes in UI scenarios with
* draft-enabled BOs.
*
* 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
* 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.
*

View File

@@ -10,7 +10,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
<CLSDEFINT>ZDEMO_ABAP_RAP_DRAFT_M</CLSDEFINT>
</VSEOCLASS>
</asx:values>

View File

@@ -16,5 +16,5 @@ ENDCLASS.
CLASS zbp_demo_abap_rap_ro_m IMPLEMENTATION.
CLASS ZBP_DEMO_ABAP_RAP_RO_M IMPLEMENTATION.
ENDCLASS.

View File

@@ -21,13 +21,13 @@
*
* 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
* 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.
*

View File

@@ -10,7 +10,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
<CLSDEFINT>ZDEMO_ABAP_RAP_RO_M</CLSDEFINT>
</VSEOCLASS>
</asx:values>

View File

@@ -16,5 +16,5 @@ ENDCLASS.
CLASS zbp_demo_abap_rap_ro_u IMPLEMENTATION.
CLASS ZBP_DEMO_ABAP_RAP_RO_U IMPLEMENTATION.
ENDCLASS.

View File

@@ -25,13 +25,13 @@
*
* 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
* 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.
*

View File

@@ -10,7 +10,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
<CLSDEFINT>ZDEMO_ABAP_RAP_RO_U</CLSDEFINT>
</VSEOCLASS>
</asx:values>

View File

@@ -35,13 +35,13 @@
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -113,30 +113,31 @@ CLASS zcl_demo_abap_amdp DEFINITION
"fill a demo database table to have data to work with in the example.
CLASS-METHODS class_constructor.
"AMDP procedure
"This method demonstrates the calling of an AMDP procedure from SQLScript.
"In this example, the selection of data is 'delegated' to another AMDP method get_flights_amdp
"in the same AMDP class. The method declaration includes the addition RAISING with an
"exception class for AMDP-specific exceptions.
CLASS-METHODS get_flights
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli-carrid
EXPORTING VALUE(fli_tab) TYPE fli_tab
RAISING cx_amdp_execution_error.
"AMDP procedure
"This method demonstrates the calling of an AMDP procedure from SQLScript.
"In this example, the selection of data is 'delegated' to another AMDP method get_flights_amdp
"in the same AMDP class. The method declaration includes the addition RAISING with an
"exception class for AMDP-specific exceptions.
CLASS-METHODS get_flights
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli-carrid
EXPORTING VALUE(fli_tab) TYPE fli_tab
RAISING cx_amdp_execution_error.
"AMDP Table Function for CDS Table Function
"Note that, in this case, a static method declaration is required along with the special
"syntax FOR TABLE FUNCTION. Plus, there are no parameters specified and the declaration
"is made in the PUBLIC visibility section.
CLASS-METHODS flight_analysis FOR TABLE FUNCTION zdemo_abap_table_function.
"AMDP Table Function for CDS Table Function
"Note that, in this case, a static method declaration is required along with the special
"syntax FOR TABLE FUNCTION. Plus, there are no parameters specified and the declaration
"is made in the PUBLIC visibility section.
CLASS-METHODS flight_analysis FOR TABLE FUNCTION zdemo_abap_table_function.
PROTECTED SECTION.
PRIVATE SECTION.
"AMDP procedure
"This method demonstrates the calling of an AMDP procedure from SQLScript as mentioned above.
CLASS-METHODS get_flights_amdp
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli-carrid
EXPORTING VALUE(fli_tab) TYPE fli_tab
RAISING cx_amdp_execution_error.
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli-carrid
EXPORTING VALUE(fli_tab) TYPE fli_tab
RAISING cx_amdp_execution_error.
"AMDP table function
"AMDP table functions can only be called by other AMDP methods. In this example,
@@ -145,23 +146,119 @@ CLASS zcl_demo_abap_amdp DEFINITION
IMPORTING VALUE(carrid) TYPE zdemo_abap_flsch-carrid
RETURNING VALUE(carr_fli_tab) TYPE carr_fli_tab.
CONSTANTS nl TYPE string value cl_abap_char_utilities=>newline.
ENDCLASS.
CLASS zcl_demo_abap_amdp IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
ENDMETHOD.
METHOD flight_analysis
BY DATABASE FUNCTION
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zdemo_abap_flsch "Two database tables are used and must both be specified here.
zdemo_abap_carr.
* Reading data from two database tables
itab_cities =
select DISTINCT
zdemo_abap_flsch.mandt as client,
zdemo_abap_flsch.carrid as carrier_id,
zdemo_abap_flsch.airpfrom as airport_from,
zdemo_abap_flsch.airpto as airport_to,
zdemo_abap_flsch.fltime as flight_time,
zdemo_abap_flsch.distance as flight_distance,
zdemo_abap_flsch.distid as unit
from zdemo_abap_flsch;
itab_carrier_names =
select distinct
zdemo_abap_carr.mandt as client,
zdemo_abap_carr.carrid as carrier_id,
zdemo_abap_carr.carrname as carrier_name
from zdemo_abap_carr;
* Returning joined data using an inner join
return
select fl.client, fl.carrier_id, ca.carrier_name,
* Departure and destination airports are concatenated; then all results are joined by string aggregation
string_agg( concat(concat(fl.airport_from,' -> '),fl.airport_to), ', ' ORDER BY fl.airport_from) AS connections,
* Retrieving the average flight time of all flights by carrier
AVG( fl.flight_time ) as avg_flight_time,
* Retrieving the average flight distance of all flights by carrier; miles are converted to kilometers
avg( case 'MI'
when fl.unit then fl.flight_distance * 1.609
ELSE fl.flight_distance
END ) AS avg_distance
FROM :itab_cities AS fl
INNER JOIN :itab_carrier_names AS ca
ON ca.client = fl.client
AND ca.carrier_id = fl.carrier_id
WHERE fl.client = ca.client AND fl.carrier_id = ca.carrier_id
GROUP BY fl.client, ca.carrier_name, fl.carrier_id;
ENDMETHOD.
METHOD get_carr_fli
BY DATABASE FUNCTION
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zdemo_abap_carr zdemo_abap_flsch.
* AMDP table function to be called by other AMDP methods only.
* In the example, joined data from two database table are returned.
RETURN
SELECT ca.carrname, fl.connid, fl.cityfrom, fl.cityto
FROM zdemo_abap_carr as ca
INNER JOIN zdemo_abap_flsch as fl
ON ca.carrid = fl.carrid
WHERE fl.carrid = :carrid
ORDER BY ca.mandt, ca.carrname, fl.connid;
ENDMETHOD.
METHOD get_flights
BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zcl_demo_abap_amdp=>get_flights_amdp.
* Another AMDP procedure is called from SQLScript
CALL "ZCL_DEMO_ABAP_AMDP=>GET_FLIGHTS_AMDP"(
carrid => :carrid,
fli_tab => :fli_tab );
ENDMETHOD.
METHOD get_flights_amdp
BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zdemo_abap_fli.
* Simple data selection
fli_tab = SELECT *
FROM "ZDEMO_ABAP_FLI"
WHERE carrid = :carrid
ORDER BY carrid;
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
output->display( `ABAP Cheat Sheet Example: ABAP AMDP` ).
output->display( `1. AMDP procedure` ).
output->display( `1) AMDP procedure` ).
"Declaring an internal table to store the data that are
"returned by the following method.
@@ -180,7 +277,7 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
**********************************************************************
output->next_section( `2. Calling an AMDP Procedure from SQLScript` ).
output->next_section( `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.
@@ -203,7 +300,7 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
**********************************************************************
output->next_section( `3. AMDP Table Function for AMDP Method` ).
output->next_section( `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
@@ -229,20 +326,20 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
**********************************************************************
output->next_section( `4. AMDP Table Function for CDS Table Function` ).
output->next_section( `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.
"You might want to navigate to the DDL source after FROM by holding
"CTRL and clicking the DDL source name in ADT to see the details.
"Or, just check out the F2 help.
"In this example, the CDS table function is implemented in a way to
"return accumulated data.
"In the method implementation for flight_analysis, first two kinds of
"data sets from two database tables are gathered. These data sets are
"joined using an inner join. There, some expressions are included
"(strings are aggregated, average values are determined).
"The example demonstrates that a CDS table function can be used as a
"data source of ABAP SQL read statements.
"You might want to navigate to the DDL source after FROM by holding
"CTRL and clicking the DDL source name in ADT to see the details.
"Or, just check out the F2 help.
"In this example, the CDS table function is implemented in a way to
"return accumulated data.
"In the method implementation for flight_analysis, first two kinds of
"data sets from two database tables are gathered. These data sets are
"joined using an inner join. There, some expressions are included
"(strings are aggregated, average values are determined).
SELECT * FROM zdemo_abap_table_function
INTO TABLE @DATA(cds_tab_func).
@@ -251,7 +348,6 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
ENDMETHOD.
**********************************************************************
METHOD select_carriers
BY DATABASE PROCEDURE
@@ -265,93 +361,6 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
ORDER BY carrid;
ENDMETHOD.
METHOD get_flights
BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zcl_demo_abap_amdp=>get_flights_amdp.
* Another AMDP procedure is called from SQLScript
CALL "ZCL_DEMO_ABAP_AMDP=>GET_FLIGHTS_AMDP"(
CARRID => :CARRID,
FLI_TAB => :FLI_TAB );
ENDMETHOD.
METHOD get_flights_amdp
BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zdemo_abap_fli.
* Simple data selection
fli_tab = SELECT *
FROM "ZDEMO_ABAP_FLI"
WHERE carrid = :carrid
ORDER BY carrid;
ENDMETHOD.
METHOD flight_analysis
BY DATABASE FUNCTION
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zdemo_abap_flsch "Two database tables are used and must both be specified here.
zdemo_abap_carr.
* Reading data from two database tables
itab_cities =
SELECT DISTINCT
zdemo_abap_flsch.mandt as client,
zdemo_abap_flsch.carrid as carrier_id,
zdemo_abap_flsch.airpfrom as airport_from,
zdemo_abap_flsch.airpto as airport_to,
zdemo_abap_flsch.fltime as flight_time,
zdemo_abap_flsch.distance as flight_distance,
zdemo_abap_flsch.distid as unit
FROM zdemo_abap_flsch;
itab_carrier_names =
SELECT DISTINCT
zdemo_abap_carr.mandt as client,
zdemo_abap_carr.carrid as carrier_id,
zdemo_abap_carr.carrname as carrier_name
FROM zdemo_abap_carr;
* Returning joined data using an inner join
RETURN
SELECT fl.client, fl.carrier_id, ca.carrier_name,
* Departure and destination airports are concatenated; then all results are joined by string aggregation
STRING_AGG( CONCAT(CONCAT(fl.airport_from,' -> '),fl.airport_to), ', ' ORDER BY fl.airport_from) AS connections,
* Retrieving the average flight time of all flights by carrier
AVG( fl.flight_time ) as avg_flight_time,
* Retrieving the average flight distance of all flights by carrier; miles are converted to kilometers
AVG( CASE 'MI'
WHEN fl.unit THEN fl.flight_distance * 1.609
ELSE fl.flight_distance
END ) AS avg_distance
FROM :itab_cities AS fl
INNER JOIN :itab_carrier_names AS ca
ON ca.client = fl.client
AND ca.carrier_id = fl.carrier_id
WHERE fl.client = ca.client AND fl.carrier_id = ca.carrier_id
GROUP BY fl.client, ca.carrier_name, fl.carrier_id;
ENDMETHOD.
METHOD get_carr_fli
BY DATABASE FUNCTION
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zdemo_abap_carr zdemo_abap_flsch.
* AMDP table function to be called by other AMDP methods only.
* In the example, joined data from two database table are returned.
RETURN
SELECT ca.carrname, fl.connid, fl.cityfrom, fl.cityto
FROM zdemo_abap_carr as ca
INNER JOIN zdemo_abap_flsch as fl
ON ca.carrid = fl.carrid
WHERE fl.carrid = :carrid
ORDER BY ca.mandt, ca.carrname, fl.connid;
ENDMETHOD.
METHOD select_get_carr_fli
BY DATABASE PROCEDURE
@@ -364,5 +373,4 @@ CLASS zcl_demo_abap_amdp IMPLEMENTATION.
FROM "ZCL_DEMO_ABAP_AMDP=>GET_CARR_FLI"(
carrid => :carrid );
ENDMETHOD.
ENDCLASS.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -30,13 +30,13 @@
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -53,11 +53,13 @@ CLASS zcl_demo_abap_cds_ve DEFINITION
if_oo_adt_classrun.
CLASS-METHODS class_constructor.
ENDCLASS.
CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
@@ -91,9 +93,9 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
period = 0 ) ) ).
MODIFY zdemo_abap_fli FROM TABLE @( VALUE #( ( carrid = 'UA' ) ) ).
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
@@ -101,7 +103,7 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
output->display( `ABAP Cheat Sheet Example: CDS view entities` ).
output->display( `1) Operands, expressions and built-in functions ` &&
`in a CDS view entity` ).
`in a CDS view entity` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved. The sample CDS view entity
@@ -170,7 +172,7 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
" contain the coalesce function and CASE expressions similar to the
" CDS view entity.
output->display( `----- Inner join -----` ).
output->display( `---------- Inner join ----------` ).
SELECT _carr~carrid,
_carr~carrname,
@@ -184,7 +186,7 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
output->display( input = sql_inner_join name = `sql_inner_join` ).
output->display( `----- Left outer join -----` ).
output->display( `---------- Left outer join ----------` ).
SELECT _carr~carrid,
_carr~carrname,
@@ -198,7 +200,7 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
output->display( input = sql_left_outer_join name = `sql_left_outer_join` ).
output->display( `----- Right outer join -----` ).
output->display( `---------- Right outer join ----------` ).
SELECT _carr~carrid,
_carr~carrname,
@@ -215,7 +217,7 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
output->display( input = sql_right_outer_join name = `sql_right_outer_join` ).
output->display( `----- Cross join -----` ).
output->display( `---------- Cross join ----------` ).
SELECT _carr~carrid,
_carr~carrname,
@@ -255,7 +257,7 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
output->next_section( `Associations` ).
output->display( `5) Selecting data from a CDS view that contains associations` ).
output->display( `5) Selecting data from a CDS view that contains associations` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved. The sample CDS view entity
@@ -281,7 +283,7 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
"The following examples use path expressions to access the association
"targets of exposed associations.
output->display( `6) ... SELECT clause` ).
output->display( `6) ... SELECT clause` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. The statement uses an exposed association.
@@ -359,7 +361,7 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
**********************************************************************
output->next_section( `8) ... Specifying attributes ` ).
output->next_section( `8) ... Specifying attributes` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. The statement uses an exposed association.
@@ -460,5 +462,4 @@ CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
output->display( input = assoc_exp_where name = `assoc_exp_where` ).
ENDMETHOD.
ENDCLASS.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -25,13 +25,13 @@
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -96,7 +96,8 @@ protected section.
tab1 TYPE TABLE OF s1_type WITH EMPTY KEY,
tab2 TYPE TABLE OF s2_type WITH EMPTY KEY,
tab3 TYPE TABLE OF s2_type WITH EMPTY KEY,
tab4 TYPE SORTED TABLE OF s2_type WITH NON-UNIQUE KEY comp3.
tab4 TYPE SORTED TABLE OF s2_type WITH NON-UNIQUE KEY comp3,
nl TYPE string..
CLASS-METHODS:
fill_deep_structures,
@@ -105,15 +106,69 @@ protected section.
ENDCLASS.
CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
METHOD fill_deep_structures.
"Clearing all contents of struc2
CLEAR struc2.
"Filling nested tables in deep structures
struc2-struc_nested = VALUE #( comp1 = `aaa`
comp2 = `bbb`
comp3 = `ccc` ).
struc1-itab = VALUE #(
( col1 = 111 col2 = 222 )
( col1 = 333 col2 = 444
) ).
struc2-itab = VALUE #(
( col2 = 1 col3 = 2 col4 = 3 )
( col2 = 4 col3 = 5 col4 = 6 )
( col2 = 7 col3 = 8 col4 = 9 )
).
"Filling individual component that is not shared by both structures
struc2-comp4 = 999.
ENDMETHOD.
METHOD fill_struc_and_tab.
CLEAR: s1, s2, tab1, tab2, tab3.
s1 = VALUE #( comp1 = 'A' comp2 = `bbb` comp3 = 1 ).
s2 = VALUE #( comp1 = `ccc` comp2 = 'D' comp3 = 2 comp4 = 3 ).
tab1 = VALUE #(
( comp1 = 'A' comp2 = `bbb` comp3 = 1 )
( comp1 = 'B' comp2 = `ccc` comp3 = 2 )
( comp1 = 'C' comp2 = `ddd` comp3 = 3 ) ).
tab2 = VALUE #(
( comp1 = `eee` comp2 = 'F' comp3 = 4 comp4 = 5 )
( comp1 = `ggg` comp2 = 'H' comp3 = 6 comp4 = 7 )
( comp1 = `iii` comp2 = 'J' comp3 = 8 comp4 = 9 ) ).
tab3 = VALUE #(
( comp1 = `aaa` comp2 = 'B' comp3 = 1 comp4 = 2 )
( comp1 = `ccc` comp2 = 'D' comp3 = 3 comp4 = 4 )
( comp1 = `eee` comp2 = 'F' comp3 = 5 comp4 = 6 )
( comp1 = `ggg` comp2 = 'H' comp3 = 7 comp4 = 8 )
( comp1 = `iii` comp2 = 'J' comp3 = 9 comp4 = 10 ) ).
tab4 = tab3.
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
output->display( `ABAP Cheat Sheet Example: Constructor expressions` ).
output->next_section( `VALUE` ).
output->display( `VALUE` ).
output->display( `1) Structures: Populating a flat structure` ).
"A flat structure is created based on a data type defined with a
@@ -147,7 +202,7 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
"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.
"no extra parentheses within the outer pair of parentheses.
struc = VALUE #( BASE struc char2 = 'xyz' ).
output->display( input = struc name = `struc` ).
@@ -185,7 +240,7 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
itab = VALUE #( ( num = 1 char1 = 'aaa' char2 = 'abc' )
( num = 2 char1 = 'bbb' char2 = 'def' )
( num = 3 char1 = 'ccc' ) ).
( num = 3 char1 = 'ccc' ) ).
output->display( input = itab name = `itab` ).
@@ -312,7 +367,7 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
carrname = 'Singapore Airlines'
currcode = 'SGD'
url = 'http://www.singaporeair.com' )
) ).
) ).
"Retrieving table entries for display purposes
SELECT FROM zdemo_abap_carr
@@ -341,7 +396,7 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
END OF substruc,
END OF deep_struc_ty.
DATA(deep_struc) = VALUE deep_struc_ty( num = 1
DATA(deep_struc) = VALUE deep_struc_ty( num = 1
char1 = 'aaa'
substruc = VALUE #( int = 123 str = `hallo` ) ).
@@ -744,25 +799,25 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
output->display( input = dec_num name = `dec_num` ).
"Declaring data objects
DATA(txt) = VALUE abap_bool( ).
DATA(txt) = VALUE abap_bool( ).
DATA(str) = ` `.
"Comparing the data objects with and without conversion
output->display( `Without conversion:` ).
output->display( `Without conversion:` ).
IF txt = str.
output->display( `txt is equal to str.` ).
output->display( `txt is equal to str.` ).
ELSE.
output->display( `txt is not equal to str.` ).
output->display( `txt is not equal to str.` ).
ENDIF.
output->display( `With conversion:` ).
output->display( `With conversion:` ).
IF txt = CONV abap_bool( str ).
output->display( `txt is equal to converted str.` ).
output->display( `txt is equal to converted str.` ).
ELSE.
output->display( `txt is not equal to converted str.` ).
output->display( `txt is not equal to converted str.` ).
ENDIF.
**********************************************************************
@@ -806,13 +861,13 @@ 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 }| ).
output->display( |ex2: { ex2 }; { t1 }| ).
ELSE.
output->display( ex1 ).
ENDIF.
IF ex3 IS INITIAL.
output->display( |ex4: { ex4 }; { t2 }| ).
output->display( |ex4: { ex4 }; { t2 }| ).
ELSE.
output->display( input = ex3 name = `ex3` ).
ENDIF.
@@ -891,7 +946,7 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
DATA(methods) =
CAST cl_abap_objectdescr(
cl_abap_objectdescr=>describe_by_name( 'LOCAL_CLASS' )
)->methods.
)->methods.
"Excursion: Using the older cast operator ?=
"Retrieving structure components
@@ -940,7 +995,7 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
THEN |It's { syst_time TIME = ISO }. | &&
|Good night, { sy-uname }.|
ELSE |Hallo, { sy-uname }.|
).
).
output->display( input = greets name = `greets` ).
@@ -1173,7 +1228,7 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
FOR wa3 IN tab3 WHERE ( comp3 < 4 )
( compX = wa1-comp1
compY = wa2-comp1
compZ = wa3-comp3 ) ).
compZ = wa3-comp3 ) ).
output->display( input = for4 name = `for4` ).
@@ -1202,12 +1257,12 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
"FOR ... WHILE ...
DATA(for5) = VALUE t_type4(
FOR x = 11 THEN x + 10 WHILE x < 40
( col1 = x col2 = x + 1 col3 = x + 2 ) ).
( col1 = x col2 = x + 1 col3 = x + 2 ) ).
"FOR ... UNTIL ...
DATA(for6) = VALUE t_type4(
FOR y = 31 THEN y - 10 UNTIL y < 10
( col1 = y col2 = y + 1 col3 = y + 2 ) ).
( col1 = y col2 = y + 1 col3 = y + 2 ) ).
output->display( input = for5 name = `for5` ).
output->display( input = for6 name = `for6` ).
@@ -1242,7 +1297,7 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
DATA(a_word) =
REDUCE string( INIT text = ``
FOR word IN tab
NEXT text = |{ text }{ word }| ).
NEXT text = |{ text }{ word }| ).
"Example 2
tab = VALUE #( ( `Some` ) ( `cool` ) ( `stuff` )
@@ -1335,7 +1390,7 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
output->display( input = str_tab name = `str_tab` ).
**********************************************************************
**********************************************************************
output->next_section( `42) LET Expressions (2)` ).
@@ -1389,7 +1444,7 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
LET <date> = dates[ sy-index ]
separator = '-'
IN <date>-year && separator && <date>-month &&
separator && <date>-day ).
separator && <date>-day ).
"Adding line to table
stringtab = VALUE #( BASE stringtab ( isodate ) ).
@@ -1398,55 +1453,4 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
output->display( input = stringtab name = `stringtab` ).
ENDMETHOD.
METHOD fill_deep_structures.
"Clearing all contents of struc2
CLEAR struc2.
"Filling nested tables in deep structures
struc2-struc_nested = VALUE #( comp1 = `aaa`
comp2 = `bbb`
comp3 = `ccc` ).
struc1-itab = VALUE #(
( col1 = 111 col2 = 222 )
( col1 = 333 col2 = 444
) ).
struc2-itab = VALUE #(
( col2 = 1 col3 = 2 col4 = 3 )
( col2 = 4 col3 = 5 col4 = 6 )
( col2 = 7 col3 = 8 col4 = 9 )
).
"Filling individual component that is not shared by both structures
struc2-comp4 = 999.
ENDMETHOD.
METHOD fill_struc_and_tab.
CLEAR: s1, s2, tab1, tab2, tab3.
s1 = VALUE #( comp1 = 'A' comp2 = `bbb` comp3 = 1 ).
s2 = VALUE #( comp1 = `ccc` comp2 = 'D' comp3 = 2 comp4 = 3 ).
tab1 = VALUE #(
( comp1 = 'A' comp2 = `bbb` comp3 = 1 )
( comp1 = 'B' comp2 = `ccc` comp3 = 2 )
( comp1 = 'C' comp2 = `ddd` comp3 = 3 ) ).
tab2 = VALUE #(
( comp1 = `eee` comp2 = 'F' comp3 = 4 comp4 = 5 )
( comp1 = `ggg` comp2 = 'H' comp3 = 6 comp4 = 7 )
( comp1 = `iii` comp2 = 'J' comp3 = 8 comp4 = 9 ) ).
tab3 = VALUE #(
( comp1 = `aaa` comp2 = 'B' comp3 = 1 comp4 = 2 )
( comp1 = `ccc` comp2 = 'D' comp3 = 3 comp4 = 4 )
( comp1 = `eee` comp2 = 'F' comp3 = 5 comp4 = 6 )
( comp1 = `ggg` comp2 = 'H' comp3 = 7 comp4 = 8 )
( comp1 = `iii` comp2 = 'J' comp3 = 9 comp4 = 10 ) ).
tab4 = tab3.
ENDMETHOD.
ENDCLASS.
ENDCLASS.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -5,7 +5,7 @@
*
* -------------------------- 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.
* 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.
@@ -45,22 +45,25 @@ CLASS zcl_demo_abap_display DEFINITION
IMPORTING
heading TYPE string.
protected section.
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.
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 ).
@@ -97,7 +100,7 @@ CLASS ZCL_DEMO_ABAP_DISPLAY IMPLEMENTATION.
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 && `":` && cl_abap_char_utilities=>newline && input ) ).
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.
@@ -105,7 +108,7 @@ CLASS ZCL_DEMO_ABAP_DISPLAY IMPLEMENTATION.
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 && `":` && cl_abap_char_utilities=>newline && input->* ) ).
display = mo_out->get( data = COND string( WHEN name IS INITIAL THEN input->* ELSE `"` && name && `":` && nl && input->* ) ).
ELSE.
to_be_serialized = abap_true.
ENDIF.
@@ -127,29 +130,31 @@ CLASS ZCL_DEMO_ABAP_DISPLAY IMPLEMENTATION.
assoc_arrays_opt = abap_true ).
IF to_be_serialized = abap_true.
IF name IS INITIAL.
REPLACE PCRE `^` IN display WITH json && cl_abap_char_utilities=>newline.
REPLACE PCRE `^` IN display WITH json && nl.
ELSE.
REPLACE PCRE `^` IN display WITH `"` && name && `":` && cl_abap_char_utilities=>newline && json && cl_abap_char_utilities=>newline.
REPLACE PCRE `^` IN display WITH `"` && name && `":` && nl && json && nl.
ENDIF.
"substring found
"substring found
ELSE.
IF name IS INITIAL.
REPLACE SECTION OFFSET off LENGTH len OF display WITH json && cl_abap_char_utilities=>newline.
REPLACE SECTION OFFSET off LENGTH len OF display WITH json && nl.
ELSE.
REPLACE SECTION OFFSET off LENGTH len OF display WITH `"` && name && `":` && cl_abap_char_utilities=>newline && json && cl_abap_char_utilities=>newline.
REPLACE SECTION OFFSET off LENGTH len OF display WITH `"` && name && `":` && nl && json && nl.
ENDIF.
ENDIF.
mo_out->write( display ).
mo_out->write( display && nl ).
ELSE.
mo_out->write( display ).
mo_out->write( display && nl ).
ENDIF.
ENDMETHOD.
METHOD next_section.
mo_out->write( `_________________________________________________________________________________`
&& cl_abap_char_utilities=>newline
&& cl_abap_char_utilities=>newline
&& nl
&& nl
&& heading
&& cl_abap_char_utilities=>newline ).
&& nl
&& nl ).
ENDMETHOD.
ENDCLASS.
ENDCLASS.

View File

@@ -115,7 +115,147 @@ CLASS zcl_demo_abap_dtype_dobj DEFINITION
ENDCLASS.
CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
CLASS ZCL_DEMO_ABAP_DTYPE_DOBJ IMPLEMENTATION.
METHOD adapt_text.
DATA text TYPE t_pub_text_c30.
text = cl_text && comma && sy-uname && me->text.
str = text && |\n(Note: The value of me->text is "{ me->text }")|.
ENDMETHOD.
METHOD addition_with_generic_num.
result = num1 + num2.
ENDMETHOD.
METHOD class_constructor.
"Filling demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
ENDMETHOD.
METHOD enum_meth_params.
CASE char.
WHEN a.
output = a.
WHEN b.
output = b.
WHEN OTHERS.
output = `Either c or d: ` && char.
ENDCASE.
ENDMETHOD.
METHOD enum_processing.
"Read and write positions of enumerated objects
"Enumerated objects can be used in all read positions in which the operand
"type is their enumerated type.
"Likewise, enumerated variables can only be used in write positions in which
"the operand type is the enumerated type and only the associated enumerated
"values can be written.
"So, assignments are possible only from one enumerated type to the same (with one
"exception -> assignment to character-like variables of the types c and string)
DATA do_enum TYPE t_enum.
do_enum = a.
APPEND |do_enum: { do_enum }| TO output.
DATA do_enum_2 LIKE do_enum.
do_enum_2 = do_enum.
APPEND |do_enum_2: { do_enum_2 }| TO output.
"Assignment to character-like variables of the types c and string.
"In this case, the target field is assigned the name of the enumerated constant or
"the component of the enumerated structure under which the enumerated value of the
"source field is defined in the enumerated type.
DATA do_a_string TYPE string.
do_a_string = do_enum.
APPEND |do_a_string: { do_a_string }| TO output.
"Or using the CONV operator as follows
DATA(do_next_string) = CONV string( do_enum ).
APPEND |do_next_string: { do_next_string }| TO output.
"Enumerated constants are converted implicitly to the type string
"before the concatenation in the string template.
DATA(str_from_enum) = |{ a }{ b }{ c }{ d }|.
APPEND |str_from_enum: { str_from_enum }| TO output.
"Note that only the enumerated type itself is relevant. Usually, the content
"of an enumerated object is not of interest.
"The enumerated value in the base type can be accessed using the constructor
"operators CONV and EXACT only. The base type is i in this case.
DATA(conv_value) = CONV i( do_enum ).
APPEND |conv_value: { conv_value }| TO output.
"Converting the other way round.
DATA(another_conv) = CONV t_enum( 3 ).
APPEND |another_conv: { another_conv }| TO output.
"If known statically, an attempt to assign a value other than a valid enumerated value
"to an enumerated variable produces a syntax error.
"If not known statically, an exception is raised.
"The following produces a syntax error
"do_enum = f.
"The following example shows raising an exception.
DATA dobj TYPE t_enum.
TYPES t_int_tab TYPE TABLE OF i WITH EMPTY KEY.
DATA(int_tab) = VALUE t_int_tab( ( 0 ) ( 1 ) ( 2 ) ( 3 ) ( 4 ) ).
DATA str_tab TYPE TABLE OF string.
LOOP AT int_tab INTO DATA(wa_en).
TRY.
dobj = CONV t_enum( wa_en ).
APPEND dobj TO str_tab.
CATCH cx_sy_conversion_no_enum_value INTO DATA(error_enum).
APPEND error_enum->get_text( ) TO str_tab.
ENDTRY.
ENDLOOP.
APPEND `------------- START: Output for str_tab -------------` TO output.
APPEND LINES OF str_tab TO output.
APPEND `^^^^^^^^^^^^^ END: Output for str_tab ^^^^^^^^^^^^^` TO output.
"An enumerated variable can be set to the initial value of its base type
"using CLEAR.
CLEAR do_enum.
APPEND |do_enum: { do_enum }| TO output.
"Enumerated structures
DATA do_enum_s TYPE t_enum_struc.
"The enumerated structure en_struc was decalred in the public section.
"Using the addition LIKE, a second structure is created referring to the enumerated structure.
"Note that the second structure is not a constant structure.
"The components of the constant structure contain the enumerated values of the enumerated type.
"All the components of the variable structure declared by LIKE contain the initial values.
DATA do_s LIKE en_struc.
APPEND |do_s: { do_s-j } / { do_s-k } / { do_s-l } / { do_s-m }| TO output.
DATA(do_en) = en_struc.
APPEND |do_en: { do_en-j } / { do_en-k } / { do_en-l } / { do_en-m }| TO output.
"Accessing structure components using the component selector
DATA(do_en_k) = en_struc-k.
APPEND |do_en_k: { do_en_k }| TO output.
DATA(do_s_m) = do_s-m.
APPEND |do_s_m: { do_s_m }| TO output.
"Assigning enumerated constants to the variable structure
do_s = en_struc.
APPEND |do_s: { do_s-j } / { do_s-k } / { do_s-l } / { do_s-m }| TO output.
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
@@ -232,7 +372,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `2) Declaring data types based on complex types` ).
output->next_section( `2) Declaring data types based on complex types` ).
"Structure and internal table types as examples for complex types
@@ -302,7 +442,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `3) Declaring reference types` ).
output->next_section( `3) Declaring reference types` ).
"Declaring reference types with static types
TYPES tr_i TYPE REF TO i.
@@ -339,7 +479,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `Declaring data objects` ).
output->next_section( `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.
@@ -437,7 +577,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `5) Declaring structures and internal tables as examples for complex types` ).
output->next_section( `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.
@@ -498,7 +638,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `6) Declaring data reference variables` ).
output->next_section( `6) Declaring data reference variables` ).
"Declaring data reference variables types with static types
DATA dref_int TYPE REF TO i.
@@ -531,7 +671,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `7) Assigning values to data objects` ).
output->next_section( `7) Assigning values to data objects` ).
"An assignment passes the content of a source to a target data object.
"Note:
@@ -635,13 +775,13 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `8) Creating data objects by inline declaration` ).
output->next_section( `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
"to derive this type completely statically.
"Note:
"- In newer ABAP releases, the FINAL declaration operator is available for creating
"- The FINAL declaration operator is available for creating
" immutable variables as shon below.
"- As shown in the previous section, there are many options for what can be placed on
" the right side.
@@ -749,7 +889,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `9) Assigning references to data reference variables` ).
output->next_section( `9) Assigning references to data reference variables` ).
"Note:
"- As is true for other data object and types, there are special assignment rules
@@ -851,7 +991,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `10) Creating anonymous data objects` ).
output->next_section( `10) Creating anonymous data objects` ).
"Anonymous data objects are a topic related to data reference variables.
"These data objects are unnamed data objects.
@@ -956,7 +1096,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `Excursions: Elementary types and type conversions` ).
output->next_section( `Excursions: Elementary types and type conversions` ).
output->display( `11) Implicit and explicit conversion` ).
@@ -1029,7 +1169,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `12) Character strings and text field strings` ).
output->next_section( `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
@@ -1046,7 +1186,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `13) Floating point numbers` ).
output->next_section( `13) Floating point numbers` ).
"The following example shows the difference between binary and decimal
"floating point numbers.
@@ -1061,7 +1201,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `14) Byte-like types` ).
output->next_section( `14) Byte-like types` ).
"The following example shows byte-like types x and xstring.
@@ -1115,11 +1255,11 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `15) Date and time` ).
output->next_section( `15) Date and time` ).
"In the example, date and time fields are assigned the current values
"using the cl_abap_context_info class. Calculations follow. The date of next
"day and the next hour are calculated.
"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
"day is calculated.
"Note: The data types behave like numeric values in the context of calculations.
"In assignments and in the output, they behave like character-like types.
"The second example shows an undesired result for a conversion of type i to d.
@@ -1128,18 +1268,12 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
"In such a case, the date field is assigned the invalid value '00000000'.
DATA: today TYPE d,
tomorrow TYPE d,
now TYPE t,
next_hour TYPE t.
today = cl_abap_context_info=>get_system_date( ).
now = cl_abap_context_info=>get_system_time( ).
tomorrow = today + 1.
next_hour = ( now + 3600 ) / 3600 * 3600.
tomorrow TYPE d.
today = cl_abap_context_info=>get_system_date( ).
tomorrow = today + 1.
output->display(
|Today: { today }\n| &&
|Now: { now }\n\n| &&
|Tommorow: { tomorrow }\n| &&
|Next Hour: { next_hour }| ).
|Today: { today }\n| &&
|Tommorow: { tomorrow }| ).
DATA date TYPE d.
date = '20240101'.
@@ -1150,7 +1284,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `16) Type conversion rules` ).
output->next_section( `16) Type conversion rules` ).
"The purpose of this example is to emphasize the conversion rules
"that should be noted when performing conversions. The example
@@ -1305,7 +1439,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `17) Excursion: RTTI` ).
output->next_section( `17) Excursion: RTTI` ).
"Using RTTI to check type compatibility
"In the following example the applies_to_data method of the RTTI class
@@ -1371,7 +1505,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `18) Constants and immutable variables` ).
output->next_section( `18) Constants and immutable variables` ).
"As mentioned above, constants cannot be changed at runtime.
CONSTANTS con_str TYPE string VALUE `hallo`.
@@ -1381,29 +1515,28 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
DATA str_w_con_as_start_value TYPE string VALUE con_underscores.
"Immutable variables
"In newer ABAP releases, comment the code in.
* FINAL(do_final_inl) = 1.
* DATA(do_data_inl) = 1 + do_final_inl.
* "not possible
* "do_final_inl = 2.
*
* SELECT * FROM zdemo_abap_carr INTO TABLE @DATA(itab_data_inl).
*
* DATA itab_like_inline LIKE itab_data_inl.
*
* "Using an inline declaration as target of a LOOP statement
* "A value is assigned multiple times, but it cannot be changed in any other
* "write positions.
* LOOP AT itab_data_inl INTO FINAL(wa_final).
*
* "The following is not possible
* "wa_final-carrid = 'd'.
* "only read access
* APPEND wa_final TO itab_like_inline.
* ENDLOOP.
*
* "SELECT statement with a an immutable target table declared inline
* SELECT * FROM zdemo_abap_carr INTO TABLE @FINAL(itab_final_inl).
FINAL(do_final_inl) = 1.
DATA(do_data_inl) = 1 + do_final_inl.
"not possible
"do_final_inl = 2.
SELECT * FROM zdemo_abap_carr INTO TABLE @DATA(itab_data_inl).
DATA itab_like_inline LIKE itab_data_inl.
"Using an inline declaration as target of a LOOP statement
"A value is assigned multiple times, but it cannot be changed in any other
"write positions.
LOOP AT itab_data_inl INTO FINAL(wa_final).
"The following is not possible
"wa_final-carrid = 'd'.
"only read access
APPEND wa_final TO itab_like_inline.
ENDLOOP.
"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 `
@@ -1411,7 +1544,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `19) Various ABAP glossary terms on data types and objects in a nutshell` ).
output->next_section( `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
@@ -1639,7 +1772,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `20) Generic ABAP types for formal parameters of methods` ).
output->next_section( `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
@@ -1681,7 +1814,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `21) Built-in data objects` ).
output->next_section( `21) Built-in data objects` ).
"This example demonstrates the availability of built-in data objects in ABAP.
@@ -1760,7 +1893,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `22) Declaration context` ).
output->next_section( `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
@@ -1806,7 +1939,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
**********************************************************************
output->display( `23) Enumerated Types and Objects` ).
output->next_section( `23) Enumerated Types and Objects` ).
"Examples for enumerated types and objects are contained in
"separate methods. Check the comments there.
@@ -1841,138 +1974,6 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
ENDMETHOD.
METHOD adapt_text.
DATA text TYPE t_pub_text_c30.
text = cl_text && comma && sy-uname && me->text.
str = text && |\n(Note: The value of me->text is "{ me->text }")|.
ENDMETHOD.
METHOD class_constructor.
"Filling demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
ENDMETHOD.
METHOD addition_with_generic_num.
result = num1 + num2.
ENDMETHOD.
METHOD enum_meth_params.
CASE char.
WHEN a.
output = a.
WHEN b.
output = b.
WHEN OTHERS.
output = `Either c or d: ` && char.
ENDCASE.
ENDMETHOD.
METHOD enum_processing.
"Read and write positions of enumerated objects
"Enumerated objects can be used in all read positions in which the operand
"type is their enumerated type.
"Likewise, enumerated variables can only be used in write positions in which
"the operand type is the enumerated type and only the associated enumerated
"values can be written.
"So, assignments are possible only from one enumerated type to the same (with one
"exception -> assignment to character-like variables of the types c and string)
DATA do_enum TYPE t_enum.
do_enum = a.
APPEND |do_enum: { do_enum }| TO output.
DATA do_enum_2 LIKE do_enum.
do_enum_2 = do_enum.
APPEND |do_enum_2: { do_enum_2 }| TO output.
"Assignment to character-like variables of the types c and string.
"In this case, the target field is assigned the name of the enumerated constant or
"the component of the enumerated structure under which the enumerated value of the
"source field is defined in the enumerated type.
DATA do_a_string TYPE string.
do_a_string = do_enum.
APPEND |do_a_string: { do_a_string }| TO output.
"Or using the CONV operator as follows
DATA(do_next_string) = CONV string( do_enum ).
APPEND |do_next_string: { do_next_string }| TO output.
"Enumerated constants are converted implicitly to the type string
"before the concatenation in the string template.
DATA(str_from_enum) = |{ a }{ b }{ c }{ d }|.
APPEND |str_from_enum: { str_from_enum }| TO output.
"Note that only the enumerated type itself is relevant. Usually, the content
"of an enumerated object is not of interest.
"The enumerated value in the base type can be accessed using the constructor
"operators CONV and EXACT only. The base type is i in this case.
DATA(conv_value) = CONV i( do_enum ).
APPEND |conv_value: { conv_value }| TO output.
"Converting the other way round.
DATA(another_conv) = CONV t_enum( 3 ).
APPEND |another_conv: { another_conv }| TO output.
"If known statically, an attempt to assign a value other than a valid enumerated value
"to an enumerated variable produces a syntax error.
"If not known statically, an exception is raised.
"The following produces a syntax error
"do_enum = f.
"The following example shows raising an exception.
DATA dobj TYPE t_enum.
TYPES t_int_tab TYPE TABLE OF i WITH EMPTY KEY.
DATA(int_tab) = VALUE t_int_tab( ( 0 ) ( 1 ) ( 2 ) ( 3 ) ( 4 ) ).
DATA str_tab TYPE TABLE OF string.
LOOP AT int_tab INTO DATA(wa_en).
TRY.
dobj = CONV t_enum( wa_en ).
APPEND dobj TO str_tab.
CATCH cx_sy_conversion_no_enum_value INTO DATA(error_enum).
APPEND error_enum->get_text( ) TO str_tab.
ENDTRY.
ENDLOOP.
APPEND `------------- START: Output for str_tab -------------` TO output.
APPEND LINES OF str_tab TO output.
APPEND `^^^^^^^^^^^^^ END: Output for str_tab ^^^^^^^^^^^^^` TO output.
"An enumerated variable can be set to the initial value of its base type
"using CLEAR.
CLEAR do_enum.
APPEND |do_enum: { do_enum }| TO output.
"Enumerated structures
DATA do_enum_s TYPE t_enum_struc.
"The enumerated structure en_struc was decalred in the public section.
"Using the addition LIKE, a second structure is created referring to the enumerated structure.
"Note that the second structure is not a constant structure.
"The components of the constant structure contain the enumerated values of the enumerated type.
"All the components of the variable structure declared by LIKE contain the initial values.
DATA do_s LIKE en_struc.
APPEND |do_s: { do_s-j } / { do_s-k } / { do_s-l } / { do_s-m }| TO output.
DATA(do_en) = en_struc.
APPEND |do_en: { do_en-j } / { do_en-k } / { do_en-l } / { do_en-m }| TO output.
"Accessing structure components using the component selector
DATA(do_en_k) = en_struc-k.
APPEND |do_en_k: { do_en_k }| TO output.
DATA(do_s_m) = do_s-m.
APPEND |do_s_m: { do_s_m }| TO output.
"Assigning enumerated constants to the variable structure
do_s = en_struc.
APPEND |do_s: { do_s-j } / { do_s-k } / { do_s-l } / { do_s-m }| TO output.
ENDMETHOD.
METHOD rtti_enum.
@@ -2022,5 +2023,4 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
REPLACE FIRST OCCURRENCE OF PCRE `/\s` IN mem_string WITH ``.
APPEND ` members:` && mem_string TO output.
ENDMETHOD.
ENDCLASS.
ENDCLASS.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -31,10 +31,6 @@
* or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* Some code sections are commented out. The syntax is only available in
* newer ABAP releases. Comment them in if you are running a newer
* ABAP release, for example, in the SAP BTP environment.
*
* 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
@@ -60,19 +56,19 @@ CLASS zcl_demo_abap_dynamic_prog DEFINITION
CLASS-METHODS:
class_constructor.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
@@ -463,12 +459,11 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DO.
"sy-index represents the position of a structure component
"NOTE: The following statement is replaced by the newer syntax that is
"commented out below. Therefore, it is recommended that you use this
"syntax in newer ABAP releases.
ASSIGN COMPONENT sy-index OF STRUCTURE <struct> TO <comp>.
"ASSIGN <struct>-(sy-index) to <comp>.
ASSIGN <struct>-(sy-index) to <comp>.
"Old syntax
"ASSIGN COMPONENT sy-index OF STRUCTURE <struct> TO <comp>.
IF sy-subrc <> 0.
"If all components are processed, the loop is exited.
@@ -959,38 +954,34 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
output->display( input = <fs_m5> name = `<fs_m5>` ).
**********************************************************************
"Note: Comment in the following example in newer ABAP releases and in the SAP BTP environment.
* output->next_section( `21) Dynamic Specifications in ASSIGN Statements (2) - Setting sy-subrc/ELSE UNASSIGN` ).
*
* "In dynamic assignments, the statement ASSIGN sets the return code sy-subrc.
* "If ELSE UNASSIGN is specified, no memory area is assigned to the field symbol. It has the state unassigned after the ASSIGN statement.
*
* DATA(attr) = VALUE string_table( ( `another_string` ) ( `public_string` ) ( `this_will_fail` ) ).
*
* LOOP AT attr INTO DATA(attribute).
*
* ASSIGN cl_ref->(attribute) TO FIELD-SYMBOL(<attr>) ELSE UNASSIGN.
* IF sy-subrc = 0.
* output->display( |Successful assignment for attribute "{ attribute }". sy-subrc = { sy-subrc }. | ).
* output->display( input = <attr> name = `<attr>` ).
* ELSE.
* output->display( |Assignment not successful for attribute "{ attribute }". sy-subrc = { sy-subrc }. | ).
* ENDIF.
*
* IF <attr> IS ASSIGNED.
* output->display( `The field symbol is assigned.` ).
* output->display( `--------------------` ).
* ELSE.
* output->display( `The field symbol is not assigned.` ).
* ENDIF.
*
* ENDLOOP.
output->next_section( `21) Dynamic Specifications in ASSIGN Statements (2) - Setting sy-subrc/ELSE UNASSIGN` ).
"In dynamic assignments, the statement ASSIGN sets the return code sy-subrc.
"If ELSE UNASSIGN is specified, no memory area is assigned to the field symbol. It has the state unassigned after the ASSIGN statement.
DATA(attr) = VALUE string_table( ( `another_string` ) ( `public_string` ) ( `this_will_fail` ) ).
LOOP AT attr INTO DATA(attribute).
ASSIGN cl_ref->(attribute) TO FIELD-SYMBOL(<attr>) ELSE UNASSIGN.
IF sy-subrc = 0.
output->display( |Successful assignment for attribute "{ attribute }". sy-subrc = { sy-subrc }. | ).
output->display( input = <attr> name = `<attr>` ).
ELSE.
output->display( |Assignment not successful for attribute "{ attribute }". sy-subrc = { sy-subrc }. | ).
ENDIF.
IF <attr> IS ASSIGNED.
output->display( `The field symbol is assigned.` ).
output->display( `--------------------` ).
ELSE.
output->display( `The field symbol is not assigned.` ).
ENDIF.
ENDLOOP.
**********************************************************************
"Note: The following code contains syntax that is only available in
"newer ABAP releases and in the SAP BTP environment. In these contexts,
"you can comment in the code.
output->next_section( `22) Dynamic Specifications in ASSIGN Statements (3) - Structure Components` ).
@@ -1002,29 +993,29 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
DATA(comp_name) = lcl_det_at_runtime=>get_dyn_field( ).
* ASSIGN wa-(comp_name) TO FIELD-SYMBOL(<fs_m6>).
*
* ASSIGN wa-('CARRNAME') TO FIELD-SYMBOL(<fs_m7>).
*
* IF sy-subrc = 0.
* DATA(subrc1) = sy-subrc.
* ENDIF.
*
* "No exception occurs in case of an unsuccessful assignment.
* ASSIGN wa-('CRRNM') TO FIELD-SYMBOL(<fs_m8>).
*
* IF sy-subrc <> 0.
* DATA(subrc2) = sy-subrc.
* ENDIF.
*
* "Numeric expressions are possible. Its value is interpreted as the position
* "of the component in the structure.
* ASSIGN wa-(4) TO FIELD-SYMBOL(<fs_m9>).
*
* "If the value is 0, the memory area of the entire structure is assigned to the field symbol.
* ASSIGN wa-(0) TO FIELD-SYMBOL(<fs_m10>).
ASSIGN wa-(comp_name) TO FIELD-SYMBOL(<fs_m6>).
"The above statements replace the following syntax
ASSIGN wa-('CARRNAME') TO FIELD-SYMBOL(<fs_m7>).
IF sy-subrc = 0.
DATA(subrc1) = sy-subrc.
ENDIF.
"No exception occurs in case of an unsuccessful assignment.
ASSIGN wa-('CRRNM') TO FIELD-SYMBOL(<fs_m8>).
IF sy-subrc <> 0.
DATA(subrc2) = sy-subrc.
ENDIF.
"Numeric expressions are possible. Its value is interpreted as the position
"of the component in the structure.
ASSIGN wa-(4) TO FIELD-SYMBOL(<fs_m9>).
"If the value is 0, the memory area of the entire structure is assigned to the field symbol.
ASSIGN wa-(0) TO FIELD-SYMBOL(<fs_m10>).
"Old syntax
ASSIGN COMPONENT 'CARRID' OF STRUCTURE wa TO FIELD-SYMBOL(<fs_m11>).
ASSIGN COMPONENT 5 OF STRUCTURE wa TO FIELD-SYMBOL(<fs_m12>).
@@ -1034,12 +1025,12 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
ASSIGN ref_m->('CARRNAME') TO FIELD-SYMBOL(<fs_m13>).
* output->display( input = <fs_m6> name = `<fs_m6>` ).
* output->display( input = <fs_m7> name = `<fs_m7>` ).
* output->display( input = subrc1 name = `subrc1` ).
* output->display( input = subrc2 name = `subrc2` ).
* output->display( input = <fs_m9> name = `<fs_m9>` ).
* output->display( input = <fs_m10> name = `<fs_m10>` ).
output->display( input = <fs_m6> name = `<fs_m6>` ).
output->display( input = <fs_m7> name = `<fs_m7>` ).
output->display( input = subrc1 name = `subrc1` ).
output->display( input = subrc2 name = `subrc2` ).
output->display( input = <fs_m9> name = `<fs_m9>` ).
output->display( input = <fs_m10> name = `<fs_m10>` ).
output->display( input = <fs_m11> name = `<fs_m11>` ).
output->display( input = <fs_m12> name = `<fs_m12>` ).
output->display( input = <fs_m13> name = `<fs_m13>` ).
@@ -2111,4 +2102,4 @@ CLASS zcl_demo_abap_dynamic_prog IMPLEMENTATION.
output->display( input = ref_tab->* name = `ref_tab->*` ).
ENDMETHOD.
ENDCLASS.
ENDCLASS.

View File

@@ -40,7 +40,7 @@ CLASS lcl_det_at_runtime DEFINITION.
get_dyn_class_meth EXPORTING cl TYPE string
meth TYPE string
ptab TYPE abap_parmbind_tab,
get_dyn_syntax_elements RETURNING VALUE(syntax_elements) TYPE struc_dyn,
get_dyn_syntax_elements RETURNING VALUE(syntax_elements) TYPE struc_dyn,
fill_string.
PROTECTED SECTION.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -35,7 +35,7 @@ ENDCLASS.
CLASS zcl_demo_abap_flight_tables IMPLEMENTATION.
CLASS ZCL_DEMO_ABAP_FLIGHT_TABLES IMPLEMENTATION.
METHOD clear_dbtabs.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -12,26 +12,26 @@
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* topic in the ABAP Keyword Documentation.
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -110,12 +110,16 @@ protected section.
ENDCLASS.
CLASS ZCL_DEMO_ABAP_INTERNAL_TABLES IMPLEMENTATION.
METHOD class_constructor.
fill_dbtabs( ).
ENDMETHOD.
METHOD fill_dbtabs.
"Initializing and filling of database tables to have data to work with
@@ -137,6 +141,7 @@ CLASS ZCL_DEMO_ABAP_INTERNAL_TABLES IMPLEMENTATION.
ENDMETHOD.
METHOD fill_itabs_for_corresponding.
tab1 = VALUE #( ( a = 1 b = 'aaa' c = 'aaa' d = 'A' )
( a = 2 b = 'bbb' c = 'bbb' d = 'B' ) ).
@@ -177,6 +182,7 @@ CLASS ZCL_DEMO_ABAP_INTERNAL_TABLES IMPLEMENTATION.
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
@@ -227,7 +233,7 @@ CLASS ZCL_DEMO_ABAP_INTERNAL_TABLES IMPLEMENTATION.
output->display( input = it_so name = `it_so` ).
**********************************************************************
output->next_section( `3) Adding mutliple lines of an internal table to` &&
` another one` ).
@@ -263,7 +269,7 @@ CLASS ZCL_DEMO_ABAP_INTERNAL_TABLES IMPLEMENTATION.
output->display( input = it_st name = `it_st` ).
**********************************************************************
**********************************************************************
output->next_section( `5) Inserting lines of an internal table` &&
` into another one at a specific position` ).
@@ -425,6 +431,10 @@ CLASS ZCL_DEMO_ABAP_INTERNAL_TABLES IMPLEMENTATION.
output->display( input = tab1 name = `tab1` ).
**********************************************************************
output->next_section( `11g) ... excluding components and using MAPPING` ).
"EXCEPT * means that all components remain initial not specified
"for mapping
tab1 = CORRESPONDING #( tab2 MAPPING d = f EXCEPT * ).
@@ -1691,7 +1701,7 @@ CLASS ZCL_DEMO_ABAP_INTERNAL_TABLES IMPLEMENTATION.
"the internal table.
DATA(it_str) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ).
it_str = VALUE #( ).
it_str = VALUE #( ).
output->display( input = it_st name = `it_st` ).
output->display( input = it_st2 name = `it_st2` ).

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -20,26 +20,26 @@
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* topic in the ABAP Keyword Documentation.
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -81,18 +81,21 @@ ENDCLASS.
CLASS zcl_demo_abap_objects IMPLEMENTATION.
CLASS ZCL_DEMO_ABAP_OBJECTS IMPLEMENTATION.
METHOD hallo_instance_method.
string = |Hallo { sy-uname }. | &&
|I'm an instance method of class zcl_demo_abap_objects.|.
ENDMETHOD.
METHOD hallo_static_method.
string = |Hallo { sy-uname }. | &&
|I'm a static method of class zcl_demo_abap_objects.|.
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
@@ -126,7 +129,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
output->display( `One or more of the declared reference ` &&
`variables are not initial.` ).
ENDIF.
**********************************************************************
output->next_section( `2) Creating objects` ).
@@ -157,7 +160,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
output->display( `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` ).
@@ -177,7 +180,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
ELSE.
output->display( `ref3b has not been assigned to ref3a.` ).
ENDIF.
**********************************************************************
output->next_section( `4) Overwriting object references` ).
@@ -197,7 +200,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
ref4 = NEW #( ).
output->display( input = ref4->no_of_instances name = `ref4->no_of_instances` ).
**********************************************************************
output->next_section( `5) Keeping references variables in internal tables` ).
@@ -219,7 +222,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
ENDDO.
output->display( input = itab5 name = `itab5` ).
**********************************************************************
output->next_section( `6) Clearing object references` ).
@@ -241,7 +244,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
ELSE.
output->display( `ref6 is not initial.` ).
ENDIF.
**********************************************************************
output->next_section( `7) Accessing and using attributes` ).
@@ -271,7 +274,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
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` ).
**********************************************************************
output->next_section( `8) Calling static and instance methods` ).
@@ -307,7 +310,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
hallo_static_method( ).
output->display( input = string name = `string` ).
**********************************************************************
output->next_section( `9) Calling methods: Examples` &&
@@ -353,7 +356,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
lcl_demo=>addition_optional( i_add_mand = 1 ).
output->display( input = lcl_demo=>calc_result name = `lcl_demo=>calc_result` ).
**********************************************************************
output->next_section( `10) Calling methods: Examples ` &&
@@ -381,7 +384,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
output->display( input = hallo name = `hallo` ).
output->display( input = subtraction_result name = `subtraction_result` ).
**********************************************************************
output->next_section( `11) Calling methods: Example with changing parameter` ).
@@ -395,7 +398,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
lcl_demo=>square_root( CHANGING i_sqr = num ).
output->display( input = num name = `num` ).
**********************************************************************
output->next_section( `12) Calling methods: Examples with returning parameters` ).
@@ -459,7 +462,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
output->display( input = random_no1 name = `random_no1` ).
output->display( input = random_no2 name = `random_no2` ).
output->display( input = random_no3 name = `random_no3` ).
**********************************************************************
output->next_section( `13) Calling methods: Examples with error handling` ).
@@ -501,7 +504,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
ENDTRY.
output->display( input = greets name = `greets` ).
**********************************************************************
output->next_section( `14) Constructors` ).
@@ -553,7 +556,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
output->display( input = lcl_constructors=>stat_text name = `lcl_constructors=>stat_text` ).
output->display( input = lcl_constructors=>stat_number name = `lcl_constructors=>stat_number` ).
**********************************************************************
output->next_section( `15) Parameters: Generic types` ).
@@ -593,7 +596,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
lcl_demo=>generic_tab( EXPORTING i_anytab = c_tab ).
output->display( input = lcl_demo=>some_data->* name = `lcl_demo=>some_data->*` ).
**********************************************************************
output->next_section( `16) Inheritance: Method redefinition` ).
@@ -624,7 +627,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
output->display( input = first_string name = `first_string` ).
output->display( input = second_string name = `second_string` ).
output->display( input = third_string name = `third_string` ).
**********************************************************************
output->next_section( `17) Polymorphism and Casting` ).
@@ -875,7 +878,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
output->display( input = intf_const1 name = `intf_const1` ).
output->display( input = intf_const2 name = `intf_const2` ).
output->display( input = intf_const3 name = `intf_const3` ).
**********************************************************************
output->next_section( `20) Singleton` ).
@@ -923,7 +926,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
output->display( input = timestamp name = `timestamp` ).
output->display( input = no_of_instances name = `no_of_instances` ).
**********************************************************************
output->next_section( `21) Factory method in an abstract class` ).
@@ -958,7 +961,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
ENDTRY.
output->display( input = lcl_abstract=>message name = `lcl_abstract=>message` ).
**********************************************************************
output->next_section( `22) Friendship: Accessing components of friends` ).
@@ -977,7 +980,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
DATA(string_table) = zcl_demo_abap_objects_friend=>get_strings( ).
output->display( input = string_table name = `string_table` ).
**********************************************************************
output->next_section( `23) Self-reference me` ).
@@ -997,7 +1000,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
output->display( input = string_without_me name = `string_without_me` ).
output->display( input = string_with_me name = `string_with_me` ).
**********************************************************************
output->next_section( `24) Events` ).

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -5,13 +5,13 @@
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -23,11 +23,15 @@
PUBLIC SECTION.
CLASS-METHODS get_strings RETURNING VALUE(res_string) TYPE string_table.
protected section.
private section.
ENDCLASS.
CLASS ZCL_DEMO_ABAP_OBJECTS_FRIEND IMPLEMENTATION.
METHOD get_strings.
"Getting the strings and adding them to the string table.
"Accessing an attribute in a public visibility section.
@@ -39,5 +43,4 @@ CLASS ZCL_DEMO_ABAP_OBJECTS_FRIEND IMPLEMENTATION.
"Accessing an attribute in a private visibility section.
APPEND zcl_demo_abap_objects=>private_string TO res_string.
ENDMETHOD.
ENDCLASS.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -16,26 +16,26 @@
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* topic in the ABAP Keyword Documentation.
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -50,6 +50,7 @@ CLASS zcl_demo_abap_prog_flow_logic DEFINITION
PUBLIC SECTION.
INTERFACES: if_oo_adt_classrun.
protected section.
PRIVATE SECTION.
"Structured type for calculation example
@@ -98,7 +99,118 @@ CLASS zcl_demo_abap_prog_flow_logic DEFINITION
ENDCLASS.
CLASS zcl_demo_abap_prog_flow_logic IMPLEMENTATION.
CLASS ZCL_DEMO_ABAP_PROG_FLOW_LOGIC IMPLEMENTATION.
METHOD addition.
res = num1 + num2.
ENDMETHOD.
METHOD calc.
DATA calc_if TYPE string.
DATA calc_case TYPE string.
DATA calc_cond TYPE string.
DATA calc_switch TYPE string.
"IF statements
IF operator = `+`.
calc_if = num1 + num2.
ELSEIF operator = `-`.
calc_if = num1 - num2.
ELSEIF operator = `*`.
calc_if = num1 * num2.
ELSEIF operator = `/`.
IF num2 = 0.
calc_if = `Division by 0`.
ELSE.
calc_if = num1 / num2.
ENDIF.
ELSE.
calc_if = |Check the operator { operator }.|.
ENDIF.
prep_calc_result( CHANGING res = calc_if ).
"CASE
CASE operator.
WHEN '+'.
calc_case = num1 + num2.
WHEN '-'.
calc_case = num1 - num2.
WHEN '*'.
calc_case = num1 * num2.
WHEN '/'.
CASE num2.
WHEN 0.
calc_case = `Division by 0`.
WHEN OTHERS.
calc_case = num1 / num2.
ENDCASE.
WHEN OTHERS.
calc_case = |Check the operator { operator }.|.
ENDCASE.
prep_calc_result( CHANGING res = calc_case ).
"COND
calc_cond = COND #( WHEN operator = '+'
THEN num1 + num2
WHEN operator = '-'
THEN num1 - num2
WHEN operator = '*'
THEN num1 * num2
WHEN operator = '/' AND num2 = 0 THEN `Division by 0`
WHEN operator = '/' AND num2 <> 0 THEN num1 / num2
ELSE |Check the operator { operator }.|
).
prep_calc_result( CHANGING res = calc_cond ).
"SWITCH
calc_switch = SWITCH #( operator
WHEN '+' THEN num1 + num2
WHEN '-' THEN num1 - num2
WHEN '*' THEN num1 * num2
WHEN '/' THEN SWITCH #( num2 WHEN 0 THEN `Division by 0` ELSE num1 / num2 )
ELSE |Check the operator { operator }.| ).
prep_calc_result( CHANGING res = calc_switch ).
res = VALUE #( calculation = |{ num1 } { operator } { num2 }|
res_if = calc_if
res_case = calc_case
res_cond = calc_cond
res_switch = calc_switch
).
ENDMETHOD.
METHOD check_is_supplied.
IF num1 IS SUPPLIED.
APPEND `num1 is supplied` TO res.
ELSE.
APPEND `num1 is not supplied` TO res.
ENDIF.
IF num2 IS NOT SUPPLIED.
APPEND `num2 is not supplied` TO res.
ELSE.
APPEND `num2 is supplied` TO res.
ENDIF.
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
@@ -113,7 +225,7 @@ CLASS zcl_demo_abap_prog_flow_logic IMPLEMENTATION.
"Simple control structure realized by an IF ... ELSEIF ... ELSE ... ENDIF.
"statement. Multiple statement blocks can be included, of which only 1 is
"executed at most and depending on conditions.
"Determining some operators for a calculation
DATA(operators) = VALUE string_table( ( `+` ) ( `-` ) ( `?` ) ).
@@ -1223,111 +1335,6 @@ CLASS zcl_demo_abap_prog_flow_logic IMPLEMENTATION.
ENDMETHOD.
METHOD check_is_supplied.
IF num1 IS SUPPLIED.
APPEND `num1 is supplied` TO res.
ELSE.
APPEND `num1 is not supplied` TO res.
ENDIF.
IF num2 IS NOT SUPPLIED.
APPEND `num2 is not supplied` TO res.
ELSE.
APPEND `num2 is supplied` TO res.
ENDIF.
ENDMETHOD.
METHOD addition.
res = num1 + num2.
ENDMETHOD.
METHOD calc.
DATA calc_if TYPE string.
DATA calc_case TYPE string.
DATA calc_cond TYPE string.
DATA calc_switch TYPE string.
"IF statements
IF operator = `+`.
calc_if = num1 + num2.
ELSEIF operator = `-`.
calc_if = num1 - num2.
ELSEIF operator = `*`.
calc_if = num1 * num2.
ELSEIF operator = `/`.
IF num2 = 0.
calc_if = `Division by 0`.
ELSE.
calc_if = num1 / num2.
ENDIF.
ELSE.
calc_if = |Check the operator { operator }.|.
ENDIF.
prep_calc_result( CHANGING res = calc_if ).
"CASE
CASE operator.
WHEN '+'.
calc_case = num1 + num2.
WHEN '-'.
calc_case = num1 - num2.
WHEN '*'.
calc_case = num1 * num2.
WHEN '/'.
CASE num2.
WHEN 0.
calc_case = `Division by 0`.
WHEN OTHERS.
calc_case = num1 / num2.
ENDCASE.
WHEN OTHERS.
calc_case = |Check the operator { operator }.|.
ENDCASE.
prep_calc_result( CHANGING res = calc_case ).
"COND
calc_cond = COND #( WHEN operator = '+'
THEN num1 + num2
WHEN operator = '-'
THEN num1 - num2
WHEN operator = '*'
THEN num1 * num2
WHEN operator = '/' AND num2 = 0 THEN `Division by 0`
WHEN operator = '/' AND num2 <> 0 THEN num1 / num2
ELSE |Check the operator { operator }.|
).
prep_calc_result( CHANGING res = calc_cond ).
"SWITCH
calc_switch = SWITCH #( operator
WHEN '+' THEN num1 + num2
WHEN '-' THEN num1 - num2
WHEN '*' THEN num1 * num2
WHEN '/' THEN SWITCH #( num2 WHEN 0 THEN `Division by 0` ELSE num1 / num2 )
ELSE |Check the operator { operator }.| ).
prep_calc_result( CHANGING res = calc_switch ).
res = VALUE #( calculation = |{ num1 } { operator } { num2 }|
res_if = calc_if
res_case = calc_case
res_cond = calc_cond
res_switch = calc_switch
).
ENDMETHOD.
METHOD meth_with_return.
@@ -1341,6 +1348,36 @@ CLASS zcl_demo_abap_prog_flow_logic IMPLEMENTATION.
ENDMETHOD.
METHOD power2_and_sqrt.
result = |Calculation result:\n{ num } powered by 2 = { ipow( base = num exp = 2 ) }\nSquare root of { num } = { sqrt( num ) }|.
ENDMETHOD.
METHOD prep_calc_result.
FIND PCRE `-$` IN res. "trailing minus
IF sy-subrc = 0.
SHIFT res BY 1 PLACES RIGHT CIRCULAR.
ENDIF.
"trailing .0
IF res CP `*.0*`.
SHIFT res RIGHT DELETING TRAILING ` `.
SHIFT res LEFT DELETING LEADING ` `.
FIND PCRE `\.0$` IN res.
IF sy-subrc = 0.
REPLACE `.0` IN res WITH ``.
ENDIF.
ENDIF.
ENDMETHOD.
METHOD validate_email.
IF matches( val = email
@@ -1363,32 +1400,4 @@ CLASS zcl_demo_abap_prog_flow_logic IMPLEMENTATION.
ENDIF.
ENDMETHOD.
METHOD power2_and_sqrt.
result = |Calculation result:\n{ num } powered by 2 = { ipow( base = num exp = 2 ) }\nSquare root of { num } = { sqrt( num ) }|.
ENDMETHOD.
METHOD prep_calc_result.
FIND PCRE `-$` IN res. "trailing minus
IF sy-subrc = 0.
SHIFT res BY 1 PLACES RIGHT CIRCULAR.
ENDIF.
"trailing .0
IF res CP `*.0*`.
SHIFT res RIGHT DELETING TRAILING ` `.
SHIFT res LEFT DELETING LEADING ` `.
FIND PCRE `\.0$` IN res.
IF sy-subrc = 0.
REPLACE `.0` IN res WITH ``.
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -85,13 +85,13 @@
*
* 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
* 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.
*

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -45,13 +45,13 @@
*
* 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
* 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.
*
@@ -903,65 +903,65 @@ CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_M IMPLEMENTATION.
*
**********************************************************************
* output->next_section( `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,
* read_dyn_result TYPE TABLE FOR READ RESULT zdemo_abap_rap_ro_m,
* rba_dyn TYPE TABLE FOR READ IMPORT
* zdemo_abap_rap_ro_m\_child,
* rba_dyn_result TYPE TABLE FOR READ RESULT
* zdemo_abap_rap_ro_m\_child,
* rba_dyn_link TYPE TABLE FOR READ LINK zdemo_abap_rap_ro_m\_child.
*
* read_dyn = VALUE #(
* ( %key-key_field = 1
* %control = VALUE #(
* field1 = if_abap_behv=>mk-on
* field2 = if_abap_behv=>mk-on
* field3 = if_abap_behv=>mk-on
* field4 = if_abap_behv=>mk-on ) )
* ( %key-key_field = 2
* %control = VALUE #(
* field1 = if_abap_behv=>mk-on
* field2 = if_abap_behv=>mk-on
* field3 = if_abap_behv=>mk-on
* field4 = if_abap_behv=>mk-on ) ) ).
*
* rba_dyn = VALUE #(
* ( %key-key_field = 1
* %control = VALUE #(
* key_ch = if_abap_behv=>mk-on
* field_ch1 = if_abap_behv=>mk-on
* field_ch2 = if_abap_behv=>mk-on ) )
* ( %key-key_field = 2
* %control = VALUE #(
* key_ch = if_abap_behv=>mk-on
* field_ch1 = if_abap_behv=>mk-on
* field_ch2 = if_abap_behv=>mk-on ) ) ).
*
* op_tab = VALUE #(
* ( op = if_abap_behv=>op-r-read
* entity_name = 'ZDEMO_ABAP_RAP_RO_M'
* instances = REF #( read_dyn )
* results = REF #( read_dyn_result ) )
* ( op = if_abap_behv=>op-r-read_ba
* entity_name = 'ZDEMO_ABAP_RAP_RO_M'
* sub_name = '_CHILD'
* full = abap_true
* instances = REF #( rba_dyn )
* results = REF #( rba_dyn_result )
* links = REF #( rba_dyn_link ) ) ).
*
* 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` ).
output->next_section( `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,
read_dyn_result TYPE TABLE FOR READ RESULT zdemo_abap_rap_ro_m,
rba_dyn TYPE TABLE FOR READ IMPORT
zdemo_abap_rap_ro_m\_child,
rba_dyn_result TYPE TABLE FOR READ RESULT
zdemo_abap_rap_ro_m\_child,
rba_dyn_link TYPE TABLE FOR READ LINK zdemo_abap_rap_ro_m\_child.
read_dyn = VALUE #(
( %key-key_field = 1
%control = VALUE #(
field1 = if_abap_behv=>mk-on
field2 = if_abap_behv=>mk-on
field3 = if_abap_behv=>mk-on
field4 = if_abap_behv=>mk-on ) )
( %key-key_field = 2
%control = VALUE #(
field1 = if_abap_behv=>mk-on
field2 = if_abap_behv=>mk-on
field3 = if_abap_behv=>mk-on
field4 = if_abap_behv=>mk-on ) ) ).
rba_dyn = VALUE #(
( %key-key_field = 1
%control = VALUE #(
key_ch = if_abap_behv=>mk-on
field_ch1 = if_abap_behv=>mk-on
field_ch2 = if_abap_behv=>mk-on ) )
( %key-key_field = 2
%control = VALUE #(
key_ch = if_abap_behv=>mk-on
field_ch1 = if_abap_behv=>mk-on
field_ch2 = if_abap_behv=>mk-on ) ) ).
op_tab = VALUE #(
( op = if_abap_behv=>op-r-read
entity_name = 'ZDEMO_ABAP_RAP_RO_M'
instances = REF #( read_dyn )
results = REF #( read_dyn_result ) )
( op = if_abap_behv=>op-r-read_ba
entity_name = 'ZDEMO_ABAP_RAP_RO_M'
sub_name = '_CHILD'
full = abap_true
instances = REF #( rba_dyn )
results = REF #( rba_dyn_result )
links = REF #( rba_dyn_link ) ) ).
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` ).
ENDMETHOD.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -49,13 +49,13 @@
*
* 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
* 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.
*
@@ -90,12 +90,16 @@ protected section.
ENDCLASS.
CLASS zcl_demo_abap_rap_ext_num_u IMPLEMENTATION.
CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION.
METHOD class_constructor.
initialize_dbtabs( ).
ENDMETHOD.
METHOD extract_from_failed.
CLEAR errors.
@@ -983,95 +987,93 @@ CLASS zcl_demo_abap_rap_ext_num_u IMPLEMENTATION.
* Excursion: Read and read-by-association operation using dynamic
* EML statements
*
* Notes:
* - If the parameter for FULL is not flagged, only the association
* links are returned. The parameter for RESULT will be empty.
* - Remove the commented out section if you are at least on ABAP
* version 756 in your on-premise system.
* Note:
* If the parameter for FULL is not flagged, only the association
* links are returned. The parameter for RESULT will be empty.
**********************************************************************
* output->next_section( `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,
* read_dyn_result TYPE TABLE FOR READ RESULT zdemo_abap_rap_ro_u,
* rba_dyn TYPE TABLE FOR READ IMPORT
* zdemo_abap_rap_ro_u\_child,
* rba_dyn_result TYPE TABLE FOR READ RESULT
* zdemo_abap_rap_ro_u\_child,
* rba_dyn_link TYPE TABLE FOR READ LINK zdemo_abap_rap_ro_u\_child.
*
* read_dyn = VALUE #(
* ( %key-key_field = 1
* %control = VALUE #(
* field1 = if_abap_behv=>mk-on
* field2 = if_abap_behv=>mk-on
* field3 = if_abap_behv=>mk-on
* field4 = if_abap_behv=>mk-on ) )
* ( %key-key_field = 2
* %control = VALUE #(
* field1 = if_abap_behv=>mk-on
* field2 = if_abap_behv=>mk-on
* field3 = if_abap_behv=>mk-on
* field4 = if_abap_behv=>mk-on ) ) ).
*
* rba_dyn = VALUE #(
* ( %key-key_field = 1
* %control = VALUE #(
* key_ch = if_abap_behv=>mk-on
* field_ch1 = if_abap_behv=>mk-on
* field_ch2 = if_abap_behv=>mk-on ) )
* ( %key-key_field = 2
* %control = VALUE #(
* key_ch = if_abap_behv=>mk-on
* field_ch1 = if_abap_behv=>mk-on
* field_ch2 = if_abap_behv=>mk-on ) ) ).
*
* output->display( `Result if FULL parameter is ` &&
* `not flagged for RBA` ).
*
* op_tab = VALUE #(
* ( op = if_abap_behv=>op-r-read
* entity_name = 'ZDEMO_ABAP_RAP_RO_U'
* instances = REF #( read_dyn )
* results = REF #( read_dyn_result ) )
* ( op = if_abap_behv=>op-r-read_ba
* entity_name = 'ZDEMO_ABAP_RAP_RO_U'
* sub_name = '_CHILD'
* full = abap_false
* instances = REF #( rba_dyn )
* results = REF #( rba_dyn_result )
* links = REF #( rba_dyn_link ) ) ).
*
* 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 ` &&
* `flagged for RBA` ).
*
* op_tab = VALUE #(
* ( op = if_abap_behv=>op-r-read
* entity_name = 'ZDEMO_ABAP_RAP_RO_U'
* instances = REF #( read_dyn )
* results = REF #( read_dyn_result ) )
* ( op = if_abap_behv=>op-r-read_ba
* entity_name = 'ZDEMO_ABAP_RAP_RO_U'
* sub_name = '_CHILD'
* full = abap_true
* instances = REF #( rba_dyn )
* results = REF #( rba_dyn_result )
* links = REF #( rba_dyn_link ) ) ).
*
* 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->next_section( `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,
read_dyn_result TYPE TABLE FOR READ RESULT zdemo_abap_rap_ro_u,
rba_dyn TYPE TABLE FOR READ IMPORT
zdemo_abap_rap_ro_u\_child,
rba_dyn_result TYPE TABLE FOR READ RESULT
zdemo_abap_rap_ro_u\_child,
rba_dyn_link TYPE TABLE FOR READ LINK zdemo_abap_rap_ro_u\_child.
read_dyn = VALUE #(
( %key-key_field = 1
%control = VALUE #(
field1 = if_abap_behv=>mk-on
field2 = if_abap_behv=>mk-on
field3 = if_abap_behv=>mk-on
field4 = if_abap_behv=>mk-on ) )
( %key-key_field = 2
%control = VALUE #(
field1 = if_abap_behv=>mk-on
field2 = if_abap_behv=>mk-on
field3 = if_abap_behv=>mk-on
field4 = if_abap_behv=>mk-on ) ) ).
rba_dyn = VALUE #(
( %key-key_field = 1
%control = VALUE #(
key_ch = if_abap_behv=>mk-on
field_ch1 = if_abap_behv=>mk-on
field_ch2 = if_abap_behv=>mk-on ) )
( %key-key_field = 2
%control = VALUE #(
key_ch = if_abap_behv=>mk-on
field_ch1 = if_abap_behv=>mk-on
field_ch2 = if_abap_behv=>mk-on ) ) ).
output->display( `Result if FULL parameter is ` &&
`not flagged for RBA` ).
op_tab = VALUE #(
( op = if_abap_behv=>op-r-read
entity_name = 'ZDEMO_ABAP_RAP_RO_U'
instances = REF #( read_dyn )
results = REF #( read_dyn_result ) )
( op = if_abap_behv=>op-r-read_ba
entity_name = 'ZDEMO_ABAP_RAP_RO_U'
sub_name = '_CHILD'
full = abap_false
instances = REF #( rba_dyn )
results = REF #( rba_dyn_result )
links = REF #( rba_dyn_link ) ) ).
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 ` &&
`flagged for RBA` ).
op_tab = VALUE #(
( op = if_abap_behv=>op-r-read
entity_name = 'ZDEMO_ABAP_RAP_RO_U'
instances = REF #( read_dyn )
results = REF #( read_dyn_result ) )
( op = if_abap_behv=>op-r-read_ba
entity_name = 'ZDEMO_ABAP_RAP_RO_U'
sub_name = '_CHILD'
full = abap_true
instances = REF #( rba_dyn )
results = REF #( rba_dyn_result )
links = REF #( rba_dyn_link ) ) ).
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` ).
ENDMETHOD.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -12,26 +12,26 @@
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* topic in the ABAP Keyword Documentation.
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -61,13 +61,15 @@ 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( ).
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
@@ -1588,6 +1590,7 @@ CLASS zcl_demo_abap_sql IMPLEMENTATION.
ENDMETHOD.
METHOD select_from_dbtab.
SELECT *
FROM zdemo_abap_carr

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -9,26 +9,26 @@
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* topic in the ABAP Keyword Documentation.
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -56,7 +56,7 @@ ENDCLASS.
CLASS zcl_demo_abap_sql_group_by IMPLEMENTATION.
CLASS ZCL_DEMO_ABAP_SQL_GROUP_BY IMPLEMENTATION.
METHOD class_constructor.
@@ -75,7 +75,7 @@ CLASS zcl_demo_abap_sql_group_by IMPLEMENTATION.
FROM zdemo_abap_flsch
INTO TABLE @DATA(fli_tab).
output->next_section( `1) Representative Binding` ).
output->display( `1) Representative Binding` ).
output->display( `1a) Grouping by one column` ).
LOOP AT fli_tab INTO wa

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -13,26 +13,26 @@
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* topic in the ABAP Keyword Documentation.
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -51,7 +51,10 @@ CLASS zcl_demo_abap_string_proc DEFINITION
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
CLASS ZCL_DEMO_ABAP_STRING_PROC IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
@@ -142,12 +145,14 @@ CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
"The expression must be convertible to a string. A blank (not
"within the curly brackets) means a blank in the resulting string.
DATA(str_c1) = `Hallo`. "String created with backquotes
DATA(str_c2) = `how`. "Strings created with pipes
DATA(str_c1) = `Hallo`.
DATA(str_c2) = `how`.
DATA(str_c3) = `are`.
DATA(str_c4) = |{ str_c1 } { sy-uname }, | &&
|{ str_c2 } { str_c3 } you?|.
output->display( input = str_c4 name = `str_c4` ).
**********************************************************************
output->next_section( `3b) String Templates (2): Control Characters` ).
@@ -157,7 +162,6 @@ CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
DATA(str_c5) = |{ str_c1 }\n{ sy-uname },| &&
|\n{ str_c2 }\n{ str_c3 }\nyou?|.
output->display( input = str_c4 name = `str_c4` ).
output->display( input = str_c5 name = `str_c5` ).
"Excursion: Class CL_ABAP_CHAR_UTILITIES provides attributes and methods as utilities for string processing.
@@ -175,7 +179,7 @@ CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
output->display( input = str_c6 name = `str_c6` ).
output->display( input = str_c7 name = `str_c7` ).
output->display( input = str_c8 name = `str_c8` ).
output->display( input = str_c9 name = `str_c9` ).
output->display( input = str_c9 name = `str_c9` ).
**********************************************************************
@@ -1752,4 +1756,4 @@ CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
output->display( input = str_tab_reg_find name = `str_tab_reg_find` ).
ENDMETHOD.
ENDCLASS.
ENDCLASS.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -13,26 +13,26 @@
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* topic in the ABAP Keyword Documentation.
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -108,7 +108,41 @@ protected section.
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( ).
ENDMETHOD.
METHOD fill_deep_structures.
"Clearing all content of gs_deep2
CLEAR gs_deep2.
"Filling nested tables in deep structures
gs_deep2-substruc = VALUE #( comp1 = `aaa`
comp2 = `bbb`
comp3 = `ccc` ).
gs_deep1-itab = VALUE #(
( col1 = 111 col2 = 222 )
( col1 = 333 col2 = 444
) ).
gs_deep2-itab = VALUE #(
( col2 = 1 col3 = 2 col4 = 3 )
( col2 = 4 col3 = 5 col4 = 6 )
( col2 = 7 col3 = 8 col4 = 9 )
).
"Filling individual component that is not shared by both structures
gs_deep2-comp4 = 999.
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
@@ -1116,40 +1150,12 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
ENDMETHOD.
METHOD class_constructor.
initialize_dbtabs( ).
fill_deep_structures( ).
"Filling demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
ENDMETHOD.
METHOD fill_deep_structures.
"Clearing all content of gs_deep2
CLEAR gs_deep2.
"Filling nested tables in deep structures
gs_deep2-substruc = VALUE #( comp1 = `aaa`
comp2 = `bbb`
comp3 = `ccc` ).
gs_deep1-itab = VALUE #(
( col1 = 111 col2 = 222 )
( col1 = 333 col2 = 444
) ).
gs_deep2-itab = VALUE #(
( col2 = 1 col3 = 2 col4 = 3 )
( col2 = 4 col3 = 5 col4 = 6 )
( col2 = 7 col3 = 8 col4 = 9 )
).
"Filling individual component that is not shared by both structures
gs_deep2-comp4 = 999.
ENDMETHOD.
METHOD initialize_dbtabs.
DELETE FROM zdemo_abap_tab1.
ENDMETHOD.
METHOD select_from_dbtab.
SELECT FROM zdemo_abap_tab1
@@ -1159,4 +1165,4 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
INTO TABLE @gt_tab.
ENDMETHOD.
ENDCLASS.
ENDCLASS.

View File

@@ -9,7 +9,7 @@
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>

View File

@@ -17,7 +17,7 @@
* and can be evaluated. The Failure Trace section provides information
* on errors found.
* - If you are interested in test coverage, you can choose
* Ctrl/Cmd + Shift + F11, or make a right-click, choose Run as ->
* Ctrl/Cmd + Shift + F11, or make a right-click, choose Run as ->
* ABAP Unit Test With..., select the Coverage checkbox and choose
* Execute. You can then check the results in the ABAP Coverage tab,
* what code is tested and what not.
@@ -39,13 +39,13 @@
* ----------------------------- NOTE -----------------------------------
* 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
* 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.
*
@@ -165,7 +165,338 @@ PRIVATE SECTION.
ENDCLASS.
CLASS zcl_demo_abap_unit_test IMPLEMENTATION.
CLASS ZCL_DEMO_ABAP_UNIT_TEST IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
"Preparing a demo database table for this example (get_sum method)
DELETE FROM zdemo_abap_tab1.
INSERT zdemo_abap_tab1 FROM @(
VALUE #( key_field = 1 char1 = 'aaa' char2 = 'bbb' num1 = 25 num2 = 75 ) ).
ENDMETHOD.
METHOD constructor.
"For demonstrating the back door injection
data_provider_local_itf = NEW lcl_data_prov_local_itf( ).
"For demonstrating the constructor injection
IF iref_data_prov IS BOUND.
"Note: The parameter is only bound when you run the unit test.
"When you run the unit test and you debug, you will see that iref_data_prov
"has a type reference to LTD_TEST_DATA_GLOBAL_INTF.
data_provider_global_itf = iref_data_prov.
ELSE.
data_provider_global_itf = NEW lcl_data_prov_glo_itf( ).
ENDIF.
"Object creation for the method call in the get_occ_rate_setter_inj method
data_provider_setter_inj = NEW lcl_data_prov_glo_itf( ).
ENDMETHOD.
METHOD get_common_div_and_gcd.
"Calculates the common divisors and the greatest common divisor of two numbers
CLEAR: common_divisors, gcd.
CHECK a >= 1.
CHECK b >= 1.
IF a >= b.
DATA(greater_num) = a.
DATA(lower_num) = b.
ELSE.
greater_num = b.
lower_num = a.
ENDIF.
"Getting common divisors
DATA(div) = 1.
WHILE div <= lower_num.
IF lower_num MOD div = 0.
DATA(divisor) = lower_num / div.
INSERT divisor INTO TABLE common_divisors.
ENDIF.
div += 1.
ENDWHILE.
LOOP AT common_divisors ASSIGNING FIELD-SYMBOL(<i>).
IF greater_num MOD <i> <> 0.
DELETE common_divisors WHERE table_line = <i>.
ENDIF.
ENDLOOP.
"Extracting the greatest common divisor from the list of common divisors
gcd = common_divisors[ lines( common_divisors ) ].
ENDMETHOD.
METHOD get_digit_sum.
"Calculates the digit sum of a number
CLEAR digit_sum.
CHECK num >= 0.
DATA(converted_int) = CONV string( num ).
DATA(len) = strlen( converted_int ).
DO len TIMES.
DATA(idx) = sy-index - 1.
digit_sum = digit_sum + converted_int+idx(1).
ENDDO.
ENDMETHOD.
METHOD get_occ_rate_global_itf.
"Method to demonstrate test double injection using constructor injection
"and a global interface
DATA total_seatsmax_global_itf TYPE i.
DATA total_seatsocc_global_itf TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing, a global interface
"is provided.
"In the example, an interface method is implemented in a local class in the local types
"tab (CCIMP include): lcl_data_prov_glo_itf
"When the class is executed using F9, the object used here refers to type lcl_data_prov_glo_itf.
"When the unit test is executed, the object used here refers to type ltd_test_data_global_intf,
"i.e. the local test double is injected.
DATA(flight_data) = data_provider_global_itf->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<l>).
total_seatsmax_global_itf = total_seatsmax_global_itf + <l>-seatsmax.
total_seatsocc_global_itf = total_seatsocc_global_itf + <l>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_global_itf / total_seatsmax_global_itf * 100.
ENDMETHOD.
METHOD get_occ_rate_local_itf.
"Method to demonstrate test double injection using back door
"injection and a local interface
DATA total_seatsmax_local_itf TYPE i.
DATA total_seatsocc_local_itf TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing - a global interface
"is not available - a local interface is created, and
"an interface method is implemented. In this example, the local interface is
"created in the local types tab (CCIMP include): lif_get_data
"A local class (lcl_data_prov_local_itf) is also created in the CCIMP include. It
"implements the local interface.
"When the class is executed using F9, the object used here refers to type lcl_data_prov_local_itf.
"When the unit test is executed, the object used here refers to type ltd_test_data_local_itf,
"i.e. the local test double is injected.
DATA(flight_data) = data_provider_local_itf->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<k>).
total_seatsmax_local_itf = total_seatsmax_local_itf + <k>-seatsmax.
total_seatsocc_local_itf = total_seatsocc_local_itf + <k>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_local_itf / total_seatsmax_local_itf * 100.
ENDMETHOD.
METHOD get_occ_rate_param_inj.
"This method demonstrates test double injection using parameter injection.
DATA total_seatsmax_param_inj TYPE i.
DATA total_seatsocc_param_inj TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing, a global interface
"is provided.
"In the example, an interface method is implemented in a local class in the local types
"tab (CCIMP include): lcl_data_prov_glo_itf
"The method has an optional importing parameter. When the unit test is executed,
"the parameter is bound. An object of the test double class is passed in that case.
"Otherwise, when the class is executed using F9, an object of the actual data provider
"is created.
IF data_prov IS BOUND.
data_provider_param_inj = data_prov.
ELSE.
data_provider_param_inj = NEW lcl_data_prov_glo_itf( ).
ENDIF.
DATA(flight_data) = data_provider_param_inj->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<o>).
total_seatsmax_param_inj = total_seatsmax_param_inj + <o>-seatsmax.
total_seatsocc_param_inj = total_seatsocc_param_inj + <o>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_param_inj / total_seatsmax_param_inj * 100.
ENDMETHOD.
METHOD get_occ_rate_setter_inj.
"This method demonstrates test double injection using setting injection.
"See the setter_meth method.
DATA total_seatsmax_setter_inj TYPE i.
DATA total_seatsocc_setter_inj TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing, a global interface
"is provided.
"In the example, an interface method is implemented in a local class in the local types
"tab (CCIMP include): lcl_data_prov_glo_itf
"See the comment in the setter_meth method
DATA(flight_data) = data_provider_setter_inj->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<n>).
total_seatsmax_setter_inj = total_seatsmax_setter_inj + <n>-seatsmax.
total_seatsocc_setter_inj = total_seatsocc_setter_inj + <n>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_setter_inj / total_seatsmax_setter_inj * 100.
ENDMETHOD.
METHOD get_occ_rate_test_seam.
"Method to demonstrate test double injection using test seams
"Note: The code is just for demonstration purposes. Of course, the result can be
"achieved more elegantly using SQL expressions, for example.
TEST-SEAM select_flights.
"DOC
SELECT seatsmax, seatsocc
FROM zdemo_abap_fli
WHERE carrid = @carrier_id
INTO CORRESPONDING FIELDS OF TABLE @seats_table.
END-TEST-SEAM.
DATA total_seatsmax_tm TYPE i.
DATA total_seatsocc_tm TYPE i.
LOOP AT seats_table ASSIGNING FIELD-SYMBOL(<j>).
total_seatsmax_tm = total_seatsmax_tm + <j>-seatsmax.
total_seatsocc_tm = total_seatsocc_tm + <j>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_tm / total_seatsmax_tm * 100.
"Further examples for test seams
DATA(var) = 0.
"Empty test seam; code is injected during unit test
"Check the output when running the class using F9 and
"the test results when running the unit test.
TEST-SEAM num1.
END-TEST-SEAM.
IF var = 0.
num1 = 1.
ELSE.
num1 = 999.
ENDIF.
num2 = 0.
"Empty injection
"See the test class: The code that is included in the test
"seam should be excluded from the test. Therefore, the
"test injection block in the test class is empty.
"Check the output when running the class using F9 and
"the test results when running the unit test.
TEST-SEAM num2.
num2 = 123.
END-TEST-SEAM.
ENDMETHOD.
METHOD get_occ_rate_using_meth.
"This method demonstrates test double injection using inheritance and method redefinition.
DATA total_seatsmax_no TYPE i.
DATA total_seatsocc_no TYPE i.
"During the unit test, the redefined method in the test class is called.
DATA(flight_data) = select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<m>).
total_seatsmax_no = total_seatsmax_no + <m>-seatsmax.
total_seatsocc_no = total_seatsocc_no + <m>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_no / total_seatsmax_no * 100.
ENDMETHOD.
METHOD get_sum.
"The method selects a record from a database table and sums the values
"of two fields, both are of type i.
SELECT SINGLE
FROM zdemo_abap_tab1
FIELDS num1 + num2 AS sum
WHERE key_field = @key
AND char1 = @char
INTO @sum.
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
"Note: The example includes a couple of implementations for the methods
@@ -179,6 +510,11 @@ METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
output->display( `ABAP Cheat Sheet Example: ABAP Unit Tests` ).
output->display( `************************************************************************` ).
output->display( `---> Choose Ctrl/Cmd + Shift + F10 to launch all tests in the class <---` ).
output->display( `************************************************************************` ).
output->display( `1) get_sum Method` ).
"This method demonstrates the use of the setup and teardown methods in the test class.
@@ -327,232 +663,6 @@ METHOD if_oo_adt_classrun~main.
ENDMETHOD.
METHOD class_constructor.
"Filling demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
"Preparing a demo database table for this example (get_sum method)
DELETE FROM zdemo_abap_tab1.
INSERT zdemo_abap_tab1 FROM @(
VALUE #( key_field = 1 char1 = 'aaa' char2 = 'bbb' num1 = 25 num2 = 75 ) ).
ENDMETHOD.
METHOD constructor.
"For demonstrating the back door injection
data_provider_local_itf = NEW lcl_data_prov_local_itf( ).
"For demonstrating the constructor injection
IF iref_data_prov IS BOUND.
"Note: The parameter is only bound when you run the unit test.
"When you run the unit test and you debug, you will see that iref_data_prov
"has a type reference to LTD_TEST_DATA_GLOBAL_INTF.
data_provider_global_itf = iref_data_prov.
ELSE.
data_provider_global_itf = NEW lcl_data_prov_glo_itf( ).
ENDIF.
"Object creation for the method call in the get_occ_rate_setter_inj method
data_provider_setter_inj = NEW lcl_data_prov_glo_itf( ).
ENDMETHOD.
METHOD get_sum.
"The method selects a record from a database table and sums the values
"of two fields, both are of type i.
SELECT SINGLE
FROM zdemo_abap_tab1
FIELDS num1 + num2 AS sum
WHERE key_field = @key
AND char1 = @char
INTO @sum.
ENDMETHOD.
METHOD get_common_div_and_gcd.
"Calculates the common divisors and the greatest common divisor of two numbers
CLEAR: common_divisors, gcd.
CHECK a >= 1.
CHECK b >= 1.
IF a >= b.
DATA(greater_num) = a.
DATA(lower_num) = b.
ELSE.
greater_num = b.
lower_num = a.
ENDIF.
"Getting common divisors
DATA(div) = 1.
WHILE div <= lower_num.
IF lower_num MOD div = 0.
DATA(divisor) = lower_num / div.
INSERT divisor INTO TABLE common_divisors.
ENDIF.
div += 1.
ENDWHILE.
LOOP AT common_divisors ASSIGNING FIELD-SYMBOL(<i>).
IF greater_num MOD <i> <> 0.
DELETE common_divisors WHERE table_line = <i>.
ENDIF.
ENDLOOP.
"Extracting the greatest common divisor from the list of common divisors
gcd = common_divisors[ lines( common_divisors ) ].
ENDMETHOD.
METHOD get_digit_sum.
"Calculates the digit sum of a number
CLEAR digit_sum.
CHECK num >= 0.
DATA(converted_int) = CONV string( num ).
DATA(len) = strlen( converted_int ).
DO len TIMES.
DATA(idx) = sy-index - 1.
digit_sum = digit_sum + converted_int+idx(1).
ENDDO.
ENDMETHOD.
METHOD get_occ_rate_test_seam.
"Method to demonstrate test double injection using test seams
"Note: The code is just for demonstration purposes. Of course, the result can be
"achieved more elegantly using SQL expressions, for example.
TEST-SEAM select_flights.
"DOC
SELECT seatsmax, seatsocc
FROM zdemo_abap_fli
WHERE carrid = @carrier_id
INTO CORRESPONDING FIELDS OF TABLE @seats_table.
END-TEST-SEAM.
DATA total_seatsmax_tm TYPE i.
DATA total_seatsocc_tm TYPE i.
LOOP AT seats_table ASSIGNING FIELD-SYMBOL(<j>).
total_seatsmax_tm = total_seatsmax_tm + <j>-seatsmax.
total_seatsocc_tm = total_seatsocc_tm + <j>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_tm / total_seatsmax_tm * 100.
"Further examples for test seams
DATA(var) = 0.
"Empty test seam; code is injected during unit test
"Check the output when running the class using F9 and
"the test results when running the unit test.
TEST-SEAM num1.
END-TEST-SEAM.
IF var = 0.
num1 = 1.
ELSE.
num1 = 999.
ENDIF.
num2 = 0.
"Empty injection
"See the test class: The code that is included in the test
"seam should be excluded from the test. Therefore, the
"test injection block in the test class is empty.
"Check the output when running the class using F9 and
"the test results when running the unit test.
TEST-SEAM num2.
num2 = 123.
END-TEST-SEAM.
ENDMETHOD.
METHOD get_occ_rate_local_itf.
"Method to demonstrate test double injection using back door
"injection and a local interface
DATA total_seatsmax_local_itf TYPE i.
DATA total_seatsocc_local_itf TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing - a global interface
"is not available - a local interface is created, and
"an interface method is implemented. In this example, the local interface is
"created in the local types tab (CCIMP include): lif_get_data
"A local class (lcl_data_prov_local_itf) is also created in the CCIMP include. It
"implements the local interface.
"When the class is executed using F9, the object used here refers to type lcl_data_prov_local_itf.
"When the unit test is executed, the object used here refers to type ltd_test_data_local_itf,
"i.e. the local test double is injected.
DATA(flight_data) = data_provider_local_itf->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<k>).
total_seatsmax_local_itf = total_seatsmax_local_itf + <k>-seatsmax.
total_seatsocc_local_itf = total_seatsocc_local_itf + <k>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_local_itf / total_seatsmax_local_itf * 100.
ENDMETHOD.
METHOD get_occ_rate_global_itf.
"Method to demonstrate test double injection using constructor injection
"and a global interface
DATA total_seatsmax_global_itf TYPE i.
DATA total_seatsocc_global_itf TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing, a global interface
"is provided.
"In the example, an interface method is implemented in a local class in the local types
"tab (CCIMP include): lcl_data_prov_glo_itf
"When the class is executed using F9, the object used here refers to type lcl_data_prov_glo_itf.
"When the unit test is executed, the object used here refers to type ltd_test_data_global_intf,
"i.e. the local test double is injected.
DATA(flight_data) = data_provider_global_itf->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<l>).
total_seatsmax_global_itf = total_seatsmax_global_itf + <l>-seatsmax.
total_seatsocc_global_itf = total_seatsocc_global_itf + <l>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_global_itf / total_seatsmax_global_itf * 100.
ENDMETHOD.
METHOD select_flight_data.
"Method that is identified as DOC in the method implementations above.
@@ -564,56 +674,6 @@ METHOD select_flight_data.
INTO CORRESPONDING FIELDS OF TABLE @flight_data.
ENDMETHOD.
METHOD get_occ_rate_using_meth.
"This method demonstrates test double injection using inheritance and method redefinition.
DATA total_seatsmax_no TYPE i.
DATA total_seatsocc_no TYPE i.
"During the unit test, the redefined method in the test class is called.
DATA(flight_data) = select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<m>).
total_seatsmax_no = total_seatsmax_no + <m>-seatsmax.
total_seatsocc_no = total_seatsocc_no + <m>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_no / total_seatsmax_no * 100.
ENDMETHOD.
METHOD get_occ_rate_setter_inj.
"This method demonstrates test double injection using setting injection.
"See the setter_meth method.
DATA total_seatsmax_setter_inj TYPE i.
DATA total_seatsocc_setter_inj TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing, a global interface
"is provided.
"In the example, an interface method is implemented in a local class in the local types
"tab (CCIMP include): lcl_data_prov_glo_itf
"See the comment in the setter_meth method
DATA(flight_data) = data_provider_setter_inj->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<n>).
total_seatsmax_setter_inj = total_seatsmax_setter_inj + <n>-seatsmax.
total_seatsocc_setter_inj = total_seatsocc_setter_inj + <n>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_setter_inj / total_seatsmax_setter_inj * 100.
ENDMETHOD.
METHOD setter_meth.
"Method to demonstrate the test double injection using setter injection
@@ -623,44 +683,4 @@ METHOD setter_meth.
"i.e. the local test double is injected.
data_provider_setter_inj = data_prov.
ENDMETHOD.
METHOD get_occ_rate_param_inj.
"This method demonstrates test double injection using parameter injection.
DATA total_seatsmax_param_inj TYPE i.
DATA total_seatsocc_param_inj TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing, a global interface
"is provided.
"In the example, an interface method is implemented in a local class in the local types
"tab (CCIMP include): lcl_data_prov_glo_itf
"The method has an optional importing parameter. When the unit test is executed,
"the parameter is bound. An object of the test double class is passed in that case.
"Otherwise, when the class is executed using F9, an object of the actual data provider
"is created.
IF data_prov IS BOUND.
data_provider_param_inj = data_prov.
ELSE.
data_provider_param_inj = NEW lcl_data_prov_glo_itf( ).
ENDIF.
DATA(flight_data) = data_provider_param_inj->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<o>).
total_seatsmax_param_inj = total_seatsmax_param_inj + <o>-seatsmax.
total_seatsocc_param_inj = total_seatsocc_param_inj + <o>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_param_inj / total_seatsmax_param_inj * 100.
ENDMETHOD.
ENDCLASS.
ENDCLASS.

View File

@@ -1381,4 +1381,4 @@ METHOD test_get_occ_rate_par_inj_fail.
ENDMETHOD.
ENDCLASS.
ENDCLASS.

View File

@@ -5,11 +5,11 @@
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_UNIT_TEST</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: Unit test</DESCRIPT>
<DESCRIPT>ABAP cheat sheet: Unit tests</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
</VSEOCLASS>
</asx:values>

View File

@@ -11,7 +11,6 @@
<MASTERLANG>E</MASTERLANG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_CARR</TABNAME>

View File

@@ -13,7 +13,6 @@
<MAINFLAG>X</MAINFLAG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_DRAFT</TABNAME>

View File

@@ -11,7 +11,6 @@
<MASTERLANG>E</MASTERLANG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_FLI</TABNAME>

View File

@@ -12,7 +12,6 @@
<MAINFLAG>X</MAINFLAG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_FLSCH</TABNAME>

View File

@@ -8,7 +8,7 @@
<DESCRIPT>Interface for ABAP cheat sheet example</DESCRIPT>
<EXPOSURE>2</EXPOSURE>
<STATE>1</STATE>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOINTERF>
</asx:values>
</asx:abap>

View File

@@ -8,7 +8,7 @@
<DESCRIPT>Interface for ABAP cheat sheet example</DESCRIPT>
<EXPOSURE>2</EXPOSURE>
<STATE>1</STATE>
<UNICODE>5</UNICODE>
<UNICODE>X</UNICODE>
</VSEOINTERF>
</asx:values>
</asx:abap>

View File

@@ -1,5 +1,5 @@
managed implementation in class zbp_demo_abap_rap_draft_m unique;
strict;
strict(2);
with draft;
define behavior for ZDEMO_ABAP_RAP_DRAFT_M alias calc
@@ -22,11 +22,7 @@ late numbering
determination det_modify on modify { field num1, num2, arithm_op; }
draft action Resume;
draft action Edit;
//As of release 2308: Draft action "Activate" should be defined as "optimized"
//to enable optimized execution of determinations and validations.
//Comment in the following notation, comment out the one below.
//draft action Activate optimized;
draft action Activate;
draft action Activate optimized;
draft action Discard;
draft determine action Prepare
{

View File

@@ -14,12 +14,6 @@
<REL>http://www.sap.com/adt/relations/versions</REL>
<TITLE>Historic versions</TITLE>
</item>
<item>
<HREF>/sap/bc/adt/repository/informationsystem/abaplanguageversions?uri=%2Fsap%2Fbc%2Fadt%2Fbo%2Fbehaviordefinitions%2Fzdemo_abap_rap_draft_m</HREF>
<REL>http://www.sap.com/adt/relations/informationsystem/abaplanguageversions</REL>
<TYPE>application/vnd.sap.adt.nameditems.v1+xml</TYPE>
<TITLE>Allowed ABAP language versions</TITLE>
</item>
<item>
<HREF>./zdemo_abap_rap_draft_m/source/main</HREF>
<REL>http://www.sap.com/adt/relations/source</REL>
@@ -32,11 +26,6 @@
<TYPE>text/html</TYPE>
<TITLE>Source Content (HTML)</TITLE>
</item>
<item>
<HREF>./zdemo_abap_rap_draft_m/objectstructure</HREF>
<REL>http://www.sap.com/adt/relations/objectstructure</REL>
<TITLE>Object Structure</TITLE>
</item>
</LINKS>
<MASTER_LANGUAGE>EN</MASTER_LANGUAGE>
<ABAP_LANGU_VERSION>5</ABAP_LANGU_VERSION>

View File

@@ -1,5 +1,5 @@
managed implementation in class zbp_demo_abap_rap_ro_m unique;
strict;
strict(2);
define behavior for ZDEMO_ABAP_RAP_RO_M alias root
persistent table zdemo_abap_rapt1

View File

@@ -14,12 +14,6 @@
<REL>http://www.sap.com/adt/relations/versions</REL>
<TITLE>Historic versions</TITLE>
</item>
<item>
<HREF>/sap/bc/adt/repository/informationsystem/abaplanguageversions?uri=%2Fsap%2Fbc%2Fadt%2Fbo%2Fbehaviordefinitions%2Fzdemo_abap_rap_ro_m</HREF>
<REL>http://www.sap.com/adt/relations/informationsystem/abaplanguageversions</REL>
<TYPE>application/vnd.sap.adt.nameditems.v1+xml</TYPE>
<TITLE>Allowed ABAP language versions</TITLE>
</item>
<item>
<HREF>./zdemo_abap_rap_ro_m/source/main</HREF>
<REL>http://www.sap.com/adt/relations/source</REL>
@@ -32,11 +26,6 @@
<TYPE>text/html</TYPE>
<TITLE>Source Content (HTML)</TITLE>
</item>
<item>
<HREF>./zdemo_abap_rap_ro_m/objectstructure</HREF>
<REL>http://www.sap.com/adt/relations/objectstructure</REL>
<TITLE>Object Structure</TITLE>
</item>
</LINKS>
<MASTER_LANGUAGE>EN</MASTER_LANGUAGE>
<ABAP_LANGU_VERSION>5</ABAP_LANGU_VERSION>

View File

@@ -1,5 +1,5 @@
unmanaged implementation in class zbp_demo_abap_rap_ro_u unique;
strict;
strict(2);
define behavior for ZDEMO_ABAP_RAP_RO_U alias root
lock master

View File

@@ -14,12 +14,6 @@
<REL>http://www.sap.com/adt/relations/versions</REL>
<TITLE>Historic versions</TITLE>
</item>
<item>
<HREF>/sap/bc/adt/repository/informationsystem/abaplanguageversions?uri=%2Fsap%2Fbc%2Fadt%2Fbo%2Fbehaviordefinitions%2Fzdemo_abap_rap_ro_u</HREF>
<REL>http://www.sap.com/adt/relations/informationsystem/abaplanguageversions</REL>
<TYPE>application/vnd.sap.adt.nameditems.v1+xml</TYPE>
<TITLE>Allowed ABAP language versions</TITLE>
</item>
<item>
<HREF>./zdemo_abap_rap_ro_u/source/main</HREF>
<REL>http://www.sap.com/adt/relations/source</REL>
@@ -32,11 +26,6 @@
<TYPE>text/html</TYPE>
<TITLE>Source Content (HTML)</TITLE>
</item>
<item>
<HREF>./zdemo_abap_rap_ro_u/objectstructure</HREF>
<REL>http://www.sap.com/adt/relations/objectstructure</REL>
<TITLE>Object Structure</TITLE>
</item>
</LINKS>
<MASTER_LANGUAGE>EN</MASTER_LANGUAGE>
<ABAP_LANGU_VERSION>5</ABAP_LANGU_VERSION>

View File

@@ -12,7 +12,6 @@
<MAINFLAG>X</MAINFLAG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_RAPT1</TABNAME>

View File

@@ -12,7 +12,6 @@
<MAINFLAG>X</MAINFLAG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_RAPT2</TABNAME>

View File

@@ -12,7 +12,6 @@
<MAINFLAG>X</MAINFLAG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_TAB1</TABNAME>

View File

@@ -12,7 +12,6 @@
<MAINFLAG>X</MAINFLAG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_TAB2</TABNAME>

View File

@@ -12,7 +12,6 @@
<MAINFLAG>X</MAINFLAG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
<ABAP_LANGUAGE_VERSION>5</ABAP_LANGUAGE_VERSION>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_TABCA</TABNAME>