Update
This commit is contained in:
@@ -1,14 +1,7 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>RAP BO provider for a RAP demo scenario</strong><br/>ABAP cheat sheet example class </p>
|
||||||
*
|
"!
|
||||||
* RAP BO provider (i. e. ABAP behavior pool/ABP)
|
"! <p>The class represents a RAP BO provider (i. e. an ABAP behavior pool/ABP) for a RAP demo scenario:<br/>
|
||||||
* for a RAP demo scenario
|
"! Managed, draft-enabled RAP BO with late numbering.</p>
|
||||||
*
|
|
||||||
* See more information in the CCIMP include (local types tab in ADT).
|
|
||||||
*
|
|
||||||
**********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">Behavior implementation for RAP demo scenario (draft BO)</p>
|
|
||||||
"! The class represents a RAP BO provider (i. e. an ABAP behavior pool/ABP) for a RAP demo scenario
|
|
||||||
"! (managed, draft-enabled RAP BO with late numbering).
|
|
||||||
CLASS zbp_demo_abap_rap_draft_m DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_draft_m.
|
CLASS zbp_demo_abap_rap_draft_m DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_draft_m.
|
||||||
PROTECTED SECTION.
|
PROTECTED SECTION.
|
||||||
PRIVATE SECTION.
|
PRIVATE SECTION.
|
||||||
@@ -16,5 +9,5 @@ ENDCLASS.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
CLASS ZBP_DEMO_ABAP_RAP_DRAFT_M IMPLEMENTATION.
|
CLASS zbp_demo_abap_rap_draft_m IMPLEMENTATION.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|||||||
@@ -1,14 +1,7 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>RAP BO provider for a RAP demo scenario</strong><br/>ABAP cheat sheet example class </p>
|
||||||
*
|
"!
|
||||||
* RAP BO provider (i. e. ABAP behavior pool/ABP)
|
"! <p>The class represents a RAP BO provider (i. e. an ABAP behavior pool/ABP) for a RAP demo scenario:<br/>
|
||||||
* for a RAP demo scenario
|
"! Managed RAP BO with external numbering.</p>
|
||||||
*
|
|
||||||
* See more information in the CCIMP include (local types tab in ADT).
|
|
||||||
*
|
|
||||||
**********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">Behavior implementation for RAP demo scenario (managed BO)</p>
|
|
||||||
"! The class represents a RAP BO provider (i. e. an ABAP behavior pool/ABP) for a RAP demo scenario
|
|
||||||
"! (managed RAP BO with external numbering).
|
|
||||||
CLASS zbp_demo_abap_rap_ro_m DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_ro_m.
|
CLASS zbp_demo_abap_rap_ro_m DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_ro_m.
|
||||||
PROTECTED SECTION.
|
PROTECTED SECTION.
|
||||||
PRIVATE SECTION.
|
PRIVATE SECTION.
|
||||||
@@ -16,5 +9,5 @@ ENDCLASS.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
CLASS ZBP_DEMO_ABAP_RAP_RO_M IMPLEMENTATION.
|
CLASS zbp_demo_abap_rap_ro_m IMPLEMENTATION.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
"! <p class="shorttext"><strong>RAP BO provider for a RAP demo scenario</strong><br/>ABAP cheat sheet example class </p>
|
||||||
|
"!
|
||||||
|
"! <p>The class represents a RAP BO provider (i. e. an ABAP behavior pool/ABP) for a RAP demo scenario:<br/>
|
||||||
|
"! Managed RAP BO with managed internal numbering and additional save, demonstrating the local consumption
|
||||||
|
"! of RAP business events.</p>
|
||||||
CLASS zbp_demo_abap_rap_ro_m_as DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_ro_m_as.
|
CLASS zbp_demo_abap_rap_ro_m_as DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_ro_m_as.
|
||||||
PUBLIC SECTION.
|
PUBLIC SECTION.
|
||||||
CLASS-DATA num_raised_events TYPE i.
|
CLASS-DATA num_raised_events TYPE i.
|
||||||
|
|||||||
@@ -1,14 +1,7 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>RAP BO provider for a RAP demo scenario</strong><br/>ABAP cheat sheet example class </p>
|
||||||
*
|
"!
|
||||||
* RAP BO provider (i. e. ABAP behavior pool/ABP)
|
"! <p>The class represents a RAP BO provider (i. e. an ABAP behavior pool/ABP) for a RAP demo scenario:<br/>
|
||||||
* for a RAP demo scenario
|
"! Unmanaged RAP BO with external numbering.</p>
|
||||||
*
|
|
||||||
* See more information in the CCIMP include (local types tab in ADT).
|
|
||||||
*
|
|
||||||
**********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">Behavior implementation for RAP demo scenario (unmanaged BO)</p>
|
|
||||||
"! The class represents a RAP BO provider (i. e. an ABAP behavior pool/ABP) for a RAP demo scenario
|
|
||||||
"! (unmanaged RAP BO with external numbering).
|
|
||||||
CLASS zbp_demo_abap_rap_ro_u DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_ro_u.
|
CLASS zbp_demo_abap_rap_ro_u DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_ro_u.
|
||||||
PROTECTED SECTION.
|
PROTECTED SECTION.
|
||||||
PRIVATE SECTION.
|
PRIVATE SECTION.
|
||||||
|
|||||||
@@ -1028,4 +1028,4 @@ CLASS lhc_child IMPLEMENTATION.
|
|||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|||||||
@@ -1,52 +1,19 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>AMDP</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: AMDP
|
"! <p>The example class demonstrates AMDP procedures and functions.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Example to demonstrate AMDP procedures and functions. It includes
|
"! <h2>Note</h2>
|
||||||
* a CDS table function.
|
"! <ul>
|
||||||
* - NOTE:
|
"! <li>The example covers the basics of AMDP method declarations and implementations.</li>
|
||||||
* - The example covers basics regarding AMDP method declarations
|
"! <li>The goal is to provide a general overview of AMDP, so the SQLScript code used in these
|
||||||
* and implementations.
|
"! methods is quite simple. AMDP is usually not necessary for such simple cases.</li>
|
||||||
* - The purpose is to give you a rough idea about AMDP. Therefore,
|
"! <li>This example is mainly intended for ABAP Cloud, where only read-only operations are
|
||||||
* the SQLScript code used in the method implementations is
|
"! possible. In classic ABAP, there are more syntax options available. Refer to the ABAP
|
||||||
* fairly simple. AMDP is not needed in simple cases like these.
|
"! Keyword Documentation for more details and examples.</li>
|
||||||
* - The example is primarily intended for ABAP Cloud.
|
"! <li>The example includes a CDS table function.</li>
|
||||||
* For example, in ABAP Cloud only read-only operations are possible.
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* In general, there are more syntax options available in classic
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li></ul>
|
||||||
* ABAP. Check the ABAP Keyword Documentation for more details and
|
|
||||||
* examples.
|
|
||||||
*
|
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
|
||||||
* - 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, check the notes
|
|
||||||
* included in the class as comments or refer to the respective topic
|
|
||||||
* in the ABAP Keyword Documentation.
|
|
||||||
* - Due to the amount of output in the console, the examples include
|
|
||||||
* numbers (e. g. 1) ..., 2) ..., 3) ...) for the individual example
|
|
||||||
* sections. Plus, the variable name is displayed in most cases. Hence,
|
|
||||||
* to easier and faster find the relevant output in the console, just
|
|
||||||
* search in the console for the number/variable name (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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: AMDP</p>
|
|
||||||
"! Example to demonstrate AMDP procedures and functions.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_amdp DEFINITION
|
CLASS zcl_demo_abap_amdp DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
|
|||||||
@@ -1,25 +1,32 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext">ABAP cheat sheet example class: ABAP cheat sheet auxiliary class</p>
|
||||||
*
|
"!
|
||||||
* Class for ABAP cheat sheet examples designed to clear and populate
|
"! <p>The class supports the ABAP cheat examples by clearing and populating demo database tables that are used there.
|
||||||
* demo database tables
|
"! The demo database tables contain airline and flight information.</p>
|
||||||
*
|
"!
|
||||||
* -------------------------- NOTE -------------------------------------
|
"! <h2>Getting started with ABAP cheat sheet example classes</h2>
|
||||||
* The code presented in this class is only meant for supporting the ABAP
|
"! <ol><li>Open the class using ABAP development tools for Eclipse (ADT).</li>
|
||||||
* cheat sheets. It is not intended for direct use in a
|
"! <li>Choose F9 to run the class.</li>
|
||||||
* production system environment. The code examples in the ABAP cheat
|
"! <li>Check the console output.</li>
|
||||||
* sheets are primarily intended to provide a better explanation and
|
"! <li>To understand the context and ABAP syntax used, refer to the notes in the
|
||||||
* visualization of the syntax and semantics of ABAP statements and not to
|
"! class comments or the relevant topic in the ABAP Keyword Documentation.</li>
|
||||||
* solve concrete programming tasks. For production application programs,
|
"! <li>The console output contains numbered sections (e.g., 1) ... , 2) ..., 3) ...)
|
||||||
* a dedicated solution should therefore always be worked out for each
|
"! for each example. Most of the time, the variable name is diplayed. To quickly find
|
||||||
* individual case. There is no guarantee for either the correctness or
|
"! the output, use CTRL+F to search for the specific number or variable name in the
|
||||||
* the completeness of the code. In addition, there is no legal
|
"! console. Alternatively, debug the class using the debugger to check the data
|
||||||
* responsibility or liability for possible errors or their consequences
|
"! objects' content and values.</li></ol>
|
||||||
* which occur through the use of the example code.
|
"!
|
||||||
*
|
"! <h2>Disclaimer</h2>
|
||||||
***********************************************************************
|
"! <p>The code presented in this class is only meant for supporting the ABAP
|
||||||
"! <p class="shorttext synchronized">Class supporting ABAP cheat sheet examples</p>
|
"! cheat sheets. It is not intended for direct use in a
|
||||||
"! The class supports the ABAP cheat examples by clearing and populating demo database tables that are used there.
|
"! production system environment. The code examples in the ABAP cheat
|
||||||
"! The demo database tables contain airline and flight information.
|
"! sheets are primarily intended to provide a better explanation and
|
||||||
|
"! visualization of the syntax and semantics of ABAP statements and not to
|
||||||
|
"! solve concrete programming tasks. For production application programs,
|
||||||
|
"! a dedicated solution should therefore always be worked out for each
|
||||||
|
"! individual case. There is no guarantee for either the correctness or
|
||||||
|
"! the completeness of the code. In addition, there is no legal
|
||||||
|
"! responsibility or liability for possible errors or their consequences
|
||||||
|
"! which occur through the use of the example code.</p>
|
||||||
CLASS zcl_demo_abap_aux DEFINITION
|
CLASS zcl_demo_abap_aux DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -30,6 +37,7 @@ CLASS zcl_demo_abap_aux DEFINITION
|
|||||||
fill_dbtabs,
|
fill_dbtabs,
|
||||||
heading IMPORTING text TYPE string
|
heading IMPORTING text TYPE string
|
||||||
RETURNING VALUE(output) TYPE string.
|
RETURNING VALUE(output) TYPE string.
|
||||||
|
CONSTANTS no_output TYPE string VALUE `No output for this section. You can set breakpoints and check the content of data objects (if available) in the debugger.`.
|
||||||
|
|
||||||
PROTECTED SECTION.
|
PROTECTED SECTION.
|
||||||
PRIVATE SECTION.
|
PRIVATE SECTION.
|
||||||
@@ -39,7 +47,6 @@ ENDCLASS.
|
|||||||
|
|
||||||
CLASS zcl_demo_abap_aux IMPLEMENTATION.
|
CLASS zcl_demo_abap_aux IMPLEMENTATION.
|
||||||
|
|
||||||
|
|
||||||
METHOD clear_dbtabs.
|
METHOD clear_dbtabs.
|
||||||
DELETE FROM zdemo_abap_flsch.
|
DELETE FROM zdemo_abap_flsch.
|
||||||
DELETE FROM zdemo_abap_carr.
|
DELETE FROM zdemo_abap_carr.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<VSEOCLASS>
|
<VSEOCLASS>
|
||||||
<CLSNAME>ZCL_DEMO_ABAP_AUX</CLSNAME>
|
<CLSNAME>ZCL_DEMO_ABAP_AUX</CLSNAME>
|
||||||
<LANGU>E</LANGU>
|
<LANGU>E</LANGU>
|
||||||
<DESCRIPT>Class supporting ABAP cheat sheet examples</DESCRIPT>
|
<DESCRIPT>ABAP cheat sheet example class: ABAP cheat sheet auxiliary c</DESCRIPT>
|
||||||
<STATE>1</STATE>
|
<STATE>1</STATE>
|
||||||
<CLSCCINCL>X</CLSCCINCL>
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
<FIXPT>X</FIXPT>
|
<FIXPT>X</FIXPT>
|
||||||
|
|||||||
@@ -1,48 +1,18 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>CDS view entities</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: CDS View Entities
|
"! <p>The example class demonstrates CDS view entities.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Example to demonstrate CDS view entities. See the CDS view entities
|
"! <h2>Note</h2>
|
||||||
* that are used in the example for more details.
|
"! <ul>
|
||||||
* - Topics covered: Operands, expressions, and built-in functions in the
|
"! <li>Example demonstrating CDS view entities. Refer to the CDS view entities used
|
||||||
* element list of CDS view entities, input parameters, joins,
|
"! here for more details.</li>
|
||||||
* associations
|
"! <li>Topics covered: Operands, expressions, built-in functions in the element list
|
||||||
* - Note: In ADT, check out the CDS view entities used in this example
|
"! of CDS view entities, input parameters, joins, associations.</li>
|
||||||
* by holding down CTRL and clicking on the CDS view entity. This will
|
"! <li>Note: In ADT, hold CTRL and click on the CDS view entity in this example to
|
||||||
* take you to the artifact. There you can choose F8 to open the data
|
"! access the artifact. You can choose F8 there to open the data preview.</li>
|
||||||
* preview.
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li></ul>
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
|
||||||
* - 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
|
|
||||||
* 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)
|
|
||||||
* 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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: CDS view entities</p>
|
|
||||||
"! Example to demonstrate CDS view entities.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_cds_ve DEFINITION
|
CLASS zcl_demo_abap_cds_ve DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -53,18 +23,18 @@ CLASS zcl_demo_abap_cds_ve DEFINITION
|
|||||||
if_oo_adt_classrun.
|
if_oo_adt_classrun.
|
||||||
|
|
||||||
CLASS-METHODS class_constructor.
|
CLASS-METHODS class_constructor.
|
||||||
protected section.
|
PROTECTED SECTION.
|
||||||
private section.
|
PRIVATE SECTION.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CLASS ZCL_DEMO_ABAP_CDS_VE IMPLEMENTATION.
|
CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
|
||||||
|
|
||||||
|
|
||||||
METHOD class_constructor.
|
METHOD class_constructor.
|
||||||
"Filling demo database tables.
|
"Filling demo database tables.
|
||||||
zcl_demo_abap_aux=>fill_dbtabs( ).
|
zcl_demo_abap_aux=>fill_dbtabs( ).
|
||||||
|
|
||||||
"Some more database table insertions for this particular example
|
"Some more database table insertions for this particular example
|
||||||
MODIFY zdemo_abap_carr FROM TABLE @( VALUE #(
|
MODIFY zdemo_abap_carr FROM TABLE @( VALUE #(
|
||||||
|
|||||||
@@ -1,42 +1,17 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>AMDP</strong><br/>Excursions into ABAP for Cloud Development</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: Excursions into ABAP for Cloud Development
|
"! <p>The example class demonstrates released APIs and libraries with the restricted
|
||||||
*
|
"! ABAP language version.<br/>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* - Example to demonstrate a selected set of released APIs and libraries
|
"!
|
||||||
* with the restricted ABAP language version
|
"! <h2>Note</h2>
|
||||||
* - NOTE: The example class includes constants in the private visbility
|
"! <ul>
|
||||||
* section. The names specified there are used by code snippets.
|
"! <li>The example class includes constants in the private visbility
|
||||||
* Make sure that you insert suitable values before running the
|
"! section. The names specified there are used by code snippets.
|
||||||
* example class.
|
"! Make sure that you insert suitable values before running the
|
||||||
*
|
"! example class if you want to explore all syntax examples.</li>
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* - Open the class with the ABAP development tools for Eclipse (ADT).
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li></ul>
|
||||||
* - Choose F9 to run the class.
|
|
||||||
* - Check the console output.
|
|
||||||
* - Due to the amount of output in the console, the examples include
|
|
||||||
* numbers (e. g. 1) ..., 2) ..., 3) ...) for the individual example
|
|
||||||
* sections. Plus, the variable name is displayed in several cases.
|
|
||||||
* Hence, to easier and faster find the relevant output in the console,
|
|
||||||
* just search in the console for the number/variable name (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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: Excursions into ABAP for Cloud Development</p>
|
|
||||||
"! Example to demonstrate released APIs and libraries with the restricted ABAP language version.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_cloud_excursion DEFINITION
|
CLASS zcl_demo_abap_cloud_excursion DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -98,49 +73,122 @@ CLASS zcl_demo_abap_cloud_excursion IMPLEMENTATION.
|
|||||||
out->write( `1) Restrictions in ABAP for Cloud Development` ).
|
out->write( `1) Restrictions in ABAP for Cloud Development` ).
|
||||||
out->write( |\nYou can check the code of this section by commenting it in and out. Note the comments in the code.| ).
|
out->write( |\nYou can check the code of this section by commenting it in and out. Note the comments in the code.| ).
|
||||||
"The following statements demonstrate a selection of restrictions in ABAP for Cloud Development.
|
"The following statements demonstrate a selection of restrictions in ABAP for Cloud Development.
|
||||||
|
"It includes (not) released APIs, deprecated and invalid syntax in ABAP for Cloud Development.
|
||||||
"Comment in the code lines (CTRL + 7) up to BREAK-POINT and check the syntax errors/warnings
|
"Comment in the code lines (CTRL + 7) up to BREAK-POINT and check the syntax errors/warnings
|
||||||
"displayed.
|
"displayed.
|
||||||
"Notes about the errors/warnings:
|
|
||||||
"- Using ABAP SQL statements, data is retrieved from database tables. The first table
|
|
||||||
" is a demo table provided by SAP. This table cannot be accessed directly (unlike in classic
|
|
||||||
" ABAP) and therefore cannot be used as a data source from which to select. The second
|
|
||||||
" is a database table from the ABAP Cheat Sheet GitHub repository. If you have imported
|
|
||||||
" the repository into the system, you can use it as a data source.
|
|
||||||
"- The example includes dynamic ABAP SQL statements. This is just to emphasize that such
|
|
||||||
" statements can lead to unwanted results, since in this case you cannot select from the
|
|
||||||
" first database table whose name is specified dynamically. Therefore, there is no syntax
|
|
||||||
" error or warning at compile time, but an error at runtime. You can try the following:
|
|
||||||
" Comment out all code except the lines with the dynamic statements, activate the code
|
|
||||||
" and execute the class with F9. Note: Check out the CL_ABAP_DYN_PRG class, which supports
|
|
||||||
" dynamic programming by checking the validity of dynamic specifications.
|
|
||||||
"- Further examples of obsolete and invalid syntax in ABAP for Cloud Development include
|
|
||||||
" the invalid MOVE ... TO ... statement and others. To set breakpoints in ADT, double-click
|
|
||||||
" the area to the left of the code line number.
|
|
||||||
|
|
||||||
|
* "Released DDIC data elements
|
||||||
* SELECT carrid, connid FROM spfli WHERE carrid = 'LH' INTO TABLE @DATA(it1).
|
* DATA dobj1 TYPE timestampl.
|
||||||
* SELECT carrid, connid FROM zdemo_abap_fli WHERE carrid = 'LH' INTO TABLE @DATA(it2).
|
* DATA dobj2 TYPE land1.
|
||||||
* SELECT SINGLE carrid, connid FROM ('SPFLI') WHERE carrid = 'LH' INTO NEW @DATA(wa1).
|
|
||||||
* SELECT SINGLE carrid, connid FROM ('ZDEMO_ABAP_FLI') WHERE carrid = 'LH' INTO NEW @DATA(wa2).
|
|
||||||
*
|
*
|
||||||
|
* "Attributes of the accessible type pool ABAP
|
||||||
|
* DATA flag TYPE abap_boolean.
|
||||||
|
* flag = abap_true.
|
||||||
|
*
|
||||||
|
* "Released table types
|
||||||
|
* DATA it1 TYPE string_table.
|
||||||
|
* DATA it2 TYPE string_hashed_table.
|
||||||
|
* DATA it3 TYPE xstring_table.
|
||||||
|
*
|
||||||
|
* "Released CDS object
|
||||||
|
* DATA s1 TYPE i_timezone.
|
||||||
|
*
|
||||||
|
* "Released interface
|
||||||
|
* "The if_oo_adt_classrun interface is released, and you can implement it to run an ABAP class.
|
||||||
|
* "In ADT, you can do this by choosing F9. To output the content of data objects, you can use
|
||||||
|
* "out->write( ... ). in the main method.
|
||||||
|
* DATA ref_classrun TYPE REF TO if_oo_adt_classrun.
|
||||||
|
*
|
||||||
|
* "Not released DDIC database table
|
||||||
|
* DATA s2 TYPE scarr.
|
||||||
|
*
|
||||||
|
* "Classes
|
||||||
|
* "Released class
|
||||||
|
* DATA(ixml1) = cl_ixml_core=>create( ).
|
||||||
|
* "Not released (API for classic ABAP)
|
||||||
|
* DATA(ixml2) = cl_ixml=>create( ).
|
||||||
|
*
|
||||||
|
* "Released APIs from the XCO library
|
||||||
|
* "Retrieving the current user date
|
||||||
|
* DATA(user_date) = xco_cp=>sy->date( xco_cp_time=>time_zone->user
|
||||||
|
* )->as( xco_cp_time=>format->iso_8601_extended
|
||||||
|
* )->value.
|
||||||
|
*
|
||||||
|
* "Retrieving the current user time
|
||||||
|
* DATA(user_time) = xco_cp=>sy->time( xco_cp_time=>time_zone->user
|
||||||
|
* )->as( xco_cp_time=>format->iso_8601_extended
|
||||||
|
* )->value.
|
||||||
|
*
|
||||||
|
* "Not released API: Querying whether the current database supports AMDP methods
|
||||||
|
* DATA(amdp_allowed) = xsdbool( cl_abap_dbfeatures=>use_features(
|
||||||
|
* EXPORTING requested_features = VALUE #( ( cl_abap_dbfeatures=>call_amdp_method ) ) ) ).
|
||||||
|
*
|
||||||
|
* "ABAP SQL statements
|
||||||
|
* "Selecting from a
|
||||||
|
* "... not released database table
|
||||||
|
* SELECT carrid, connid FROM spfli WHERE carrid = 'LH' INTO TABLE @DATA(spfli_tab).
|
||||||
|
*
|
||||||
|
* "... released CDS view
|
||||||
|
* SELECT SINGLE * FROM i_timezone WHERE TimeZoneID = 'EST' INTO @DATA(tz_info).
|
||||||
|
*
|
||||||
|
* "... not released database table using a dynamic ABAP SQL statement
|
||||||
|
* "Although the source code provides an invalid data source, the dynamic ABAP SQL statement
|
||||||
|
* "does not produce a syntax error during compilation. However, it would result in a runtime
|
||||||
|
* "error because you cannot select from that data source. You can check the validity of dynamic
|
||||||
|
* "specifications using the `cl_abap_dyn_prg` class, which supports dynamic programming.
|
||||||
|
* SELECT SINGLE carrid, connid FROM ('SPFLI') WHERE carrid = 'LH' INTO NEW @DATA(ref_spfli_tab).
|
||||||
|
*
|
||||||
|
* "ABAP SQL Statement involving client handling; using a cheat sheet database table
|
||||||
|
* "The addition `USING CLIENT` for client handling is not allowed in the restricted ABAP language scope.
|
||||||
|
* DATA(clnt) = sy-mandt.
|
||||||
|
* SELECT carrid, connid FROM ('ZDEMO_ABAP_FLI') USING CLIENT @clnt WHERE carrid = 'LH' INTO TABLE NEW @DATA(ref_demo_tab).
|
||||||
|
*
|
||||||
|
* "The example includes a selection of deprecated and invalid syntax in ABAP for Cloud Development. They are added
|
||||||
|
* "for demonstration purposes. For example, classic UI technology-related (such as dynpro) syntax is not allowed.
|
||||||
|
* "The pointless WRITE statement within the method implementation represents invalid classic list-related statements.
|
||||||
|
* "Executable programs (reports) are not allowed in the restricted ABAP language scope. To set breakpoints in ADT,
|
||||||
|
* "double-click the area to the left of the code line number.
|
||||||
|
*
|
||||||
|
* "Assignments
|
||||||
* DATA(num1) = 1.
|
* DATA(num1) = 1.
|
||||||
* DATA(num2) = 1.
|
* DATA(num2) = 1.
|
||||||
* DATA(num3) = 2.
|
* DATA(num3) = 2.
|
||||||
*
|
* "Invalid statement for an assignment
|
||||||
* MOVE num3 TO num1.
|
* MOVE num3 TO num1.
|
||||||
|
* "Using the assignment operator
|
||||||
* num2 = num3.
|
* num2 = num3.
|
||||||
*
|
*
|
||||||
* DATA(it3) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ).
|
* "Determining the number of lines in an internal table
|
||||||
* DESCRIBE TABLE it3 LINES DATA(num_lines1).
|
* DATA(str_table) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ).
|
||||||
* DATA(num_lines2) = lines( it3 ).
|
* DATA(num_lines1) = lines( str_table ).
|
||||||
|
* "Invalid statement
|
||||||
|
* DESCRIBE TABLE str_table LINES DATA(num_lines2).
|
||||||
*
|
*
|
||||||
|
* "Getting references
|
||||||
* DATA: ref1 TYPE REF TO i,
|
* DATA: ref1 TYPE REF TO i,
|
||||||
* ref2 TYPE REF TO i.
|
* ref2 TYPE REF TO i.
|
||||||
|
*
|
||||||
* ref1 = REF #( num1 ).
|
* ref1 = REF #( num1 ).
|
||||||
|
* "Deprecated statement
|
||||||
* GET REFERENCE OF num1 INTO ref2.
|
* GET REFERENCE OF num1 INTO ref2.
|
||||||
*
|
*
|
||||||
* DATA str_itab TYPE string_table.
|
* "Classic ABAP-related statements and syntax
|
||||||
* READ REPORT 'ZCL_DEMO_ABAP_UNIT_TEST=======CCAU' INTO str_itab.
|
* "Various sy components should not be used in ABAP for Cloud Development
|
||||||
|
* DATA(current_as_abap_time) = sy-uzeit.
|
||||||
|
* DATA(current_as_abap_date) = sy-datum.
|
||||||
|
* DATA(current_local_time) = sy-timlo.
|
||||||
|
*
|
||||||
|
* "Various invalid statements
|
||||||
|
* DATA scarr_tab TYPE TABLE OF scarr WITH EMPTY KEY.
|
||||||
|
* TRY.
|
||||||
|
* cl_salv_table=>factory( IMPORTING r_salv_table = DATA(alv)
|
||||||
|
* CHANGING t_table = scarr_tab ).
|
||||||
|
* "The exception class is not released, too.
|
||||||
|
* CATCH cx_salv_msg.
|
||||||
|
* ENDTRY.
|
||||||
|
*
|
||||||
|
* DATA code TYPE string_table.
|
||||||
|
* READ REPORT 'ZCL_DEMO_ABAP_UNIT_TEST=======CCAU' INTO code.
|
||||||
* WRITE 'hi'.
|
* WRITE 'hi'.
|
||||||
* BREAK-POINT.
|
* BREAK-POINT.
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +1,16 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>Constructor expressions</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: Constructor expressions
|
"! <p>The example class demonstrates the use of constructor expressions.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Example to demonstrate the use of constructor expressions.
|
"! <h2>Note</h2>
|
||||||
* - Topics covered: Operators VALUE, CORRESPONDING, NEW, CONV, EXACT, REF,
|
"! <ul><li>Topics covered:<ul>
|
||||||
* CAST, COND, SWITCH, FILTER, REDUCE, iteration expressions with FOR,
|
"! <li>Operators VALUE, CORRESPONDING, NEW, CONV, EXACT, REF,
|
||||||
* LET expressions
|
"! CAST, COND, SWITCH, FILTER, REDUCE</li>
|
||||||
*
|
"! <li>Iteration expressions with FOR</li>
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
"! <li>LET expressions</li></ul>
|
||||||
* - Open the class with the ABAP development tools for Eclipse (ADT).
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* - Choose F9 to run the class.
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li></ul>
|
||||||
* - 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
|
|
||||||
* 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)
|
|
||||||
* 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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: Constructor expressions</p>
|
|
||||||
"! Example to demonstrate the use of constructor expressions.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_constructor_expr DEFINITION
|
CLASS zcl_demo_abap_constructor_expr DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -1966,4 +1939,4 @@ CLASS zcl_demo_abap_constructor_expr IMPLEMENTATION.
|
|||||||
|
|
||||||
out->write( data = stringtab name = `stringtab` ).
|
out->write( data = stringtab name = `stringtab` ).
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|||||||
@@ -1,41 +1,11 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>Date, Time, and Time Stamp</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: Date, Time, and Time Stamp
|
"! <p>The example class demonstrates the handling and procesing dates, times, and time stamps in ABAP.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Example to demonstrate various syntax options for working with
|
"! <h2>Note</h2>
|
||||||
* date, time, and time stamp.
|
"! <p>Find information on <strong>getting started with the example class</strong> and the
|
||||||
*
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
|
||||||
* - 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
|
|
||||||
* 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)
|
|
||||||
* 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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: Date, Time, and Time Stamp</p>
|
|
||||||
"! Example to demonstrate handling and procesing dates, times, and time stamps in ABAP.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_date_time DEFINITION
|
CLASS zcl_demo_abap_date_time DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -187,18 +157,18 @@ CLASS zcl_demo_abap_date_time IMPLEMENTATION.
|
|||||||
|
|
||||||
"Assignment of an invalid date of type d to type i; the initial value
|
"Assignment of an invalid date of type d to type i; the initial value
|
||||||
"is produced
|
"is produced
|
||||||
"In newer ABAP releases, the following statement shows a
|
"In newer ABAP releases, the following statement shows a
|
||||||
"syntax warning that the date (intentionally specified as
|
"syntax warning that the date (intentionally specified as
|
||||||
"invalid date here) does not match the type. Therefore,
|
"invalid date here) does not match the type. Therefore,
|
||||||
"the example is provided differently to circumvent the
|
"the example is provided differently to circumvent the
|
||||||
"syntax warning.
|
"syntax warning.
|
||||||
|
|
||||||
"DATA(inv_date3) = CONV i( CONV d( '20240231' ) ).
|
"DATA(inv_date3) = CONV i( CONV d( '20240231' ) ).
|
||||||
|
|
||||||
TYPES c8 TYPE c LENGTH 8.
|
TYPES c8 TYPE c LENGTH 8.
|
||||||
DATA false_date TYPE c8 VALUE '20240231'.
|
DATA false_date TYPE c8 VALUE '20240231'.
|
||||||
DATA(inv_date3) = CONV i( CONV d( false_date ) ).
|
DATA(inv_date3) = CONV i( CONV d( false_date ) ).
|
||||||
|
|
||||||
IF inv_date3 = 0.
|
IF inv_date3 = 0.
|
||||||
out->write( `inv_date3 = 0` ).
|
out->write( `inv_date3 = 0` ).
|
||||||
ENDIF.
|
ENDIF.
|
||||||
@@ -924,10 +894,10 @@ CLASS zcl_demo_abap_date_time IMPLEMENTATION.
|
|||||||
"No data object change. The statement below should return a valid time stamp.
|
"No data object change. The statement below should return a valid time stamp.
|
||||||
WHEN 2.
|
WHEN 2.
|
||||||
"Invalid date
|
"Invalid date
|
||||||
"In newer ABAP releases, the following statement shows a
|
"In newer ABAP releases, the following statement shows a
|
||||||
"syntax warning that the date (intentionally specified as
|
"syntax warning that the date (intentionally specified as
|
||||||
"invalid date here) does not match the type. Therefore,
|
"invalid date here) does not match the type. Therefore,
|
||||||
"the example is provided differently to circumvent the
|
"the example is provided differently to circumvent the
|
||||||
"syntax warning.
|
"syntax warning.
|
||||||
|
|
||||||
"date_test = '20249999'.
|
"date_test = '20249999'.
|
||||||
|
|||||||
@@ -1,46 +1,19 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>Data Types and Data Objects</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: Data Types and Data Objects
|
"! <p>The example class demonstrates data types and data objects in ABAP.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Example to demonstrate data types and data objects.
|
"! <h2>Note</h2>
|
||||||
* - Note that in many cases there is no output displayed because the
|
"! <ul>
|
||||||
* focus is on syntax options and declarations. In the class, you can
|
"! <li>In many cases, there is no output displayed because the
|
||||||
* set breakpoints and use the debugger to check out data objects.
|
"! focus is on syntax options and declarations.</li>
|
||||||
* You can also use the F2 information for the many types and data
|
"! <li>In the class, you can set breakpoints and use the debugger to
|
||||||
* objects. Simply select a type or object in the code and press F2
|
"! check out data objects.</li>
|
||||||
* in ADT to check out the information.
|
"! <li>You can also use the F2 information for the many types and data
|
||||||
*
|
"! objects. Simply select a type or object in the code and choose F2
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
"! in ADT to check out the information.</li>
|
||||||
* - Open the class with the ABAP development tools for Eclipse (ADT).
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* - Choose F9 to run the class.
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li></ul>
|
||||||
* - 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
|
|
||||||
* 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)
|
|
||||||
* 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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: Data Types and Data Objects</p>
|
|
||||||
"! Example to demonstrate data types and data objects in ABAP.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_dtype_dobj DEFINITION
|
CLASS zcl_demo_abap_dtype_dobj DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -68,8 +41,6 @@ CLASS zcl_demo_abap_dtype_dobj DEFINITION
|
|||||||
num2 TYPE numeric
|
num2 TYPE numeric
|
||||||
RETURNING VALUE(result) TYPE decfloat34.
|
RETURNING VALUE(result) TYPE decfloat34.
|
||||||
|
|
||||||
constants no_output type string value `No output for this section. Check out the types in the code e.g. using the F2 information.`.
|
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
"Types and methods for demonstrating enumerated types and objects
|
"Types and methods for demonstrating enumerated types and objects
|
||||||
@@ -366,7 +337,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
TYPES te_tp TYPE abap_bool.
|
TYPES te_tp TYPE abap_bool.
|
||||||
TYPES te_const_in_tp LIKE abap_true.
|
TYPES te_const_in_tp LIKE abap_true.
|
||||||
|
|
||||||
out->write( no_output ).
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -434,7 +405,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
"Elementary line type; the type is available in a global interface
|
"Elementary line type; the type is available in a global interface
|
||||||
TYPES tt_elem_type_from_itf TYPE TABLE OF zdemo_abap_get_data_itf=>occ_rate.
|
TYPES tt_elem_type_from_itf TYPE TABLE OF zdemo_abap_get_data_itf=>occ_rate.
|
||||||
|
|
||||||
out->write( no_output ).
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -467,9 +438,9 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
"Reference table types
|
"Reference table types
|
||||||
TYPES tr_tab_ref_i TYPE TABLE OF REF TO i.
|
TYPES tr_tab_ref_i TYPE TABLE OF REF TO i.
|
||||||
DATA itab_str TYPE TABLE OF string.
|
DATA itab_str TYPE TABLE OF string.
|
||||||
TYPES tr_like_table_ref LIKE TABLE OF ref TO itab_str.
|
TYPES tr_like_table_ref LIKE TABLE OF REF TO itab_str.
|
||||||
|
|
||||||
out->write( no_output ).
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -565,7 +536,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
...
|
...
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
|
||||||
out->write( no_output ).
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -624,7 +595,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
DATA struc_from_itab_type TYPE LINE OF tt_ddic_tab.
|
DATA struc_from_itab_type TYPE LINE OF tt_ddic_tab.
|
||||||
DATA struc_like_line LIKE LINE OF itab_ddic_tab.
|
DATA struc_like_line LIKE LINE OF itab_ddic_tab.
|
||||||
|
|
||||||
out->write( no_output ).
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -655,7 +626,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
DATA dref_tab_i TYPE TABLE OF REF TO i.
|
DATA dref_tab_i TYPE TABLE OF REF TO i.
|
||||||
DATA dref_tab_str LIKE TABLE OF REF TO do_some_string.
|
DATA dref_tab_str LIKE TABLE OF REF TO do_some_string.
|
||||||
|
|
||||||
out->write( no_output ).
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -757,7 +728,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
"with the conversion rules.
|
"with the conversion rules.
|
||||||
str_a2 = some_itab[ 2 ]-carrname.
|
str_a2 = some_itab[ 2 ]-carrname.
|
||||||
|
|
||||||
out->write( no_output ).
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -869,7 +840,22 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
"NEW addition
|
"NEW addition
|
||||||
SELECT * FROM zdemo_abap_carr INTO TABLE NEW @DATA(itab_ref).
|
SELECT * FROM zdemo_abap_carr INTO TABLE NEW @DATA(itab_ref).
|
||||||
|
|
||||||
out->write( no_output ).
|
"Inline declaration is useful for specifying data objects as actual
|
||||||
|
"parameters in method calls
|
||||||
|
"The following method calculates the difference in days, hours, minutes,
|
||||||
|
"and seconds of two time stamps.
|
||||||
|
"Check the F2 information of the 'diff' method. It has 4 exporting parameters.
|
||||||
|
"3 different types are involved. Using the inline declarations, the data
|
||||||
|
"objects receive the suitable types automatically. Extra variable declarations
|
||||||
|
"with suitable types can be avoided.
|
||||||
|
cl_abap_utclong=>diff( EXPORTING high = CONV utclong( '2024-01-01 15:30:00' )
|
||||||
|
low = CONV utclong( '2023-12-24 14:20:40' )
|
||||||
|
IMPORTING days = DATA(days)
|
||||||
|
hours = DATA(hours)
|
||||||
|
minutes = DATA(minutes)
|
||||||
|
seconds = DATA(seconds) ).
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -1074,7 +1060,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
FROM zdemo_abap_carr
|
FROM zdemo_abap_carr
|
||||||
INTO TABLE NEW @DATA(dref_14_inline).
|
INTO TABLE NEW @DATA(dref_14_inline).
|
||||||
|
|
||||||
out->write( no_output ).
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -1273,12 +1259,12 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
out->write( data = date name = `date` ).
|
out->write( data = date name = `date` ).
|
||||||
out->write( |\n| ).
|
out->write( |\n| ).
|
||||||
|
|
||||||
"In newer ABAP releases, the following statement shows a syntax
|
"In newer ABAP releases, the following statement shows a syntax
|
||||||
"warning that the value of the the data object (intentionally
|
"warning that the value of the the data object (intentionally
|
||||||
"specified here like this) is not an admissable value for the
|
"specified here like this) is not an admissable value for the
|
||||||
"target type. Therefore, the example is provided differently to
|
"target type. Therefore, the example is provided differently to
|
||||||
"circumvent the syntax warning.
|
"circumvent the syntax warning.
|
||||||
|
|
||||||
"date = 20240101.
|
"date = 20240101.
|
||||||
DATA falsedate TYPE i VALUE 20240101.
|
DATA falsedate TYPE i VALUE 20240101.
|
||||||
date = falsedate.
|
date = falsedate.
|
||||||
@@ -1545,7 +1531,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
"SELECT statement with a an immutable target table declared inline
|
"SELECT statement with a an immutable target table declared inline
|
||||||
SELECT * FROM zdemo_abap_carr INTO TABLE @FINAL(itab_final_inl).
|
SELECT * FROM zdemo_abap_carr INTO TABLE @FINAL(itab_final_inl).
|
||||||
|
|
||||||
out->write( no_output ).
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -1678,11 +1664,11 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
|
|
||||||
"Assignments
|
"Assignments
|
||||||
do_h_c5 = 'abc'.
|
do_h_c5 = 'abc'.
|
||||||
|
|
||||||
"In newer ABAP releases, the following statement shows a syntax
|
"In newer ABAP releases, the following statement shows a syntax
|
||||||
"warning that the value of the literal (intentionally specified
|
"warning that the value of the literal (intentionally specified
|
||||||
"here like this) is not an admissable value for the target type.
|
"here like this) is not an admissable value for the target type.
|
||||||
"Therefore, the example is provided differently to circumvent the
|
"Therefore, the example is provided differently to circumvent the
|
||||||
"syntax warning.
|
"syntax warning.
|
||||||
|
|
||||||
"do_h_c5 = 'defghi'.
|
"do_h_c5 = 'defghi'.
|
||||||
@@ -1798,7 +1784,7 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `20) Generic ABAP types for formal parameters of methods` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `20a) Generic ABAP types for formal parameters of methods` ) ).
|
||||||
|
|
||||||
"Generic data types have already been covered above.
|
"Generic data types have already been covered above.
|
||||||
"A generic data type is an incomplete type specification that covers multiple
|
"A generic data type is an incomplete type specification that covers multiple
|
||||||
@@ -1840,7 +1826,154 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `21) Built-in data objects` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `20b) Overview of generic ABAP types using field symbols` ) ).
|
||||||
|
|
||||||
|
FIELD-SYMBOLS:
|
||||||
|
"Any data type
|
||||||
|
<data> TYPE data,
|
||||||
|
<any> TYPE any,
|
||||||
|
"Any data type can be assigned. Restrictions for formal parameters and 'data': no
|
||||||
|
"numeric functions, no description functions, and no arithmetic expressions can be
|
||||||
|
"passed to these parameters. However, you can bypass the restriction by applying the
|
||||||
|
"CONV operator for the actual parameter.
|
||||||
|
|
||||||
|
"Character-like types
|
||||||
|
<c> TYPE c, "Text field with a generic length
|
||||||
|
<clike> TYPE clike, "Character-like (c, n, string, d, t and character-like flat structures)
|
||||||
|
<csequence> TYPE csequence, "Text-like (c, string)
|
||||||
|
<n> TYPE n, "Numeric text with generic length
|
||||||
|
<x> TYPE x, "Byte field with generic length
|
||||||
|
<xsequence> TYPE xsequence, "Byte-like (x, xstring)
|
||||||
|
|
||||||
|
"Numeric types
|
||||||
|
<decfloat> TYPE decfloat, "decfloat16, decfloat34
|
||||||
|
<numeric> TYPE numeric, "Numeric ((b, s), i, int8, p, decfloat16, decfloat34, f)
|
||||||
|
<p> TYPE p, "Packed number (generic length and number of decimal places)
|
||||||
|
|
||||||
|
"Internal table types
|
||||||
|
<any_table> TYPE ANY TABLE, "Internal table with any table type
|
||||||
|
<hashed_table> TYPE HASHED TABLE,
|
||||||
|
<index_table> TYPE INDEX TABLE,
|
||||||
|
<sorted_table> TYPE SORTED TABLE,
|
||||||
|
<standard_table> TYPE STANDARD TABLE,
|
||||||
|
<table> TYPE table, "Standard table
|
||||||
|
|
||||||
|
"Other types
|
||||||
|
<simple> TYPE simple. "Elementary data type including enumerated types and
|
||||||
|
"structured types with exclusively character-like flat components
|
||||||
|
|
||||||
|
"Data objects to work with
|
||||||
|
DATA: BEGIN OF s,
|
||||||
|
c3 TYPE c LENGTH 3,
|
||||||
|
c10 TYPE c LENGTH 10,
|
||||||
|
n4 TYPE n LENGTH 4,
|
||||||
|
str TYPE string,
|
||||||
|
time TYPE t,
|
||||||
|
date TYPE d,
|
||||||
|
dec16 TYPE decfloat16,
|
||||||
|
dec34 TYPE decfloat34,
|
||||||
|
int TYPE i,
|
||||||
|
pl4d2 TYPE p LENGTH 4 DECIMALS 2,
|
||||||
|
tab_std TYPE STANDARD TABLE OF string WITH EMPTY KEY,
|
||||||
|
tab_so TYPE SORTED TABLE OF string WITH NON-UNIQUE KEY table_line,
|
||||||
|
tab_ha TYPE HASHED TABLE OF string WITH UNIQUE KEY table_line,
|
||||||
|
xl1 TYPE x LENGTH 1,
|
||||||
|
xstr TYPE xstring,
|
||||||
|
structure TYPE zdemo_abap_carr, "character-like flat structure
|
||||||
|
END OF s.
|
||||||
|
|
||||||
|
"The following static ASSIGN statements demonstrate various assignments
|
||||||
|
"Note:
|
||||||
|
"- The statements commented out show impossible assignments.
|
||||||
|
"- If a static assignment is not successful, sy-subrc is not set and no
|
||||||
|
" memory area is assigned. Dynamic assignments, however, set the value.
|
||||||
|
|
||||||
|
"----- Any data type -----
|
||||||
|
ASSIGN s-c3 TO <data>.
|
||||||
|
ASSIGN s-time TO <data>.
|
||||||
|
ASSIGN s-tab_std TO <data>.
|
||||||
|
ASSIGN s-xstr TO <any>.
|
||||||
|
ASSIGN s-pl4d2 TO <any>.
|
||||||
|
ASSIGN s-date TO <any>.
|
||||||
|
ASSIGN s TO <any>.
|
||||||
|
|
||||||
|
"----- Character-like types -----
|
||||||
|
ASSIGN s-c3 TO <c>.
|
||||||
|
ASSIGN s-c10 TO <c>.
|
||||||
|
"ASSIGN s-str TO <c>.
|
||||||
|
|
||||||
|
ASSIGN s-c10 TO <clike>.
|
||||||
|
ASSIGN s-str TO <clike>.
|
||||||
|
ASSIGN s-n4 TO <clike>.
|
||||||
|
ASSIGN s-date TO <clike>.
|
||||||
|
ASSIGN s-time TO <clike>.
|
||||||
|
ASSIGN s-structure TO <clike>.
|
||||||
|
|
||||||
|
ASSIGN s-c10 TO <csequence>.
|
||||||
|
ASSIGN s-str TO <csequence>.
|
||||||
|
"ASSIGN s-n4 TO <csequence>.
|
||||||
|
|
||||||
|
ASSIGN s-n4 TO <n>.
|
||||||
|
"ASSIGN s-int TO <n>.
|
||||||
|
"ASSIGN s-time TO <n>.
|
||||||
|
|
||||||
|
ASSIGN s-xl1 TO <x>.
|
||||||
|
"ASSIGN s-xstr TO <x>.
|
||||||
|
|
||||||
|
ASSIGN s-xl1 TO <xsequence>.
|
||||||
|
ASSIGN s-xstr TO <xsequence>.
|
||||||
|
|
||||||
|
"----- Numeric types -----
|
||||||
|
ASSIGN s-dec16 TO <numeric>.
|
||||||
|
ASSIGN s-dec34 TO <numeric>.
|
||||||
|
ASSIGN s-int TO <numeric>.
|
||||||
|
ASSIGN s-pl4d2 TO <numeric>.
|
||||||
|
"ASSIGN s-n4 TO <numeric>.
|
||||||
|
|
||||||
|
ASSIGN s-dec16 TO <decfloat>.
|
||||||
|
ASSIGN s-dec34 TO <decfloat>.
|
||||||
|
|
||||||
|
ASSIGN s-pl4d2 TO <p>.
|
||||||
|
"ASSIGN s-dec34 TO <p>.
|
||||||
|
|
||||||
|
"----- Internal table types -----
|
||||||
|
ASSIGN s-tab_std TO <any_table>.
|
||||||
|
ASSIGN s-tab_so TO <any_table>.
|
||||||
|
ASSIGN s-tab_ha TO <any_table>.
|
||||||
|
|
||||||
|
ASSIGN s-tab_std TO <index_table>.
|
||||||
|
ASSIGN s-tab_so TO <index_table>.
|
||||||
|
"ASSIGN s-tab_ha TO <index_table>.
|
||||||
|
|
||||||
|
"ASSIGN s-tab_std TO <sorted_table>.
|
||||||
|
ASSIGN s-tab_so TO <sorted_table>.
|
||||||
|
"ASSIGN s-tab_ha TO <sorted_table>.
|
||||||
|
|
||||||
|
ASSIGN s-tab_std TO <standard_table>.
|
||||||
|
ASSIGN s-tab_std TO <table>.
|
||||||
|
"ASSIGN s-tab_so TO <standard_table>.
|
||||||
|
"ASSIGN s-tab_so TO <table>.
|
||||||
|
"ASSIGN s-tab_ha TO <standard_table>.
|
||||||
|
"ASSIGN s-tab_ha TO <table>.
|
||||||
|
|
||||||
|
"ASSIGN s-tab_std TO <hashed_table>.
|
||||||
|
"ASSIGN s-tab_so TO <hashed_table>.
|
||||||
|
ASSIGN s-tab_ha TO <hashed_table>.
|
||||||
|
|
||||||
|
"----- Other types -----
|
||||||
|
ASSIGN s-c10 TO <simple>.
|
||||||
|
ASSIGN s-str TO <simple>.
|
||||||
|
ASSIGN s-dec34 TO <simple>.
|
||||||
|
ASSIGN s-date TO <simple>.
|
||||||
|
ASSIGN s-structure TO <simple>.
|
||||||
|
ASSIGN s-xl1 TO <simple>.
|
||||||
|
"ASSIGN s-tab_ha TO <simple>.
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `21a) Built-in data objects (1)` ) ).
|
||||||
|
|
||||||
"This example demonstrates the availability of built-in data objects in ABAP.
|
"This example demonstrates the availability of built-in data objects in ABAP.
|
||||||
|
|
||||||
@@ -1922,6 +2055,271 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
|
|
||||||
out->write( data = res_str name = `res_str` ).
|
out->write( data = res_str name = `res_str` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `21b) Built-in data objects (2)` ) ).
|
||||||
|
|
||||||
|
"This sections is an addition to the previous one.
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"------------------ sy-subrc: Return code of ABAP statements ------------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
"Many ABAP statements set a sy-subrc value. Check the ABAP Keyword Documentation
|
||||||
|
"for individual statements. Usually, the value 0 indicates a successful execution.
|
||||||
|
|
||||||
|
DATA(test_string) = `ABAP`.
|
||||||
|
|
||||||
|
"FIND statements
|
||||||
|
"Found
|
||||||
|
FIND `P` IN test_string.
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
|
||||||
|
"Not found
|
||||||
|
FIND `p` IN test_string RESPECTING CASE.
|
||||||
|
ASSERT sy-subrc = 4.
|
||||||
|
|
||||||
|
DATA(test_tab) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ( `d` ) ).
|
||||||
|
|
||||||
|
"READ TABLE statements
|
||||||
|
"Entry available
|
||||||
|
READ TABLE test_tab INTO DATA(wa1) INDEX 3.
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
|
||||||
|
"Entry not available
|
||||||
|
READ TABLE test_tab INTO DATA(wa2) INDEX 7.
|
||||||
|
ASSERT sy-subrc = 4.
|
||||||
|
|
||||||
|
"ABAP SQL statements
|
||||||
|
DELETE FROM zdemo_abap_tab1.
|
||||||
|
IF sy-subrc = 0.
|
||||||
|
out->write( `DELETE: All rows were deleted.` ).
|
||||||
|
ELSE.
|
||||||
|
out->write( `DELETE: No row was deleted because it was already empty.` ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 1 ) ( key_field = 2 ) ) ).
|
||||||
|
IF sy-subrc = 0.
|
||||||
|
out->write( `INSERT: All rows of the internal table were inserted.` ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 3 ) ( key_field = 3 ) ) ) ACCEPTING DUPLICATE KEYS.
|
||||||
|
IF sy-subrc = 4.
|
||||||
|
out->write( `INSERT ... ACCEPTING DUPLICATE KEYS: sy-subrc has the value 4 in this case. Not all rows of the ` &&
|
||||||
|
`internal table were inserted because a row with the key already exists.` ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
DELETE FROM zdemo_abap_tab1 WHERE key_field = 3.
|
||||||
|
IF sy-subrc = 0.
|
||||||
|
out->write( `DELETE: The row matching the WHERE condition was deleted.` ).
|
||||||
|
ELSE.
|
||||||
|
out->write( `DELETE: No match according to the WHERE condition.` ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
DELETE FROM zdemo_abap_tab1 WHERE key_field = 3.
|
||||||
|
IF sy-subrc = 0.
|
||||||
|
out->write( `DELETE: The row matching the WHERE condition was deleted.` ).
|
||||||
|
ELSE.
|
||||||
|
out->write( `DELETE: No match according to the WHERE condition.` ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"--------------------------- sy-index: Loop indexes ---------------------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
CLEAR test_string.
|
||||||
|
|
||||||
|
"DO loops
|
||||||
|
DO 5 TIMES.
|
||||||
|
test_string = test_string && sy-index.
|
||||||
|
ENDDO.
|
||||||
|
|
||||||
|
ASSERT test_string = `12345`.
|
||||||
|
|
||||||
|
CLEAR test_string.
|
||||||
|
|
||||||
|
DO 10 TIMES.
|
||||||
|
test_string = test_string && sy-index.
|
||||||
|
IF sy-index = 7.
|
||||||
|
EXIT.
|
||||||
|
ENDIF.
|
||||||
|
ENDDO.
|
||||||
|
|
||||||
|
ASSERT test_string = `1234567`.
|
||||||
|
|
||||||
|
CLEAR test_string.
|
||||||
|
|
||||||
|
DATA test_number TYPE i.
|
||||||
|
|
||||||
|
"WHILE loop
|
||||||
|
WHILE test_number < 9.
|
||||||
|
test_number = sy-index.
|
||||||
|
test_string = test_string && test_number.
|
||||||
|
ENDWHILE.
|
||||||
|
|
||||||
|
ASSERT test_string = `123456789`.
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"------------------- sy-tabix: Row index of internal tables -------------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
"Demo standard internal table with 5 entries
|
||||||
|
DATA(std_itab) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ( `d` ) ( `e` ) ).
|
||||||
|
|
||||||
|
"READ TABLE statement using a free key
|
||||||
|
READ TABLE std_itab INTO DATA(wa3) WITH KEY table_line = `b`.
|
||||||
|
ASSERT sy-tabix = 2.
|
||||||
|
|
||||||
|
"Demo hashed internal table with 5 entries
|
||||||
|
DATA(hashed_itab) = VALUE string_hashed_table( ( `a` ) ( `b` ) ( `c` ) ( `d` ) ( `e` ) ).
|
||||||
|
|
||||||
|
"READ TABLE statement using a free key
|
||||||
|
READ TABLE hashed_itab INTO DATA(wa4) WITH KEY table_line = `b`.
|
||||||
|
"Hashed tables do not have a primary table index.
|
||||||
|
ASSERT sy-tabix = 0.
|
||||||
|
|
||||||
|
CLEAR test_string.
|
||||||
|
|
||||||
|
"LOOP statements
|
||||||
|
LOOP AT std_itab INTO DATA(wa5).
|
||||||
|
test_string = test_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT test_string = `12345`.
|
||||||
|
|
||||||
|
CLEAR test_string.
|
||||||
|
"Step addition
|
||||||
|
"In the example, the table is looped across backwards
|
||||||
|
"indicated by the negative value. The step size 1 indicates
|
||||||
|
"that each line is respected.
|
||||||
|
LOOP AT std_itab INTO DATA(wa6) STEP -1.
|
||||||
|
test_string = test_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT test_string = `54321`.
|
||||||
|
|
||||||
|
CLEAR test_string.
|
||||||
|
"Forward loop, step size = 2
|
||||||
|
LOOP AT std_itab INTO DATA(wa7) STEP 2.
|
||||||
|
test_string = test_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT test_string = `135`.
|
||||||
|
|
||||||
|
CLEAR test_string.
|
||||||
|
"FROM/TO additions
|
||||||
|
LOOP AT std_itab INTO DATA(wa8) FROM 2 TO 4.
|
||||||
|
test_string = test_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT test_string = `234`.
|
||||||
|
|
||||||
|
CLEAR test_string.
|
||||||
|
"STEP/FROM additions
|
||||||
|
LOOP AT std_itab INTO DATA(wa9) STEP 2 FROM 2.
|
||||||
|
test_string = test_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT test_string = `24`.
|
||||||
|
|
||||||
|
CLEAR test_string.
|
||||||
|
"Hashed table
|
||||||
|
LOOP AT hashed_itab INTO DATA(wa10).
|
||||||
|
test_string = test_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT test_string = `00000`.
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"------------------------ sy-dbcnt: Edited table rows -------------------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
DELETE FROM zdemo_abap_tab1.
|
||||||
|
DATA(dbcnt) = sy-dbcnt.
|
||||||
|
|
||||||
|
out->write( |Dbtab rows deleted: { dbcnt }| ).
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 1 ) ( key_field = 2 ) ) ).
|
||||||
|
ASSERT sy-dbcnt = 2.
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 3 ) ( key_field = 3 ) ) ) ACCEPTING DUPLICATE KEYS.
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
MODIFY zdemo_abap_tab1 FROM @( VALUE #( key_field = 1 char1 = 'aaa' ) ).
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
UPDATE zdemo_abap_tab1 SET char2 = 'bbb'.
|
||||||
|
ASSERT sy-dbcnt = 3.
|
||||||
|
|
||||||
|
DELETE FROM zdemo_abap_tab1 WHERE num1 IS INITIAL.
|
||||||
|
ASSERT sy-dbcnt = 3.
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"------------- sy-fdpos: Occurrence in byte or character strings --------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"For example, relevant in comparison expressions such as CS (constains string).
|
||||||
|
"If the comparison is true, sy-fdpos contains the offset of the found value. If it
|
||||||
|
"is false, sy-fdpos contains the length of the searched string.
|
||||||
|
|
||||||
|
test_string = `###abap###`.
|
||||||
|
|
||||||
|
IF test_string CS `p`.
|
||||||
|
out->write( |The substring is found. Offset of first finding: { sy-fdpos }| ).
|
||||||
|
ELSE.
|
||||||
|
out->write( |The substring is not found. Length of searched string: { sy-fdpos }| ).
|
||||||
|
ASSERT sy-fdpos = strlen( test_string ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
IF test_string CS `#`.
|
||||||
|
out->write( |The substring is found. Offset of first finding: { sy-fdpos }| ).
|
||||||
|
ELSE.
|
||||||
|
out->write( |The substring is not found. Length of searched string: { sy-fdpos }| ).
|
||||||
|
ASSERT sy-fdpos = strlen( test_string ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
IF test_string CS `Y`.
|
||||||
|
out->write( |The substring is found. Offset of first finding: { sy-fdpos }| ).
|
||||||
|
ELSE.
|
||||||
|
out->write( |The substring is not found. Length of searched string: { sy-fdpos }| ).
|
||||||
|
ASSERT sy-fdpos = strlen( test_string ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"----------------------------- Constant space ---------------------------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"Has the data type c, length 1, and contains a blank character.
|
||||||
|
|
||||||
|
"Note: Trailing blanks are ignored in most operand positions. Therfore, the constant
|
||||||
|
"space should not be used in such positions.
|
||||||
|
|
||||||
|
test_string = |{ space }{ space }|.
|
||||||
|
ASSERT test_string = ``.
|
||||||
|
|
||||||
|
test_string = `#` && space && space && space && space && space && `#`.
|
||||||
|
ASSERT test_string = `##`.
|
||||||
|
|
||||||
|
"Using a CONCATENATE statement, blanks are respected after the SEPARATED BY
|
||||||
|
"addition only
|
||||||
|
CONCATENATE space space INTO test_string SEPARATED BY space.
|
||||||
|
ASSERT test_string = ` `.
|
||||||
|
|
||||||
|
"Text field literal, concatentation without SEPARATED BY space
|
||||||
|
DATA test_char TYPE c LENGTH 5.
|
||||||
|
CONCATENATE '#' space space '#' INTO test_char.
|
||||||
|
ASSERT test_char = '##'.
|
||||||
|
|
||||||
|
CONCATENATE space space '#' space '#' INTO test_char.
|
||||||
|
ASSERT test_char = '##'.
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"----------------------------- Self-reference me ------------------------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
DATA text TYPE string VALUE `Local data object 'text'`.
|
||||||
|
|
||||||
|
"Demo assignments
|
||||||
|
"dobj1 contains the value of the locally declared data object
|
||||||
|
DATA(dobj1) = text.
|
||||||
|
"dobj2 contains the value of the class attribute
|
||||||
|
DATA(dobj2) = me->text.
|
||||||
|
|
||||||
|
out->write( data = dobj1 name = `dobj1` ).
|
||||||
|
out->write( data = dobj2 name = `dobj2` ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `22) Declaration context` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `22) Declaration context` ) ).
|
||||||
@@ -2011,6 +2409,37 @@ CLASS zcl_demo_abap_dtype_dobj IMPLEMENTATION.
|
|||||||
DATA(output_for_rtti_enum) = rtti_enum( ).
|
DATA(output_for_rtti_enum) = rtti_enum( ).
|
||||||
out->write( data = output_for_rtti_enum name = `output_for_rtti_enum` ).
|
out->write( data = output_for_rtti_enum name = `output_for_rtti_enum` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `24) Typed literals` ) ).
|
||||||
|
|
||||||
|
"Miscellaneous typed literals in an ABAP SQL statement
|
||||||
|
"Note that typed literals can be specified in read
|
||||||
|
"positions where host variables are possible.
|
||||||
|
DATA(tmstamp) = CONV timestamp( '20240808112517' ).
|
||||||
|
some_string = `Some string`.
|
||||||
|
SELECT SINGLE
|
||||||
|
FROM zdemo_abap_fli
|
||||||
|
FIELDS
|
||||||
|
carrid,
|
||||||
|
@some_string AS host_var,
|
||||||
|
char`X` AS flag,
|
||||||
|
int8`32984723948723` AS int8,
|
||||||
|
raw`11` AS raw,
|
||||||
|
numc`1234` AS numc,
|
||||||
|
utclong`2024-01-01T10:01:02,2` AS utc,
|
||||||
|
tims`101507` AS tims,
|
||||||
|
curr`173.95` AS curr,
|
||||||
|
"Multiple cast expressions splitting a time stamp into date and time parts
|
||||||
|
CAST( CAST( div( @tmstamp, 1000000 ) AS CHAR ) AS DATS ) AS date,
|
||||||
|
CAST( substring( CAST( @tmstamp AS CHAR ), 9, 6 ) AS TIMS ) AS time,
|
||||||
|
"Untyped literal
|
||||||
|
'ABAP' AS txt
|
||||||
|
WHERE fldate = datn`20240102`
|
||||||
|
INTO @DATA(wa_misc_typed_literals).
|
||||||
|
|
||||||
|
out->write( data = wa_misc_typed_literals name = `wa_misc_typed_literals` ).
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
METHOD rtti_enum.
|
METHOD rtti_enum.
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
1082
src/zcl_demo_abap_error_handling.clas.abap
Normal file
1082
src/zcl_demo_abap_error_handling.clas.abap
Normal file
File diff suppressed because it is too large
Load Diff
16
src/zcl_demo_abap_error_handling.clas.xml
Normal file
16
src/zcl_demo_abap_error_handling.clas.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||||
|
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||||
|
<asx:values>
|
||||||
|
<VSEOCLASS>
|
||||||
|
<CLSNAME>ZCL_DEMO_ABAP_ERROR_HANDLING</CLSNAME>
|
||||||
|
<LANGU>E</LANGU>
|
||||||
|
<DESCRIPT>ABAP cheat sheet: Exceptions and Runtime Errors</DESCRIPT>
|
||||||
|
<STATE>1</STATE>
|
||||||
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
|
<FIXPT>X</FIXPT>
|
||||||
|
<UNICODE>X</UNICODE>
|
||||||
|
</VSEOCLASS>
|
||||||
|
</asx:values>
|
||||||
|
</asx:abap>
|
||||||
|
</abapGit>
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,51 +1,18 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>ABAP object orientation</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: ABAP object orientation
|
"! <p>The example class demonstrates syntax and concepts related to ABAP object orientation.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Example to demonstrate various syntax options and concepts related
|
"! <h2>Note</h2>
|
||||||
* to ABAP object orientation.
|
"! <ul><li>Topics covered include working with objects and components, method redefinition in inheritance,
|
||||||
* - Topics covered: Working with objects and components, method redefinition
|
"! using interfaces, upcasting and downcasting, and concepts like factory methods, singletons, abstract
|
||||||
* in inheritance, working with interfaces, upcast and downcast, concepts
|
"! classes, and events.</li>
|
||||||
* like factory methods, singleton and abstract classes, using events.
|
"! <li>The CCIMP include (local types tab in ADT) contains multiple local classes to support the example.</li>
|
||||||
* - The CCIMP include (local types tab in ADT) includes multiple local
|
"! <li>Artifacts related to this example: {@link zdemo_abap_objects_interface} (a separate global interface to
|
||||||
* classes to support the example.
|
"! demonstrate interface usage) and {@link zcl_demo_abap_objects_friend} (another global class used to
|
||||||
* - Artifacts related to this example:
|
"! demonstrate the concept of friendship</li>
|
||||||
* - zdemo_abap_objects_interface: Separate global interface to demonstrate
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* working with interfaces
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li></ul>
|
||||||
* - zcl_demo_abap_objects_friend: Another global class used to demonstrate
|
|
||||||
* the concept of friendship
|
|
||||||
*
|
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
|
||||||
* - 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
|
|
||||||
* 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)
|
|
||||||
* 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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: ABAP object orientation</p>
|
|
||||||
"! Example to demonstrate concepts related to ABAP object orientation.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_objects DEFINITION
|
CLASS zcl_demo_abap_objects DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -98,7 +65,7 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
|
|||||||
|
|
||||||
METHOD if_oo_adt_classrun~main.
|
METHOD if_oo_adt_classrun~main.
|
||||||
|
|
||||||
out->write( |ABAP Cheat Sheet Example: ABAP Object Orientation\n\n| ).
|
out->write( |ABAP cheat sheet example: ABAP Object Orientation (1)\n\n| ).
|
||||||
out->write( |Working with objects and components\n\n| ).
|
out->write( |Working with objects and components\n\n| ).
|
||||||
out->write( |1) Declaring reference variables\n\n| ).
|
out->write( |1) Declaring reference variables\n\n| ).
|
||||||
|
|
||||||
@@ -1108,4 +1075,33 @@ CLASS zcl_demo_abap_objects IMPLEMENTATION.
|
|||||||
zdemo_abap_objects_interface~stat_str = `The result of calling zdemo_abap_objects_interface~halve is: `.
|
zdemo_abap_objects_interface~stat_str = `The result of calling zdemo_abap_objects_interface~halve is: `.
|
||||||
r_halve = i_op / 2.
|
r_halve = i_op / 2.
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD zdemo_abap_objects_interface~addition.
|
||||||
|
... "No implementation included since the method is not used in this example class.
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD zdemo_abap_objects_interface~subtraction.
|
||||||
|
... "No implementation included since the method is not used in this example class.
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD zdemo_abap_objects_interface~meth_fail.
|
||||||
|
...
|
||||||
|
"No implementation included since the method is not used in this example class.
|
||||||
|
"Interface methods declared with DEFAULT IGNORE and DEFAULT FAIL are not required
|
||||||
|
"to be implemented, i.e. specifying
|
||||||
|
"METHOD zdemo_abap_objects_interface~meth_fail.
|
||||||
|
" ...
|
||||||
|
"ENDMETHOD.
|
||||||
|
"is not required. Ususally, all interface methods must be implemented.
|
||||||
|
"See the example class zcl_demo_abap_objects_misc that also implements the
|
||||||
|
"interface, but does not include the method implementations.
|
||||||
|
"If implementations are desired, you can manually add the implementations (if
|
||||||
|
"not automatically added using the ADT quickfix when adding the interface) for
|
||||||
|
"these methods.
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD zdemo_abap_objects_interface~meth_ignore.
|
||||||
|
... "See the comment in the method implementation of zdemo_abap_objects_interface~meth_fail.
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<VSEOCLASS>
|
<VSEOCLASS>
|
||||||
<CLSNAME>ZCL_DEMO_ABAP_OBJECTS</CLSNAME>
|
<CLSNAME>ZCL_DEMO_ABAP_OBJECTS</CLSNAME>
|
||||||
<LANGU>E</LANGU>
|
<LANGU>E</LANGU>
|
||||||
<DESCRIPT>ABAP cheat sheet: ABAP Object Orientation</DESCRIPT>
|
<DESCRIPT>ABAP cheat sheet: ABAP object orientation</DESCRIPT>
|
||||||
<STATE>1</STATE>
|
<STATE>1</STATE>
|
||||||
<CLSCCINCL>X</CLSCCINCL>
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
<FIXPT>X</FIXPT>
|
<FIXPT>X</FIXPT>
|
||||||
|
|||||||
@@ -1,23 +1,11 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>Class supporting the ABAP object orientation example</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* Class supporting an ABAP cheat sheet example
|
"! <p>The example class supports the ABAP object orientation example.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* ----------------------------- NOTE -----------------------------------
|
"!
|
||||||
* The code presented in this class is intended only to support the ABAP
|
"! <h2>Note</h2>
|
||||||
* cheat sheets. It is not intended for direct use in a production system
|
"! <p>Find the <strong>disclaimer</strong> in the ABAP Doc comment of class
|
||||||
* environment. The code examples in the ABAP cheat sheets are primarily
|
"! {@link zcl_demo_abap_aux}.</p>
|
||||||
* intended to provide a better explanation and visualization of the
|
|
||||||
* syntax and semantics of ABAP statements, not to solve concrete
|
|
||||||
* programming tasks. For production application programs, you should
|
|
||||||
* always work out your own solution for each individual case. There is
|
|
||||||
* no guarantee for the correctness or completeness of the code.
|
|
||||||
* Furthermore, there is no legal responsibility or liability for any
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">Class supporting ABAP cheat sheet example</p>
|
|
||||||
"! The class supports the ABAP cheat sheet example about object orientation.
|
|
||||||
CLASS zcl_demo_abap_objects_friend DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
CLASS zcl_demo_abap_objects_friend DEFINITION PUBLIC FINAL CREATE PUBLIC.
|
||||||
|
|
||||||
PUBLIC SECTION.
|
PUBLIC SECTION.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<VSEOCLASS>
|
<VSEOCLASS>
|
||||||
<CLSNAME>ZCL_DEMO_ABAP_OBJECTS_FRIEND</CLSNAME>
|
<CLSNAME>ZCL_DEMO_ABAP_OBJECTS_FRIEND</CLSNAME>
|
||||||
<LANGU>E</LANGU>
|
<LANGU>E</LANGU>
|
||||||
<DESCRIPT>Class for ABAP cheat sheet example</DESCRIPT>
|
<DESCRIPT>Class supporting ABAP cheat sheet example</DESCRIPT>
|
||||||
<STATE>1</STATE>
|
<STATE>1</STATE>
|
||||||
<CLSCCINCL>X</CLSCCINCL>
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
<FIXPT>X</FIXPT>
|
<FIXPT>X</FIXPT>
|
||||||
|
|||||||
1067
src/zcl_demo_abap_objects_misc.clas.abap
Normal file
1067
src/zcl_demo_abap_objects_misc.clas.abap
Normal file
File diff suppressed because it is too large
Load Diff
2
src/zcl_demo_abap_objects_misc.clas.locals_def.abap
Normal file
2
src/zcl_demo_abap_objects_misc.clas.locals_def.abap
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
CLASS local_class DEFINITION DEFERRED.
|
||||||
|
CLASS zcl_demo_abap_objects_misc DEFINITION LOCAL FRIENDS local_class.
|
||||||
15
src/zcl_demo_abap_objects_misc.clas.locals_imp.abap
Normal file
15
src/zcl_demo_abap_objects_misc.clas.locals_imp.abap
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
CLASS local_class DEFINITION FRIENDS zcl_demo_abap_objects_misc.
|
||||||
|
|
||||||
|
PUBLIC SECTION.
|
||||||
|
PROTECTED SECTION.
|
||||||
|
PRIVATE SECTION.
|
||||||
|
CLASS-DATA hello TYPE zcl_demo_abap_objects_misc=>str4friend.
|
||||||
|
CLASS-METHODS say_hello.
|
||||||
|
|
||||||
|
ENDCLASS.
|
||||||
|
|
||||||
|
CLASS local_class IMPLEMENTATION.
|
||||||
|
METHOD say_hello.
|
||||||
|
hello = |{ zcl_demo_abap_objects_misc=>get_hello( ) } { sy-uname }.|.
|
||||||
|
ENDMETHOD.
|
||||||
|
ENDCLASS.
|
||||||
16
src/zcl_demo_abap_objects_misc.clas.xml
Normal file
16
src/zcl_demo_abap_objects_misc.clas.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||||
|
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||||
|
<asx:values>
|
||||||
|
<VSEOCLASS>
|
||||||
|
<CLSNAME>ZCL_DEMO_ABAP_OBJECTS_MISC</CLSNAME>
|
||||||
|
<LANGU>E</LANGU>
|
||||||
|
<DESCRIPT>ABAP cheat sheet: ABAP object orientation</DESCRIPT>
|
||||||
|
<STATE>1</STATE>
|
||||||
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
|
<FIXPT>X</FIXPT>
|
||||||
|
<UNICODE>X</UNICODE>
|
||||||
|
</VSEOCLASS>
|
||||||
|
</asx:values>
|
||||||
|
</asx:abap>
|
||||||
|
</abapGit>
|
||||||
219
src/zcl_demo_abap_oo_inheritance_1.clas.abap
Normal file
219
src/zcl_demo_abap_oo_inheritance_1.clas.abap
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
"! <p class="shorttext"><strong>ABAP object orientation - Inheritance</strong><br/>ABAP cheat sheet example class</p>
|
||||||
|
"!
|
||||||
|
"! <p>The example class explores inheritance and demonstrate a selection of the inheritance-related syntax.
|
||||||
|
"! The inheritance tree consists of four example classes. The base class {@link zcl_demo_abap_oo_inheritance_1}
|
||||||
|
"! includes the implementation of the classrun interface. Choose F9 in ADT to run the class.</p>
|
||||||
|
"! <p>Classes of the inheritance tree:</p>
|
||||||
|
"! <ul><li>{@link zcl_demo_abap_oo_inheritance_1}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_2}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_3}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_4}</li>
|
||||||
|
"! </ul>
|
||||||
|
"!
|
||||||
|
"! <h2>Purpose</h2>
|
||||||
|
"! <p>The purpose of the example and information output is to visualize and explore concepts and syntax related to
|
||||||
|
"! inheritance, checking out when and how methods are called, redefining methods, abstract and final classes and methods.</p>
|
||||||
|
"!
|
||||||
|
"! <h2>General notes on the example</h2>
|
||||||
|
"! <p>Many instance methods are declared in all classes to demonstrate inheritance. However, there is no meaningful implementation
|
||||||
|
"! in these methods in all classes. All instance methods include the same code. The purpose of the code in the method implementations
|
||||||
|
"! is to add a line to a log table (which is output to the console) with various pieces of information:</p>
|
||||||
|
"! <ul><li>Name of the method that is called</li>
|
||||||
|
"! <li>In which class the method is implemented when it is called</li>
|
||||||
|
"! <li>From which class the method is called</li>
|
||||||
|
"! <li>Whether the method is inherited, redefined, final, or a static method</li>
|
||||||
|
"! <li>Visibility of the method</li>
|
||||||
|
"! <li>Visibility of the method</li></ul>
|
||||||
|
"! <p>The information retrieval is implemented in a static method in the {@link zcl_demo_abap_oo_inheritance_1} class by getting callstack
|
||||||
|
"! information to determine which method in which class was called by whom. Based on the retrieved class and method names, RTTI
|
||||||
|
"! is used to get detailed information about the methods.</p>
|
||||||
|
"!
|
||||||
|
"! <h2>Notes on this class</h2>
|
||||||
|
"! <ul><li>Allows inheritance and represents the root class of the inheritance hierarchy</li>
|
||||||
|
"! <li>Declares several instance methods in each visibility section</li>
|
||||||
|
"! <li>One of them is declared with FINAL, so no redefinition is possible in subclasses.</li>
|
||||||
|
"! <li>Includes the implementation of the classrun interface meaning this class is executable using F9 in ADT.</li>
|
||||||
|
"! <li>The class includes an internal table that represents a log table and that is output to the console as described above.</li></ul>
|
||||||
|
"!
|
||||||
|
"! <h2>More information</h2>
|
||||||
|
"! <p>Find information on <strong>getting started with the example class</strong> and the
|
||||||
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
|
||||||
|
CLASS zcl_demo_abap_oo_inheritance_1 DEFINITION
|
||||||
|
PUBLIC
|
||||||
|
CREATE PUBLIC .
|
||||||
|
|
||||||
|
PUBLIC SECTION.
|
||||||
|
"Classrun interface
|
||||||
|
INTERFACES if_oo_adt_classrun.
|
||||||
|
|
||||||
|
"Instance/static constructor declarations
|
||||||
|
METHODS constructor.
|
||||||
|
CLASS-METHODS class_constructor.
|
||||||
|
|
||||||
|
"Instance method declarations
|
||||||
|
METHODS meth_public_1.
|
||||||
|
"Final method
|
||||||
|
METHODS meth_public_1_final FINAL.
|
||||||
|
|
||||||
|
"Components used for logging information about method calls
|
||||||
|
TYPES: BEGIN OF s_log,
|
||||||
|
method TYPE string,
|
||||||
|
implemented_where TYPE string,
|
||||||
|
called_from TYPE syrepid,
|
||||||
|
is_inherited TYPE abap_boolean,
|
||||||
|
is_redefined TYPE abap_boolean,
|
||||||
|
is_final TYPE abap_boolean,
|
||||||
|
visibility TYPE abap_visibility,
|
||||||
|
is_static_method TYPE abap_boolean,
|
||||||
|
called_at TYPE utclong,
|
||||||
|
END OF s_log,
|
||||||
|
t_log TYPE TABLE OF s_log WITH EMPTY KEY.
|
||||||
|
|
||||||
|
CLASS-DATA log_tab TYPE t_log.
|
||||||
|
CLASS-METHODS get_method_info RETURNING VALUE(info) TYPE s_log.
|
||||||
|
|
||||||
|
PROTECTED SECTION.
|
||||||
|
METHODS meth_protected_1.
|
||||||
|
|
||||||
|
PRIVATE SECTION.
|
||||||
|
METHODS meth_private_1.
|
||||||
|
ENDCLASS.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CLASS zcl_demo_abap_oo_inheritance_1 IMPLEMENTATION.
|
||||||
|
METHOD if_oo_adt_classrun~main.
|
||||||
|
|
||||||
|
out->write( |ABAP cheat sheet example: ABAP Object Orientation - Inheritance\n\n| ).
|
||||||
|
|
||||||
|
"----- First level in the inheritance hierarchy ----
|
||||||
|
"Creating an instance of the class
|
||||||
|
DATA(oref_super) = NEW zcl_demo_abap_oo_inheritance_1( ).
|
||||||
|
|
||||||
|
"Calling methods of the class
|
||||||
|
oref_super->meth_public_1( ).
|
||||||
|
oref_super->meth_public_1_final( ).
|
||||||
|
oref_super->meth_protected_1( ).
|
||||||
|
oref_super->meth_private_1( ).
|
||||||
|
|
||||||
|
"----- Second level in the inheritance hierarchy ----
|
||||||
|
"The instance creation and method calling is delegated to
|
||||||
|
"a static method in the class
|
||||||
|
zcl_demo_abap_oo_inheritance_2=>perform_meth_calls_2( ).
|
||||||
|
|
||||||
|
"----- Third level in the inheritance hierarchy ----
|
||||||
|
"Note: The class zcl_demo_abap_oo_inheritance_3 is abstract and contains
|
||||||
|
"both non-abstract and abstract instance methods. Instances of abstract
|
||||||
|
"classes cannot be created. So, the following statement is not possible.
|
||||||
|
"DATA(oref_3) = NEW zcl_demo_abap_oo_inheritance_3( ).
|
||||||
|
|
||||||
|
"Instance components of an abstract class can be accessed via its subclasses.
|
||||||
|
"zcl_demo_abap_oo_inheritance_4 inherits from zcl_demo_abap_oo_inheritance_3 and
|
||||||
|
"redefines methods of zcl_demo_abap_oo_inheritance_3. Both abstract methods (which
|
||||||
|
"are mandatory to implement) and non-abstract methods are redefined. To also access
|
||||||
|
"the method implementations of the non-abstract instance methods of
|
||||||
|
"zcl_demo_abap_oo_inheritance_3, the respective implementations of the redefined
|
||||||
|
"methods in zcl_demo_abap_oo_inheritance_4 include method calls to the direct
|
||||||
|
"superclass using the syntax super->meth( ).. The instance methods of
|
||||||
|
"zcl_demo_abap_oo_inheritance_3 are called in the context of the static method call
|
||||||
|
"via zcl_demo_abap_oo_inheritance_4 below.
|
||||||
|
|
||||||
|
"----- Fourth level in the inheritance hierarchy ----
|
||||||
|
"As above, the instance creation and method calling is delegated to
|
||||||
|
"a static method in the class. This method call includes method calls to
|
||||||
|
"non-abstract instance methods implemented in zcl_demo_abap_oo_inheritance_3.
|
||||||
|
zcl_demo_abap_oo_inheritance_4=>perform_meth_calls_4( ).
|
||||||
|
|
||||||
|
"Writing the log table to the console
|
||||||
|
out->write( data = log_tab name = `log_tab` ).
|
||||||
|
|
||||||
|
"Excursion: Using RTTI to retrieve the name of the superclass
|
||||||
|
"As this class starts an inheritance hierarchy, the superclass of this class
|
||||||
|
"is the root class OBJECT.
|
||||||
|
DATA(tdo_cl) = CAST cl_abap_classdescr( cl_abap_typedescr=>describe_by_name( 'ZCL_DEMO_ABAP_OO_INHERITANCE_1' ) ).
|
||||||
|
DATA(superclass) = tdo_cl->get_super_class_type( )->get_relative_name( ).
|
||||||
|
out->write( |\n\n| ).
|
||||||
|
out->write( data = superclass name = `superclass` ).
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD class_constructor.
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD constructor.
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_private_1.
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_protected_1.
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_1.
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_1_final.
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD get_method_info.
|
||||||
|
"This method retrieves callstack information to determine which method in which
|
||||||
|
"class was called by whom.
|
||||||
|
"Based on the retrieved class and method names, RTTI is used to get detailed
|
||||||
|
"information about methods (such as the visibility or whether the method is
|
||||||
|
"inherited, redefined, final, and a static method).
|
||||||
|
|
||||||
|
"Getting callstack information
|
||||||
|
DATA(call_stack_tab) = xco_cp=>current->call_stack->full( )->from->position( 2
|
||||||
|
)->to->position( 2 )->as_text( xco_cp_call_stack=>format->adt( )
|
||||||
|
)->get_lines( )->value.
|
||||||
|
|
||||||
|
IF lines( call_stack_tab ) < 2.
|
||||||
|
RETURN.
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
LOOP AT call_stack_tab INTO DATA(wa) TO 2.
|
||||||
|
DATA(tabix) = sy-tabix.
|
||||||
|
SPLIT wa AT ` ` INTO TABLE DATA(entry).
|
||||||
|
DELETE entry WHERE table_line IS INITIAL.
|
||||||
|
|
||||||
|
DATA(class_name) = condense( val = entry[ 1 ] to = `` ).
|
||||||
|
|
||||||
|
IF tabix = 1.
|
||||||
|
info-implemented_where = class_name.
|
||||||
|
|
||||||
|
DATA(meth_name) = condense( val = to_upper( entry[ 2 ] ) to = `` ).
|
||||||
|
info-method = meth_name.
|
||||||
|
|
||||||
|
IF class_name IS NOT INITIAL AND meth_name IS NOT INITIAL.
|
||||||
|
DATA(tdo_cl) = CAST cl_abap_classdescr( cl_abap_typedescr=>describe_by_name( class_name ) ).
|
||||||
|
DATA(methods_cl) = tdo_cl->methods.
|
||||||
|
DATA(meth_info) = VALUE #( methods_cl[ name = meth_name ] OPTIONAL ).
|
||||||
|
IF meth_info IS NOT INITIAL.
|
||||||
|
info-is_inherited = meth_info-is_inherited.
|
||||||
|
info-is_redefined = meth_info-is_redefined.
|
||||||
|
info-is_final = meth_info-is_final.
|
||||||
|
info-visibility = meth_info-visibility.
|
||||||
|
info-is_static_method = meth_info-is_class.
|
||||||
|
ENDIF.
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
ELSE.
|
||||||
|
info-called_from = class_name.
|
||||||
|
ENDIF.
|
||||||
|
ENDLOOP.
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
ENDCLASS.
|
||||||
16
src/zcl_demo_abap_oo_inheritance_1.clas.xml
Normal file
16
src/zcl_demo_abap_oo_inheritance_1.clas.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||||
|
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||||
|
<asx:values>
|
||||||
|
<VSEOCLASS>
|
||||||
|
<CLSNAME>ZCL_DEMO_ABAP_OO_INHERITANCE_1</CLSNAME>
|
||||||
|
<LANGU>E</LANGU>
|
||||||
|
<DESCRIPT>ABAP cheat sheet: ABAP object orientation - Inheritance</DESCRIPT>
|
||||||
|
<STATE>1</STATE>
|
||||||
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
|
<FIXPT>X</FIXPT>
|
||||||
|
<UNICODE>X</UNICODE>
|
||||||
|
</VSEOCLASS>
|
||||||
|
</asx:values>
|
||||||
|
</asx:abap>
|
||||||
|
</abapGit>
|
||||||
145
src/zcl_demo_abap_oo_inheritance_2.clas.abap
Normal file
145
src/zcl_demo_abap_oo_inheritance_2.clas.abap
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
"! <p class="shorttext"><strong>ABAP object orientation - Inheritance</strong><br/>ABAP cheat sheet example class</p>
|
||||||
|
"!
|
||||||
|
"! <p>The example class explores inheritance and demonstrate a selection of the inheritance-related syntax.
|
||||||
|
"! The inheritance tree consists of four example classes. The base class {@link zcl_demo_abap_oo_inheritance_1}
|
||||||
|
"! includes the implementation of the classrun interface. Choose F9 in ADT to run the base class.</p>
|
||||||
|
"! <p>Classes of the inheritance tree:</p>
|
||||||
|
"! <ul><li>{@link zcl_demo_abap_oo_inheritance_1}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_2}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_3}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_4}</li>
|
||||||
|
"! </ul>
|
||||||
|
"!
|
||||||
|
"! <h2>Notes on this class</h2>
|
||||||
|
"! <ul><li>Specifies <em>CREATE PROTECTED</em>, so the class can only be instantiated in methods of its subclasses,
|
||||||
|
"! of the class itself, and of its friends</li>
|
||||||
|
"! <li>You may want to try to create an instance of the class in {@link zcl_demo_abap_oo_inheritance_1}
|
||||||
|
"! like this <em>DATA(oref) = NEW zcl_demo_abap_oo_inheritance_2( ).</em>. It is not possible. In
|
||||||
|
"! {@link zcl_demo_abap_oo_inheritance_3} and {@link zcl_demo_abap_oo_inheritance_4}, for example, it is
|
||||||
|
"! possible.</li>
|
||||||
|
"! <li>Declares several instance methods</li>
|
||||||
|
"! <li>One of them is declared with <em>FINAL</em>, so no redefinition is possible in subclasses</li>
|
||||||
|
"! <li>Instance methods of the direct superclass are redefined</li>
|
||||||
|
"! <li>Note: Private methods of superclasses cannot be redefined. You cannot specify abstract methods, which
|
||||||
|
"! is only possible in abstract classes. Abstract methods are generally not possible in the private visibility
|
||||||
|
"! section since they cannot be redefined.</li>
|
||||||
|
"! <li>Declares a static method to delegate method calls of this class</li>
|
||||||
|
"! <li>The implementation includes the creation of an instance of the class and instance method calls
|
||||||
|
"! (including redefined methods).</li>
|
||||||
|
"! <li>It is called in the classrun implementation in {@link zcl_demo_abap_oo_inheritance_1}.</li></ul>
|
||||||
|
"!
|
||||||
|
"! <h2>More information</h2>
|
||||||
|
"! <ul><li>Find general information on the inheritance example in class {@link zcl_demo_abap_oo_inheritance_1}</li>
|
||||||
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li></ul>
|
||||||
|
CLASS zcl_demo_abap_oo_inheritance_2 DEFINITION
|
||||||
|
INHERITING FROM zcl_demo_abap_oo_inheritance_1
|
||||||
|
PUBLIC
|
||||||
|
CREATE PROTECTED .
|
||||||
|
|
||||||
|
PUBLIC SECTION.
|
||||||
|
"Instance/static constructor declarations
|
||||||
|
METHODS constructor.
|
||||||
|
CLASS-METHODS class_constructor.
|
||||||
|
|
||||||
|
"Instance method declarations
|
||||||
|
METHODS meth_public_2.
|
||||||
|
METHODS meth_public_2_final FINAL.
|
||||||
|
|
||||||
|
"Static method declaration for display purposes
|
||||||
|
CLASS-METHODS perform_meth_calls_2.
|
||||||
|
|
||||||
|
"Redefining method from the class one level up in the inheritance hierarchy
|
||||||
|
"(i.e. the direct superclass)
|
||||||
|
METHODS meth_public_1 REDEFINITION.
|
||||||
|
|
||||||
|
"Excursions:
|
||||||
|
"- Redefining the final public method of the superclass is not possible.
|
||||||
|
"- The same applies to constructors.
|
||||||
|
"- The following type has the same name as a type in the superclass. Since components
|
||||||
|
" are inherited, the following declaration is not possible.
|
||||||
|
"TYPES t_log TYPE string_table.
|
||||||
|
"- Similary, the log table, which is a static component in the superclass, can be
|
||||||
|
" referenced in the method implementations using 'log_table'. Using the class name
|
||||||
|
" and => is also possible, but not required.
|
||||||
|
"INSERT VALUE #( ) INTO TABLE zcl_demo_abap_oo_inheritance_1=>log_tab.
|
||||||
|
|
||||||
|
PROTECTED SECTION.
|
||||||
|
"Instance method declaration
|
||||||
|
METHODS meth_protected_2.
|
||||||
|
|
||||||
|
"Redefining method from the class one level up in the inheritance hierarchy
|
||||||
|
"(i.e. the direct superclass)
|
||||||
|
METHODS meth_protected_1 REDEFINITION.
|
||||||
|
|
||||||
|
PRIVATE SECTION.
|
||||||
|
"Ecursion:
|
||||||
|
"- The following declarations are not possible.
|
||||||
|
"- Private methods cannot be redefined.
|
||||||
|
"METHODS meth_private_1 REDEFINITION.
|
||||||
|
"- Abstract methods can only be declared in abstract classes. And, since
|
||||||
|
" private methods cannot be redefined, abstract private methods are not
|
||||||
|
" possible.
|
||||||
|
"METHODS meth_private_2_abstract ABSTRACT.
|
||||||
|
ENDCLASS.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CLASS zcl_demo_abap_oo_inheritance_2 IMPLEMENTATION.
|
||||||
|
METHOD class_constructor.
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD constructor.
|
||||||
|
super->constructor( ).
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_2.
|
||||||
|
"Method of this class
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_2_final.
|
||||||
|
"Method of this class
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_protected_2.
|
||||||
|
"Method of this class
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_1.
|
||||||
|
"Reimplementing a method from the class one level up in the inheritance hierarchy (direct superclass)
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_protected_1.
|
||||||
|
"Reimplementing a method from the class one level up in the inheritance hierarchy (direct superclass)
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD perform_meth_calls_2.
|
||||||
|
"Method of this class
|
||||||
|
"Creating an instance of the class
|
||||||
|
DATA(oref_2) = NEW zcl_demo_abap_oo_inheritance_2( ).
|
||||||
|
|
||||||
|
"Calling methods of this class
|
||||||
|
oref_2->meth_public_2( ).
|
||||||
|
oref_2->meth_public_2_final( ).
|
||||||
|
oref_2->meth_protected_2( ).
|
||||||
|
"Calling redefined methods from the class one level up in the inheritance hierarchy (direct superclass)
|
||||||
|
oref_2->meth_protected_1( ).
|
||||||
|
oref_2->meth_public_1( ).
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
ENDCLASS.
|
||||||
16
src/zcl_demo_abap_oo_inheritance_2.clas.xml
Normal file
16
src/zcl_demo_abap_oo_inheritance_2.clas.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||||
|
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||||
|
<asx:values>
|
||||||
|
<VSEOCLASS>
|
||||||
|
<CLSNAME>ZCL_DEMO_ABAP_OO_INHERITANCE_2</CLSNAME>
|
||||||
|
<LANGU>E</LANGU>
|
||||||
|
<DESCRIPT>ABAP cheat sheet: ABAP object orientation - Inheritance</DESCRIPT>
|
||||||
|
<STATE>1</STATE>
|
||||||
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
|
<FIXPT>X</FIXPT>
|
||||||
|
<UNICODE>X</UNICODE>
|
||||||
|
</VSEOCLASS>
|
||||||
|
</asx:values>
|
||||||
|
</asx:abap>
|
||||||
|
</abapGit>
|
||||||
115
src/zcl_demo_abap_oo_inheritance_3.clas.abap
Normal file
115
src/zcl_demo_abap_oo_inheritance_3.clas.abap
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
"! <p class="shorttext"><strong>ABAP object orientation - Inheritance</strong><br/>ABAP cheat sheet example class</p>
|
||||||
|
"!
|
||||||
|
"! <p>The example class explores inheritance and demonstrate a selection of the inheritance-related syntax.
|
||||||
|
"! The inheritance tree consists of four example classes. The base class {@link zcl_demo_abap_oo_inheritance_1}
|
||||||
|
"! includes the implementation of the classrun interface. Choose F9 in ADT to run the base class.</p>
|
||||||
|
"! <p>Classes of the inheritance tree:</p>
|
||||||
|
"! <ul><li>{@link zcl_demo_abap_oo_inheritance_1}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_2}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_3}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_4}</li>
|
||||||
|
"! </ul>
|
||||||
|
"!
|
||||||
|
"! <h2>Notes on this class</h2>
|
||||||
|
"! <ul><li>Inherits from {@link zcl_demo_abap_oo_inheritance_1} and thus from {@link zcl_demo_abap_oo_inheritance_2}</li>
|
||||||
|
"! <li>Declared as abstract class using the <em>ABSTRACT</em> addition, so no instances can be created from the class</li>
|
||||||
|
"! <li>Declares several instance methods</li>
|
||||||
|
"! <li>Two abstract methods are included using the <em>ABSTRACT</em> addition, so they can only be implemented in subclasses (there
|
||||||
|
"! is no implementation of these methods in the class)</li>
|
||||||
|
"! <li>Instance methods of the direct superclass are redefined as well as methods from two levels up the inheritance hierarchy</li>
|
||||||
|
"! <li>One redefined method specifies <em>FINAL REDEFINITION</em>, so a further redefinition in subclasses is not possible.</li></ul>
|
||||||
|
"!
|
||||||
|
"! <h2>More information</h2>
|
||||||
|
"! <ul><li>Find general information on the inheritance example in class {@link zcl_demo_abap_oo_inheritance_1}</li>
|
||||||
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li></ul>
|
||||||
|
CLASS zcl_demo_abap_oo_inheritance_3 DEFINITION
|
||||||
|
INHERITING FROM zcl_demo_abap_oo_inheritance_2
|
||||||
|
PUBLIC
|
||||||
|
ABSTRACT
|
||||||
|
CREATE PUBLIC .
|
||||||
|
|
||||||
|
PUBLIC SECTION.
|
||||||
|
"Instance/static constructor declarations
|
||||||
|
METHODS constructor.
|
||||||
|
CLASS-METHODS class_constructor.
|
||||||
|
|
||||||
|
"Instance method declarations
|
||||||
|
METHODS meth_public_3.
|
||||||
|
"Abstract method
|
||||||
|
METHODS meth_public_3_abstract ABSTRACT.
|
||||||
|
|
||||||
|
"Redefining methods from the class ...
|
||||||
|
"... one level up in the inheritance hierarchy (i.e. the direct superclass)
|
||||||
|
METHODS meth_public_2 REDEFINITION.
|
||||||
|
"... two levels up in the inheritance hierarchy
|
||||||
|
METHODS meth_public_1 REDEFINITION.
|
||||||
|
|
||||||
|
PROTECTED SECTION.
|
||||||
|
"Instance method declarations
|
||||||
|
METHODS meth_protected_3.
|
||||||
|
"Abstract method
|
||||||
|
METHODS meth_protected_3_abstract ABSTRACT.
|
||||||
|
|
||||||
|
"Redefining methods from the class ...
|
||||||
|
"... one level up in the inheritance hierarchy (i.e. the direct superclass)
|
||||||
|
METHODS meth_protected_2 REDEFINITION.
|
||||||
|
"... two levels up in the inheritance hierarchy
|
||||||
|
"Specifying the FINAL addition
|
||||||
|
METHODS meth_protected_1 FINAL REDEFINITION.
|
||||||
|
|
||||||
|
PRIVATE SECTION.
|
||||||
|
ENDCLASS.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CLASS zcl_demo_abap_oo_inheritance_3 IMPLEMENTATION.
|
||||||
|
|
||||||
|
METHOD class_constructor.
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD constructor.
|
||||||
|
super->constructor( ).
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_3.
|
||||||
|
"Method of this class
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_protected_3.
|
||||||
|
"Method of this class
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_2.
|
||||||
|
"Reimplementing a method from the class one level up in the inheritance hierarchy (direct superclass)
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_protected_2.
|
||||||
|
"Reimplementing a method from the class one level up in the inheritance hierarchy (direct superclass)
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_protected_1.
|
||||||
|
"Reimplementing a method from the class two levels up in the inheritance hierarchy
|
||||||
|
"Note that the method is specified with FINAL REDEFINITION. So, a further redefinition in subclasses is not possible.
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_1.
|
||||||
|
"Reimplementing a method from the class two levels up in the inheritance hierarchy
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
ENDCLASS.
|
||||||
16
src/zcl_demo_abap_oo_inheritance_3.clas.xml
Normal file
16
src/zcl_demo_abap_oo_inheritance_3.clas.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||||
|
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||||
|
<asx:values>
|
||||||
|
<VSEOCLASS>
|
||||||
|
<CLSNAME>ZCL_DEMO_ABAP_OO_INHERITANCE_3</CLSNAME>
|
||||||
|
<LANGU>E</LANGU>
|
||||||
|
<DESCRIPT>ABAP cheat sheet: ABAP object orientation - Inheritance</DESCRIPT>
|
||||||
|
<STATE>1</STATE>
|
||||||
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
|
<FIXPT>X</FIXPT>
|
||||||
|
<UNICODE>X</UNICODE>
|
||||||
|
</VSEOCLASS>
|
||||||
|
</asx:values>
|
||||||
|
</asx:abap>
|
||||||
|
</abapGit>
|
||||||
195
src/zcl_demo_abap_oo_inheritance_4.clas.abap
Normal file
195
src/zcl_demo_abap_oo_inheritance_4.clas.abap
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
"! <p class="shorttext"><strong>ABAP object orientation - Inheritance</strong><br/>ABAP cheat sheet example class</p>
|
||||||
|
"!
|
||||||
|
"! <p>The example class explores inheritance and demonstrate a selection of the inheritance-related syntax.
|
||||||
|
"! The inheritance tree consists of four example classes. The base class {@link zcl_demo_abap_oo_inheritance_1}
|
||||||
|
"! includes the implementation of the classrun interface. Choose F9 in ADT to run the base class.</p>
|
||||||
|
"! <p>Classes of the inheritance tree:</p>
|
||||||
|
"! <ul><li>{@link zcl_demo_abap_oo_inheritance_1}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_2}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_3}</li>
|
||||||
|
"! <li>{@link zcl_demo_abap_oo_inheritance_4}</li>
|
||||||
|
"! </ul>
|
||||||
|
"!
|
||||||
|
"! <h2>Notes on this class</h2>
|
||||||
|
"! <ul><li>Inherits from {@link zcl_demo_abap_oo_inheritance_3} and thus from {@link zcl_demo_abap_oo_inheritance_2}
|
||||||
|
"! and {@link zcl_demo_abap_oo_inheritance_1}</li>
|
||||||
|
"! <li>Specifies <em>FINAL</em> and so does not allow inheritance</li>
|
||||||
|
"! <li>Declares several instance methods</li>
|
||||||
|
"! <li>Instance methods of the direct superclass, which is an abstract class, are redefined. It is mandatory to
|
||||||
|
"! redefine the abstract methods.</li>
|
||||||
|
"! <li>Other instance methods from further levels up the inheritance hierarchy are redefined (except one method that
|
||||||
|
"! is declared with <em>FINAL REDEFINITION</em> in {@link zcl_demo_abap_oo_inheritance_3})</li>
|
||||||
|
"! <li>For demonstration purposes, instance methods implemented in the abstract direct superclass (instances of
|
||||||
|
"! abstract classes cannot be created) are called in the respective redefined methods by referring to the direct
|
||||||
|
"! superclass using the syntax <em>super->...</em>.</li>
|
||||||
|
"! <li>Declares a static method to delegate method calls of this class</li></ul>
|
||||||
|
"!
|
||||||
|
"! <h2>More information</h2>
|
||||||
|
"! <ul><li>Find general information on the inheritance example in class {@link zcl_demo_abap_oo_inheritance_1}</li>
|
||||||
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li></ul>
|
||||||
|
CLASS zcl_demo_abap_oo_inheritance_4 DEFINITION
|
||||||
|
INHERITING FROM zcl_demo_abap_oo_inheritance_3
|
||||||
|
PUBLIC
|
||||||
|
FINAL
|
||||||
|
CREATE PUBLIC .
|
||||||
|
|
||||||
|
PUBLIC SECTION.
|
||||||
|
"Instance/static constructor declarations
|
||||||
|
METHODS constructor.
|
||||||
|
CLASS-METHODS class_constructor.
|
||||||
|
|
||||||
|
"Instance method declaration
|
||||||
|
METHODS meth_public_4.
|
||||||
|
"Static method declaration for display purposes
|
||||||
|
CLASS-METHODS perform_meth_calls_4.
|
||||||
|
|
||||||
|
"Redefining methods from the class ...
|
||||||
|
"... one level up in the inheritance hierarchy (i.e. the direct superclass)
|
||||||
|
METHODS meth_public_3 REDEFINITION.
|
||||||
|
"Note: Redefining the abstract method here is mandatory.
|
||||||
|
METHODS meth_public_3_abstract REDEFINITION.
|
||||||
|
"... two levels up in the inheritance hierarchy
|
||||||
|
METHODS meth_public_2 REDEFINITION.
|
||||||
|
"... three levels up in the inheritance hierarchy
|
||||||
|
METHODS meth_public_1 REDEFINITION.
|
||||||
|
|
||||||
|
PROTECTED SECTION.
|
||||||
|
|
||||||
|
"Instance method declaration
|
||||||
|
METHODS meth_protected_4.
|
||||||
|
|
||||||
|
"Redefining methods from the class ...
|
||||||
|
"... one level up in the inheritance hierarchy (i.e. the direct superclass)
|
||||||
|
METHODS meth_protected_3 REDEFINITION.
|
||||||
|
"Note: Redefining the abstract method here is mandatory.
|
||||||
|
METHODS meth_protected_3_abstract REDEFINITION.
|
||||||
|
"... two levels up in the inheritance hierarchy
|
||||||
|
METHODS meth_protected_2 REDEFINITION.
|
||||||
|
"... three levels up in the inheritance hierarchy
|
||||||
|
"The meth_protected_1 method is specified with FINAL REDEFINITION in the
|
||||||
|
"direct superclass. Therefore, a further redefinition is not possible.
|
||||||
|
"The following statement is not possible.
|
||||||
|
"METHODS meth_protected_1 REDEFINITION.
|
||||||
|
|
||||||
|
PRIVATE SECTION.
|
||||||
|
ENDCLASS.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CLASS zcl_demo_abap_oo_inheritance_4 IMPLEMENTATION.
|
||||||
|
|
||||||
|
METHOD class_constructor.
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD constructor.
|
||||||
|
super->constructor( ).
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_4.
|
||||||
|
"Method of this class
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_protected_4.
|
||||||
|
"Method of this class
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_3.
|
||||||
|
"Reimplementing a method from the class one level up in the inheritance hierarchy (direct superclass)
|
||||||
|
"Calling this instance method that is redefined in the abstract direct superclass (instances of abstract classes cannot be created)
|
||||||
|
"by referring to the direct superclass using the syntax super->...
|
||||||
|
super->meth_public_3( ).
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_protected_3.
|
||||||
|
"Reimplementing a method from the class one level up in the inheritance hierarchy (direct superclass)
|
||||||
|
"This method is a non-abstract instance method of the abstract direct superclass. Instances of abstract classes
|
||||||
|
"cannot be created. The syntax super->meth is used to also call instance methods of the abstract direct superclass
|
||||||
|
"for output purposes.
|
||||||
|
super->meth_protected_3( ).
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_3_abstract.
|
||||||
|
"Implementating abstract methods are only possible in subclasses of abstract classes
|
||||||
|
"Reimplementing a method from the class one level up in the inheritance hierarchy (direct superclass)
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_protected_3_abstract.
|
||||||
|
"Implementating abstract methods are only possible in subclasses of abstract classes
|
||||||
|
"Reimplementing a method from the class one level up in the inheritance hierarchy (direct superclass)
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_2.
|
||||||
|
"Reimplementing a method from the class two levels up in the inheritance hierarchy
|
||||||
|
"Calling this instance method that is redefined in the abstract direct superclass (instances of abstract
|
||||||
|
"classes cannot be created) by referring to the direct superclass using the syntax super->....
|
||||||
|
super->meth_public_2( ).
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_protected_2.
|
||||||
|
"Reimplementing a method from the class two levels up in the inheritance hierarchy
|
||||||
|
"Calling this instance method that is redefined in the abstract direct superclass (instances of abstract
|
||||||
|
"classes cannot be created) by referring to the direct superclass using the syntax super->....
|
||||||
|
super->meth_protected_2( ).
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD meth_public_1.
|
||||||
|
"Reimplementing a method from the class three levels up in the inheritance hierarchy
|
||||||
|
"Calling this instance method that is redefined in the abstract direct superclass (instances of abstract
|
||||||
|
"classes cannot be created) by referring to the direct superclass using the syntax super->....
|
||||||
|
super->meth_public_1( ).
|
||||||
|
INSERT VALUE #( called_at = utclong_current( ) ) INTO TABLE log_tab ASSIGNING FIELD-SYMBOL(<fs>).
|
||||||
|
<fs> = CORRESPONDING #( BASE ( <fs> ) get_method_info( ) EXCEPT called_at ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD perform_meth_calls_4.
|
||||||
|
"Method of this class
|
||||||
|
"Creating an instance of the class
|
||||||
|
DATA(oref_4) = NEW zcl_demo_abap_oo_inheritance_4( ).
|
||||||
|
|
||||||
|
"Calling methods of this class
|
||||||
|
oref_4->meth_public_4( ).
|
||||||
|
oref_4->meth_protected_4( ).
|
||||||
|
"Calling redefined methods from the class ...
|
||||||
|
"... one level up in the inheritance hierarchy (direct superclass)
|
||||||
|
"Among them are abstract methods that can only be implemented in subclasses.
|
||||||
|
"Note that the implementations of the non-abstract, redefined methods in this
|
||||||
|
"class includes method calls of the abstract direct superclass so that
|
||||||
|
"also these implementations are called for output purposes.
|
||||||
|
oref_4->meth_public_3( ).
|
||||||
|
oref_4->meth_public_3_abstract( ).
|
||||||
|
oref_4->meth_protected_3( ).
|
||||||
|
oref_4->meth_protected_3_abstract( ).
|
||||||
|
"... two levels up in the inheritance hierarchy
|
||||||
|
oref_4->meth_public_2( ).
|
||||||
|
oref_4->meth_protected_2( ).
|
||||||
|
"... three levels up in the inheritance hierarchy
|
||||||
|
oref_4->meth_public_1( ).
|
||||||
|
"Note: The following method call calls the method implementation in
|
||||||
|
"class zcl_demo_abap_oo_inheritance_3. The method is specified with FINAL
|
||||||
|
"REDEFINITION. So, it cannot be redefined in this class inheriting from
|
||||||
|
"zcl_demo_abap_oo_inheritance_3.
|
||||||
|
oref_4->meth_protected_1( ).
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
ENDCLASS.
|
||||||
16
src/zcl_demo_abap_oo_inheritance_4.clas.xml
Normal file
16
src/zcl_demo_abap_oo_inheritance_4.clas.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||||
|
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||||
|
<asx:values>
|
||||||
|
<VSEOCLASS>
|
||||||
|
<CLSNAME>ZCL_DEMO_ABAP_OO_INHERITANCE_4</CLSNAME>
|
||||||
|
<LANGU>E</LANGU>
|
||||||
|
<DESCRIPT>ABAP cheat sheet: ABAP object orientation - Inheritance</DESCRIPT>
|
||||||
|
<STATE>1</STATE>
|
||||||
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
|
<FIXPT>X</FIXPT>
|
||||||
|
<UNICODE>X</UNICODE>
|
||||||
|
</VSEOCLASS>
|
||||||
|
</asx:values>
|
||||||
|
</asx:abap>
|
||||||
|
</abapGit>
|
||||||
@@ -1,47 +1,14 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>Program flow logic</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: Program flow logic
|
"! <p>The example class demonstrates program flow logic.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Demonstration example for the topic program flow logic covering
|
"! <h2>Note</h2>
|
||||||
* the following:
|
"! <ul><li>Topics covered include expressions and functions for conditions,
|
||||||
* - Expressions and functions for conditions
|
"! control structures with IF and CASE, the COND and SWITCH operators,
|
||||||
* - Control structures with IF and CASE, including the COND and SWITCH
|
"! unconditional loops with DO, conditional loops with WHILE, handling exceptions</li>
|
||||||
* operators
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* - Unconditional loops with DO
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li></ul>
|
||||||
* - Conditional loops with WHILE
|
|
||||||
* - Handling exceptions
|
|
||||||
*
|
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
|
||||||
* - 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
|
|
||||||
* 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)
|
|
||||||
* 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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: Program flow logic</p>
|
|
||||||
"! Example to demonstrate program flow logic.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_prog_flow_logic DEFINITION
|
CLASS zcl_demo_abap_prog_flow_logic DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<VSEOCLASS>
|
<VSEOCLASS>
|
||||||
<CLSNAME>ZCL_DEMO_ABAP_PROG_FLOW_LOGIC</CLSNAME>
|
<CLSNAME>ZCL_DEMO_ABAP_PROG_FLOW_LOGIC</CLSNAME>
|
||||||
<LANGU>E</LANGU>
|
<LANGU>E</LANGU>
|
||||||
<DESCRIPT>ABAP cheat sheet: Program Flow Logic</DESCRIPT>
|
<DESCRIPT>ABAP cheat sheet: Program flow logic</DESCRIPT>
|
||||||
<STATE>1</STATE>
|
<STATE>1</STATE>
|
||||||
<CLSCCINCL>X</CLSCCINCL>
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
<FIXPT>X</FIXPT>
|
<FIXPT>X</FIXPT>
|
||||||
|
|||||||
@@ -1,107 +1,79 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>ABAP EML in a RAP scenario (draft BO)</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* RAP BO consumer for a RAP demo scenario
|
"! <p>The example class demonstrates ABAP EML in the context of a RAP demo scenario (managed and draft-enabled
|
||||||
* ABAP EML in use: RAP calculator (managed, draft-enabled RAP BO with
|
"! RAP business object with RAP late numbering). The class represents a RAP BO consumer.<br/>
|
||||||
* late numbering
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
*
|
"!
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"! <h2>Purpose</h2>
|
||||||
* - This class is the RAP BO consumer for a RAP demo scenario that
|
"! <ul><li>This class is the RAP BO consumer for a RAP demo scenario that
|
||||||
* represents a calculator using RAP concepts, i. e. using ABAP EML in
|
"! represents a calculator using RAP concepts, i. e. using ABAP EML in
|
||||||
* the context of a managed and draft-enabled RAP business object with
|
"! the context of a managed and draft-enabled RAP business object with
|
||||||
* RAP late numbering to carry out simple calculations. Here, a RAP BO
|
"! RAP late numbering to carry out simple calculations. Here, a RAP BO
|
||||||
* instance consists of a calculation ID (which is the key that is finally
|
"! instance consists of a calculation ID (which is the key that is finally
|
||||||
* set not until the RAP save sequence), two operands (having integer
|
"! set not until the RAP save sequence), two operands (having integer
|
||||||
* values), the arithmetic operator and the result plus other
|
"! values), the arithmetic operator and the result plus other
|
||||||
* draft-related fields.
|
"! draft-related fields.</li>
|
||||||
* - Underlying data model: Consists of a root entity alone.
|
"! <li>Underlying data model: Consists of a root entity alone.
|
||||||
* The BDEF defines the behavior for this entity. The definitions in the
|
"! The BDEF defines the behavior for this entity. The definitions in the
|
||||||
* BDEF determine which methods must be implemented in the ABAP behavior
|
"! BDEF determine which methods must be implemented in the ABAP behavior
|
||||||
* pool (ABP). Note that the view contains many annotations for the SAP
|
"! pool (ABP). Note that the view contains many annotations for the SAP
|
||||||
* Fiori UI.
|
"! Fiori UI.</li>
|
||||||
* - ABP for this scenario: zbp_demo_abap_rap_draft_m
|
"! <li>ABP for this scenario: {@link zbp_demo_abap_rap_draft_m}</li></ul>
|
||||||
*
|
"!
|
||||||
* ----------------------- GETTING STARTED (1) -------------------------
|
"! <h2>Getting started (1)</h2>
|
||||||
* ----------------- Using this class as RAP BO consumer ---------------
|
"! <p>To <strong>use this class as RAP BO consumer</strong>, see the ABAP Doc comment about
|
||||||
*
|
"! <strong>getting started with the example class</strong> of class {@link zcl_demo_abap_aux}.
|
||||||
* - Open the class with the ABAP development tools for Eclipse (ADT).
|
"!
|
||||||
* - Choose F9 to run the class.
|
"! <h2>Getting started (2)</h2>
|
||||||
* - Check the console output.
|
"! <strong>Using the preview version of an SAP Fiori Elements UI as RAP BO consumer</strong>
|
||||||
* - To understand the context and the ABAP syntax used, check the notes
|
"! <br/>
|
||||||
* included in the class as comments or refer to the respective topic
|
"! Create a service binding:
|
||||||
* in the ABAP Keyword Documentation.
|
"! <ol><li>Find the service definition ZDEMO_ABAP_RAP_CALC_SD in the imported
|
||||||
* - Due to the amount of output in the console, the examples include
|
"! package in Business Services -> Service Definitions.</li>
|
||||||
* numbers (e. g. 1) ..., 2) ..., 3) ...) for the individual example
|
"! <li>Right-click the service definition and choose New Service Binding.</li>
|
||||||
* sections. Plus, the variable name is displayed in most cases. Hence,
|
"! <li>In the New Service Binding pop-up, make the following entries:
|
||||||
* to easier and faster find the relevant output in the console, just
|
"! Name: ZDEMO_ABAP_RAP_CALC_SB; Description: Service binding for demo,
|
||||||
* search in the console for the number/variable name (CTRL+F in the
|
"! Binding type: OData V4 - UI, Service Definition: ZDEMO_ABAP_RAP_CALC_SD
|
||||||
* console) or use the debugger.
|
"! (should be already filled)</li>
|
||||||
*
|
"! <li>Choose Next.</li>
|
||||||
* ----------------------- GETTING STARTED (2) -------------------------
|
"! <li>Assign a transport request and choose Finish.</li>
|
||||||
* Using the preview version of an SAP Fiori Elements UI as RAP BO consumer
|
"! <li>The service binding ZDEMO_ABAP_RAP_CALC_SB is opened. Activate the
|
||||||
*
|
"! service binding.</li>
|
||||||
* Create a service binding:
|
"! <li>In the Service Version Details section, choose the Publish button
|
||||||
* 1. Find the service definition ZDEMO_ABAP_RAP_CALC_SD in the imported
|
"! for the Local Service Endpoint. Once the service has been published,
|
||||||
* package in Business Services -> Service Definitions.
|
"! you should see ZDEMO_ABAP_RAP_DRAFT_M in the Entity Set and Association
|
||||||
* 2. Right-click the service definition and choose New Service Binding.
|
"! section.</li>
|
||||||
* 3. In the New Service Binding pop-up, make the following entries:
|
"! <li>Activate the service binding once the service has been published.</li>
|
||||||
* - Name: ZDEMO_ABAP_RAP_CALC_SB
|
"! <li>Select ZDEMO_ABAP_RAP_DRAFT_M and choose the Preview button.</li>
|
||||||
* - Description: Service binding for demo
|
"! <li>The preview version of an SAP Fiori Elements app is displayed. If
|
||||||
* - Binding type: OData V4 - UI
|
"! prompted, provide your credentials.</li>
|
||||||
* - Service Definition: ZDEMO_ABAP_RAP_CALC_SD (should be already filled)
|
"! <li>The app and the managed, draft-enabled RAP BO can be explored. If no
|
||||||
* 4. Choose Next.
|
"! columns are displayed, choose the 'Settings' button and select the
|
||||||
* 5. Assign a transport request and choose Finish.
|
"! desired columns.
|
||||||
* 6. The service binding ZDEMO_ABAP_RAP_CALC_SB is opened. Activate the
|
"! Choosing the 'Go' button refreshes the list. At first use, there
|
||||||
* service binding.
|
"! might not be any entry. You can create an entry choosing the 'Create'
|
||||||
* 7. In the Service Version Details section, choose the Publish button
|
"! button.
|
||||||
* for the Local Service Endpoint. Once the service has been published,
|
"! The late numbering aspects enter the picture when you, for
|
||||||
* you should see ZDEMO_ABAP_RAP_DRAFT_M in the Entity Set and Association
|
"! example, create a new instance, i. e. create a new calculation, and
|
||||||
* section.
|
"! you keep a draft version of it instead of saving it to the database.
|
||||||
* 8. Activate the service binding once the service has been published.
|
"! The calculation ID which represents the key of the instance has an
|
||||||
* 9. Select ZDEMO_ABAP_RAP_DRAFT_M and choose the Preview button.
|
"! initial value. Only when you save the instance to the database, the
|
||||||
* 10. The preview version of an SAP Fiori Elements app is displayed. If
|
"! final key is set.
|
||||||
* prompted, provide your credentials.
|
"! The effect of side effects can be explored as follows: Make an entry
|
||||||
* 11. The app and the managed, draft-enabled RAP BO can be explored. If no
|
"! in an input field, click another input field (e.g. to make a new entry
|
||||||
* columns are displayed, choose the 'Settings' button and select the
|
"! there), and check how the value for the result changes.</li></ol>
|
||||||
* desired columns.
|
"!
|
||||||
* Choosing the 'Go' button refreshes the list. At first use, there
|
"! <h2>Note</h2>
|
||||||
* might not be any entry. You can create an entry choosing the 'Create'
|
"! <p>This simplified example is not a real life scenario and rather
|
||||||
* button.
|
"! focuses on the technical side by giving an idea how the communication
|
||||||
* The late numbering aspects enter the picture when you, for
|
"! and data exchange between a RAP BO consumer, which is a class
|
||||||
* example, create a new instance, i. e. create a new calculation, and
|
"! in this case, and RAP BO provider can work. Additionally, it shows
|
||||||
* you keep a draft version of it instead of saving it to the database.
|
"! how the methods for non-standard RAP BO operations might be
|
||||||
* The calculation ID which represents the key of the instance has an
|
"! self-implemented in an ABP. The example is intentionally kept
|
||||||
* initial value. Only when you save the instance to the database, the
|
"! short and simple and focuses on specific RAP aspects. For this reason,
|
||||||
* final key is set.
|
"! the example might not fully meet the requirements of the RAP BO contract.</p>
|
||||||
* The effect of side effects can be explored as follows: Make an entry
|
"! <p>Find the <strong>disclaimer</strong> in the ABAP Doc comment of
|
||||||
* in an input field, click another input field (e.g. to make a new entry
|
"! class {@link zcl_demo_abap_aux}.</p>
|
||||||
* there), and check how the value for the result changes.
|
|
||||||
*
|
|
||||||
* ----------------------------- NOTE -----------------------------------
|
|
||||||
* This simplified example is not a real life scenario and rather
|
|
||||||
* focuses on the technical side by giving an idea how the communication
|
|
||||||
* and data exchange between a RAP BO consumer, which is a class
|
|
||||||
* in this case, and RAP BO provider can work. Additionally, it shows
|
|
||||||
* how the methods for non-standard RAP BO operations might be
|
|
||||||
* self-implemented in an ABP. The example is intentionally kept
|
|
||||||
* short and simple and focuses on specific RAP aspects. For this reason,
|
|
||||||
* the example might not fully meet the requirements of the RAP BO contract.
|
|
||||||
*
|
|
||||||
* The code presented in this class is intended only to support the ABAP
|
|
||||||
* cheat sheets. It is not intended for direct use in a production system
|
|
||||||
* environment. The code examples in the ABAP cheat sheets are primarily
|
|
||||||
* intended to provide a better explanation and visualization of the
|
|
||||||
* syntax and semantics of ABAP statements, not to solve concrete
|
|
||||||
* programming tasks. For production application programs, you should
|
|
||||||
* always work out your own solution for each individual case. There is
|
|
||||||
* no guarantee for the correctness or completeness of the code.
|
|
||||||
* Furthermore, there is no legal responsibility or liability for any
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: ABAP EML in a RAP scenario (draft BO)</p>
|
|
||||||
"! Example to demonstrate ABAP EML in the context of a RAP demo scenario (managed and draft-enabled RAP business object with RAP late numbering).
|
|
||||||
"! The class represents a RAP BO consumer.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_rap_draft_ln_m DEFINITION
|
CLASS zcl_demo_abap_rap_draft_ln_m DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -113,7 +85,7 @@ CLASS zcl_demo_abap_rap_draft_ln_m DEFINITION
|
|||||||
CLASS-METHODS:
|
CLASS-METHODS:
|
||||||
class_constructor.
|
class_constructor.
|
||||||
|
|
||||||
protected section.
|
PROTECTED SECTION.
|
||||||
PRIVATE SECTION.
|
PRIVATE SECTION.
|
||||||
CLASS-DATA:
|
CLASS-DATA:
|
||||||
activate_tab TYPE TABLE FOR ACTION IMPORT
|
activate_tab TYPE TABLE FOR ACTION IMPORT
|
||||||
@@ -136,7 +108,7 @@ ENDCLASS.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION.
|
CLASS zcl_demo_abap_rap_draft_ln_m IMPLEMENTATION.
|
||||||
|
|
||||||
|
|
||||||
METHOD class_constructor.
|
METHOD class_constructor.
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
**********************************************************************
|
"! <p class="shorttext"><strong>RAP event handler class</strong><br/>ABAP cheat sheet example class</p>
|
||||||
* Note:
|
"!
|
||||||
*
|
"! <p>The example class is the RAP event handler class for {@link zdemo_abap_rap_ro_m_as}.<br/>
|
||||||
* - This class is the RAP event handler class for zdemo_abap_rap_ro_m_as.
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
*
|
"!
|
||||||
* - The RAP business events in this example are raised using RAISE
|
"! <h2>Note</h2>
|
||||||
* ENTITY EVENT statements in the save_modified saver method that
|
"! <ul><li>The RAP business events in this example are raised using RAISE
|
||||||
* is implemented in the CCIMP include of the ABAP behavior pool
|
"! ENTITY EVENT statements in the save_modified saver method that
|
||||||
* zbp_demo_abap_rap_ro_m_as.
|
"! is implemented in the CCIMP include of the ABAP behavior pool
|
||||||
*
|
"! {@link zbp_demo_abap_rap_ro_m_as}.</li>
|
||||||
**********************************************************************
|
"! <li>Find the <strong>disclaimer</strong> in the ABAP Doc comment of
|
||||||
|
"! class {@link zcl_demo_abap_aux}.</li></ul>
|
||||||
CLASS zcl_demo_abap_rap_evt_handler DEFINITION
|
CLASS zcl_demo_abap_rap_evt_handler DEFINITION
|
||||||
PUBLIC ABSTRACT FINAL
|
PUBLIC ABSTRACT FINAL
|
||||||
FOR EVENTS OF zdemo_abap_rap_ro_m_as.
|
FOR EVENTS OF zdemo_abap_rap_ro_m_as.
|
||||||
|
|||||||
@@ -1,64 +1,35 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>ABAP EML in a RAP scenario (managed BO)</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* RAP BO consumer for a RAP demo scenario:
|
"! <p>The example class demonstrates ABAP EML in the context of a RAP demo scenario
|
||||||
* ABAP EML in use: Managed RAP BO with external numbering
|
"! (managed RAP BO with external numbering). The class represents a RAP BO consumer.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - This class is the RAP BO consumer for a RAP demo scenario that
|
"! <h2>Note</h2>
|
||||||
* demonstrates various RAP BO standard operations and non-standard
|
"! <ul><li>This class is the RAP BO consumer for a RAP demo scenario that
|
||||||
* operations using ABAP EML in the context of a managed RAP business
|
"! demonstrates various RAP BO standard operations and non-standard
|
||||||
* object with RAP external numbering.
|
"! operations using ABAP EML in the context of a managed RAP business
|
||||||
* - Topics covered: RAP BO operations like create (including a
|
"! object with RAP external numbering.</li>
|
||||||
* determination on save), update, delete, executing an action, validation,
|
"! <li>Topics covered: RAP BO operations like create (including a
|
||||||
* create-by-association (parent to child), read (root entity),
|
"! determination on save), update, delete, executing an action, validation,
|
||||||
* read-by-association (parent to child), read (child entity),
|
"! create-by-association (parent to child), read (root entity),
|
||||||
* read-by-association (child to parent)
|
"! read-by-association (parent to child), read (child entity),
|
||||||
* - Underlying data model: Consists of a root entity and one child entity.
|
"! read-by-association (child to parent)</li>
|
||||||
* The BDEF defines the behavior for these two entities which are connected
|
"! <li>Underlying data model: Consists of a root entity and one child entity.
|
||||||
* via a CDS composition relation. The definitions in the BDEF determine
|
"! The BDEF defines the behavior for these two entities which are connected
|
||||||
* which methods must be implemented in the ABAP behavior pool (ABP).
|
"! via a CDS composition relation. The definitions in the BDEF determine
|
||||||
* - ABP for this scenario: zbp_demo_abap_rap_ro_m
|
"! which methods must be implemented in the ABAP behavior pool (ABP).</li>
|
||||||
*
|
"! <li>ABP for this scenario: {@link zbp_demo_abap_rap_ro_m}.</li>
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
"! <li> This simplified example is not a real life scenario and rather
|
||||||
* - Open the class with the ABAP development tools for Eclipse (ADT).
|
"! focuses on the technical side by giving an idea how the communication
|
||||||
* - Choose F9 to run the class.
|
"! and data exchange between a RAP BO consumer, which is a class
|
||||||
* - Check the console output.
|
"! in this case, and RAP BO provider can work. Additionally, it shows
|
||||||
* - To understand the context and the ABAP syntax used, check the notes
|
"! how the methods for non-standard RAP BO operations might be
|
||||||
* included in the class as comments or refer to the respective topic
|
"! self-implemented in an ABP. The example is intentionally kept
|
||||||
* in the ABAP Keyword Documentation.
|
"! short and simple and focuses on specific RAP aspects. For this reason,
|
||||||
* - Due to the amount of output in the console, the examples include
|
"! the example might not fully meet the requirements of the RAP BO contract.</li>
|
||||||
* numbers (e. g. 1) ..., 2) ..., 3) ...) for the individual example
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* sections. Plus, the variable name is displayed in most cases. Hence,
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li>
|
||||||
* to easier and faster find the relevant output in the console, just
|
"! </ul>
|
||||||
* search in the console for the number/variable name (CTRL+F in the
|
|
||||||
* console) or use the debugger.
|
|
||||||
*
|
|
||||||
* ----------------------------- NOTE -----------------------------------
|
|
||||||
* This simplified example is not a real life scenario and rather
|
|
||||||
* focuses on the technical side by giving an idea how the communication
|
|
||||||
* and data exchange between a RAP BO consumer, which is a class
|
|
||||||
* in this case, and RAP BO provider can work. Additionally, it shows
|
|
||||||
* how the methods for non-standard RAP BO operations might be
|
|
||||||
* self-implemented in an ABP. The example is intentionally kept
|
|
||||||
* short and simple and focuses on specific RAP aspects. For this reason,
|
|
||||||
* the example might not fully meet the requirements of the RAP BO contract.
|
|
||||||
*
|
|
||||||
* The code presented in this class is intended only to support the ABAP
|
|
||||||
* cheat sheets. It is not intended for direct use in a production system
|
|
||||||
* environment. The code examples in the ABAP cheat sheets are primarily
|
|
||||||
* intended to provide a better explanation and visualization of the
|
|
||||||
* syntax and semantics of ABAP statements, not to solve concrete
|
|
||||||
* programming tasks. For production application programs, you should
|
|
||||||
* always work out your own solution for each individual case. There is
|
|
||||||
* no guarantee for the correctness or completeness of the code.
|
|
||||||
* Furthermore, there is no legal responsibility or liability for any
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: ABAP EML in a RAP scenario (managed BO)</p>
|
|
||||||
"! Example to demonstrate ABAP EML in the context of a RAP demo scenario (managed RAP BO with external numbering).
|
|
||||||
"! The class represents a RAP BO consumer.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_rap_ext_num_m DEFINITION
|
CLASS zcl_demo_abap_rap_ext_num_m DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
|
|||||||
@@ -1,68 +1,37 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>ABAP EML in a RAP scenario (unmanaged BO)</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* RAP BO consumer for a RAP demo scenario:
|
"! <p>The example class demonstrates ABAP EML in the context of a RAP demo scenario (unmanaged RAP BO with external numbering).
|
||||||
* ABAP EML in use: Unmanaged RAP BO with external numbering
|
"! The class represents a RAP BO consumer.<br/> Choose F9 in ADT to run the class.</p>
|
||||||
*
|
"!
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"! <h2>Note</h2>
|
||||||
* - This class is the RAP BO consumer for a RAP demo scenario that
|
"! <ul><li>This class is the RAP BO consumer for a RAP demo scenario that
|
||||||
* demonstrates various RAP BO standard operations and non-standard
|
"! demonstrates various RAP BO standard operations and non-standard
|
||||||
* operations using ABAP EML in the context of an unmanaged RAP business
|
"! operations using ABAP EML in the context of an unmanaged RAP business
|
||||||
* object with RAP external numbering.
|
"! object with RAP external numbering.</li>
|
||||||
* - Topics covered: RAP BO operations like create, update, delete,
|
"! <li>Topics covered: RAP BO operations like create, update, delete,
|
||||||
* executing actions, instance and global feature control, instance
|
"! executing actions, instance and global feature control, instance
|
||||||
* authorization, create-by-association (parent to child), read,
|
"! authorization, create-by-association (parent to child), read,
|
||||||
* read-by-association (parent to child), read (child entity),
|
"! read-by-association (parent to child), read (child entity),
|
||||||
* read-by-association (child to parent)
|
"! read-by-association (child to parent)</li>
|
||||||
* - Underlying data model: Consists of a root entity and one child entity.
|
"! <li>Underlying data model: Consists of a root entity and one child entity.
|
||||||
* The BDEF defines the behavior for these two entities which are connected
|
"! The BDEF defines the behavior for these two entities which are connected
|
||||||
* via a CDS composition relation. The definitions in the BDEF determine
|
"! via a CDS composition relation. The definitions in the BDEF determine
|
||||||
* which methods must be implemented in the ABAP behavior pool (ABP).
|
"! which methods must be implemented in the ABAP behavior pool (ABP).
|
||||||
* - ABP for this scenario: zbp_demo_abap_rap_ro_u
|
"! <li>ABP for this scenario: {@link zbp_demo_abap_rap_ro_u}.</li>
|
||||||
*
|
"! <li> For demonstration purposes, some of the operations are
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
"! impacted by feature controls and instance authorization as specified
|
||||||
* - Open the class with the ABAP development tools for Eclipse (ADT).
|
"! in the BDEF.</li>
|
||||||
* - Choose F9 to run the class.
|
"! <li> This simplified example is not a real life scenario and rather
|
||||||
* - Check the console output.
|
"! focuses on the technical side by giving an idea how the communication
|
||||||
* - To understand the context and the ABAP syntax used, check the notes
|
"! and data exchange between a RAP BO consumer, which is a class
|
||||||
* included in the class as comments or refer to the respective topic
|
"! in this case, and RAP BO provider can work. Additionally, it shows
|
||||||
* in the ABAP Keyword Documentation.
|
"! how the methods for non-standard RAP BO operations might be
|
||||||
* - Due to the amount of output in the console, the examples include
|
"! self-implemented in an ABP. The example is intentionally kept
|
||||||
* numbers (e. g. 1) ..., 2) ..., 3) ...) for the individual example
|
"! short and simple and focuses on specific RAP aspects. For this reason,
|
||||||
* sections. Plus, the variable name is displayed in most cases. Hence,
|
"! the example might not fully meet the requirements of the RAP BO contract.</li>
|
||||||
* to easier and faster find the relevant output in the console, just
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* search in the console for the number/variable name (CTRL+F in the
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li>
|
||||||
* console) or use the debugger.
|
"! </ul>
|
||||||
*
|
|
||||||
* ----------------------------- NOTE -----------------------------------
|
|
||||||
* This simplified example is not a real life scenario and rather
|
|
||||||
* focuses on the technical side by giving an idea how the communication
|
|
||||||
* and data exchange between a RAP BO consumer, which is a class
|
|
||||||
* in this case, and RAP BO provider can work. Additionally, it shows
|
|
||||||
* how the methods for non-standard RAP BO operations might be
|
|
||||||
* self-implemented in an ABP. The example is intentionally kept
|
|
||||||
* short and simple and focuses on specific RAP aspects. For this reason,
|
|
||||||
* the example might not fully meet the requirements of the RAP BO contract.
|
|
||||||
*
|
|
||||||
* For demonstration purposes, some of the operations are
|
|
||||||
* impacted by feature controls and instance authorization as specified
|
|
||||||
* in the BDEF.
|
|
||||||
*
|
|
||||||
* The code presented in this class is intended only to support the ABAP
|
|
||||||
* cheat sheets. It is not intended for direct use in a production system
|
|
||||||
* environment. The code examples in the ABAP cheat sheets are primarily
|
|
||||||
* intended to provide a better explanation and visualization of the
|
|
||||||
* syntax and semantics of ABAP statements, not to solve concrete
|
|
||||||
* programming tasks. For production application programs, you should
|
|
||||||
* always work out your own solution for each individual case. There is
|
|
||||||
* no guarantee for the correctness or completeness of the code.
|
|
||||||
* Furthermore, there is no legal responsibility or liability for any
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: ABAP EML in a RAP scenario (unmanaged BO)</p>
|
|
||||||
"! Example to demonstrate ABAP EML in the context of a RAP demo scenario (unmanaged RAP BO with external numbering).
|
|
||||||
"! The class represents a RAP BO consumer.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_rap_ext_num_u DEFINITION
|
CLASS zcl_demo_abap_rap_ext_num_u DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
|
|||||||
@@ -1,89 +1,60 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>Local consumption of RAP Business Events</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* RAP BO consumer for a RAP demo scenario:
|
"! <p>The example class demonstrates local consumption of RAP business events in the context of a RAP demo
|
||||||
* Managed RAP BO with managed internal numbering and additional save
|
"! scenario (managed RAP BO with managed internal numbering and additional save).
|
||||||
* demonstrating the local consumption of RAP business events
|
"! The class represents a RAP BO consumer.<br/> Choose F9 in ADT to run the class.</p>
|
||||||
*
|
"!
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"! <h2>Note</h2>
|
||||||
* - Primarily, the example demonstrates the local consumption of RAP
|
"! <ul><li>Primarily, the example demonstrates the local consumption of RAP
|
||||||
* business events.
|
"! business events.</li>
|
||||||
* - For that purpose, the BDEF defines three events. Two of them are
|
"! <li>For that purpose, the BDEF defines three events. Two of them are
|
||||||
* specified with a parameter. The events are raised for create, update
|
"! specified with a parameter. The events are raised for create, update
|
||||||
* and delete operations.
|
"! and delete operations.</li>
|
||||||
* - The example implementation in this class (the RAP BO consumer)
|
"! <li>The example implementation in this class (the RAP BO consumer)
|
||||||
* contains three ABAP EML modify requests: a RAP create, update and
|
"! contains three ABAP EML modify requests: a RAP create, update and
|
||||||
* delete operation. For each of the operations, an event is raised
|
"! delete operation. For each of the operations, an event is raised
|
||||||
* using a RAISE ENTITY EVENT statement. The events are raised in the
|
"! using a RAISE ENTITY EVENT statement. The events are raised in the
|
||||||
* save_modified RAP saver method in the CCIMP include of the behavior
|
"! save_modified RAP saver method in the CCIMP include of the behavior
|
||||||
* pool.
|
"! pool.</li>
|
||||||
* - When the events are raised, the RAP event handler methods are called
|
"! <li>When the events are raised, the RAP event handler methods are called
|
||||||
* asynchronously. To demonstrate the effect of the events, a database
|
"! asynchronously. To demonstrate the effect of the events, a database
|
||||||
* table representing a log table is populated.
|
"! table representing a log table is populated.</li>
|
||||||
* - In the output of the example, the content of internal tables is
|
"! <li>In the output of the example, the content of internal tables is
|
||||||
* displayed to demonstrate the effect of the RAP operations by
|
"! displayed to demonstrate the effect of the RAP operations by
|
||||||
* selecting from the database table where the RAP BO instances are
|
"! selecting from the database table where the RAP BO instances are
|
||||||
* persisted to after each RAP operation. Additionally, the content
|
"! persisted to after each RAP operation. Additionally, the content
|
||||||
* of an internal table is displayed including the entries that have been
|
"! of an internal table is displayed including the entries that have been
|
||||||
* inserted into the log database table by the event handler methods.
|
"! inserted into the log database table by the event handler methods.
|
||||||
* In this self-contained example, this 'log database table' is just a
|
"! In this self-contained example, this 'log database table' is just a
|
||||||
* database table that is used to store some entries triggered by the RAP
|
"! database table that is used to store some entries triggered by the RAP
|
||||||
* events for visualization purposes. You can imagine that, for example,
|
"! events for visualization purposes. You can imagine that, for example,
|
||||||
* the sending of an email is triggered there, or the application log is
|
"! the sending of an email is triggered there, or the application log is
|
||||||
* filled, and so on. The log table is used in another RAP example as
|
"! filled, and so on. The log table is used in another RAP example as
|
||||||
* draft table. The draft concept is not relevant for this simplified
|
"! draft table. The draft concept is not relevant for this simplified
|
||||||
* example here.
|
"! example here.</li>
|
||||||
* - Note the comments in the example code. You can check out the
|
"! <li>Note the comments in the example code. You can check out the
|
||||||
* asynchronity by commenting out the WAIT statement further down.
|
"! asynchronity by commenting out the WAIT statement further down.</li>
|
||||||
*
|
"! <li> This simplified example is not a real life scenario and rather
|
||||||
* ----------------- RELATED ARTIFACTS OF THE EXAMPLE ------------------*
|
"! focuses on the technical side by giving an idea how the communication
|
||||||
* - RAP BO consumer: zcl_demo_abap_rap_m_as (this class here)
|
"! and data exchange between a RAP BO consumer, which is a class
|
||||||
* - RAP BO provider (ABAP behavior pool): zbp_demo_abap_rap_ro_m_as
|
"! in this case, and RAP BO provider can work. Additionally, it shows
|
||||||
* - RAP event handler: zcl_demo_abap_rap_evt_handler
|
"! how the methods for non-standard RAP BO operations might be
|
||||||
* - BDEF: zdemo_abap_rap_ro_m_as
|
"! self-implemented in an ABP. The example is intentionally kept
|
||||||
* - More artifacts are related such as database tables, CDS views, and
|
"! short and simple and focuses on specific RAP aspects. For this reason,
|
||||||
* an abstract entity (zdemo_abap_abstract_ent; used for the parameter
|
"! the example might not fully meet the requirements of the RAP BO contract.</li>
|
||||||
* specifications for the events in the BDEF)
|
"! <li>Find information on <strong>getting started with the example class</strong> and the
|
||||||
*
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li>
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
"! </ul>
|
||||||
* - Open the class with the ABAP development tools for Eclipse (ADT).
|
"!
|
||||||
* - Choose F9 to run the class.
|
"! <h2>Related artifacts</h2>
|
||||||
* - Check the console output.
|
"! <ul><li>RAP BO consumer: {@link zcl_demo_abap_rap_m_as} (this class here)</li>
|
||||||
* - To understand the context and the ABAP syntax used, check the notes
|
"! <li>RAP BO provider (ABAP behavior pool): {@link zbp_demo_abap_rap_ro_m_as}</li>
|
||||||
* included in the class as comments or refer to the respective topic
|
"! <li>RAP event handler: {@link zcl_demo_abap_rap_evt_handler}</li>
|
||||||
* in the ABAP Keyword Documentation.
|
"! <li>BDEF: {@link zdemo_abap_rap_ro_m_as}</li>
|
||||||
* - Due to the amount of output in the console, the examples include
|
"! <li>More artifacts are related such as database tables, CDS views, and
|
||||||
* numbers (e. g. 1) ..., 2) ..., 3) ...) for the individual example
|
"! an abstract entity ({@link zdemo_abap_abstract_ent}; used for the parameter
|
||||||
* sections. Plus, the variable name is displayed in most cases. Hence,
|
"! specifications for the events in the BDEF)</li>
|
||||||
* to easier and faster find the relevant output in the console, just
|
"! </ul>
|
||||||
* search in the console for the number/variable name (CTRL+F in the
|
|
||||||
* console) or use the debugger.
|
|
||||||
*
|
|
||||||
* ----------------------------- NOTE -----------------------------------
|
|
||||||
* This simplified example is not a real life scenario and rather
|
|
||||||
* focuses on the technical side by giving an idea how the communication
|
|
||||||
* and data exchange between a RAP BO consumer, which is a class
|
|
||||||
* in this case, and RAP BO provider can work. Additionally, it shows
|
|
||||||
* how the methods for non-standard RAP BO operations might be
|
|
||||||
* self-implemented in an ABP. The example is intentionally kept
|
|
||||||
* short and simple and focuses on specific RAP aspects. For this reason,
|
|
||||||
* the example might not fully meet the requirements of the RAP BO contract.
|
|
||||||
*
|
|
||||||
* The code presented in this class is intended only to support the ABAP
|
|
||||||
* cheat sheets. It is not intended for direct use in a production system
|
|
||||||
* environment. The code examples in the ABAP cheat sheets are primarily
|
|
||||||
* intended to provide a better explanation and visualization of the
|
|
||||||
* syntax and semantics of ABAP statements, not to solve concrete
|
|
||||||
* programming tasks. For production application programs, you should
|
|
||||||
* always work out your own solution for each individual case. There is
|
|
||||||
* no guarantee for the correctness or completeness of the code.
|
|
||||||
* Furthermore, there is no legal responsibility or liability for any
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: Local consumption of RAP Business Events</p>
|
|
||||||
"! Example to demonstrate local consumption of RAP business events in the context of a RAP demo scenario (managed RAP BO with managed internal numbering and additional save).
|
|
||||||
"! The class represents a RAP BO consumer.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_rap_m_as DEFINITION
|
CLASS zcl_demo_abap_rap_m_as DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
|
|||||||
1118
src/zcl_demo_abap_regex.clas.abap
Normal file
1118
src/zcl_demo_abap_regex.clas.abap
Normal file
File diff suppressed because it is too large
Load Diff
16
src/zcl_demo_abap_regex.clas.xml
Normal file
16
src/zcl_demo_abap_regex.clas.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||||
|
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||||
|
<asx:values>
|
||||||
|
<VSEOCLASS>
|
||||||
|
<CLSNAME>ZCL_DEMO_ABAP_REGEX</CLSNAME>
|
||||||
|
<LANGU>E</LANGU>
|
||||||
|
<DESCRIPT>ABAP cheat sheet: Regular Expressions in ABAP</DESCRIPT>
|
||||||
|
<STATE>1</STATE>
|
||||||
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
|
<FIXPT>X</FIXPT>
|
||||||
|
<UNICODE>X</UNICODE>
|
||||||
|
</VSEOCLASS>
|
||||||
|
</asx:values>
|
||||||
|
</asx:abap>
|
||||||
|
</abapGit>
|
||||||
@@ -1,43 +1,11 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>ABAP SQL</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: ABAP SQL
|
"! <p>The example class demonstrates syntax and concepts related to ABAP SQL.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Example to demonstrate various syntax options for working with
|
"! <h2>Note</h2>
|
||||||
* persisted data in database tables using ABAP SQL.
|
"! <p>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* - Topics covered: reading from database tables using SELECT, changing
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
|
||||||
* data in database tables using INSERT, UPDATE, MODIFY and DELETE
|
|
||||||
*
|
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
|
||||||
* - 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
|
|
||||||
* 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)
|
|
||||||
* 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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: ABAP SQL</p>
|
|
||||||
"! Example to demonstrate ABAP SQL.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_sql DEFINITION
|
CLASS zcl_demo_abap_sql DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -72,7 +40,7 @@ CLASS zcl_demo_abap_sql IMPLEMENTATION.
|
|||||||
|
|
||||||
METHOD if_oo_adt_classrun~main.
|
METHOD if_oo_adt_classrun~main.
|
||||||
|
|
||||||
out->write( |ABAP Cheat Sheet Example: ABAP SQL\n\n| ).
|
out->write( |ABAP cheat sheet example: ABAP SQL\n\n| ).
|
||||||
out->write( |Using SELECT for multiple purposes\n| ).
|
out->write( |Using SELECT for multiple purposes\n| ).
|
||||||
out->write( |1) Reading a single row from database table into a structure\n\n| ).
|
out->write( |1) Reading a single row from database table into a structure\n\n| ).
|
||||||
|
|
||||||
@@ -763,7 +731,7 @@ CLASS zcl_demo_abap_sql IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `18) Special functions` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `18a) Special functions` ) ).
|
||||||
|
|
||||||
SELECT SINGLE
|
SELECT SINGLE
|
||||||
carrid,
|
carrid,
|
||||||
@@ -820,6 +788,49 @@ CLASS zcl_demo_abap_sql IMPLEMENTATION.
|
|||||||
out->write( |\n| ).
|
out->write( |\n| ).
|
||||||
out->write( data = special_functions name = `special_functions` ).
|
out->write( data = special_functions name = `special_functions` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `18b) coalesce Function` ) ).
|
||||||
|
|
||||||
|
"The null value is a special value that is returned by a database. It indicates an
|
||||||
|
"undefined value or result. Note that, in ABAP, there are no special null values. Do
|
||||||
|
"not confuse the null value with a type-dependent initial value. When using SELECT
|
||||||
|
"statements to read data, null values can be produced by, for example, outer joins.
|
||||||
|
"When the null values are passed to a data object, they are transformed to the
|
||||||
|
"type-dependent initial values. For more information, refer to the ABAP Keyword Documentation.
|
||||||
|
"The following example uses a left outer join to intentionally create null values. For
|
||||||
|
"this purpose, two demo database tables of the ABAP cheat sheet repository are cleared and
|
||||||
|
"populated with specific values to visualize null values.
|
||||||
|
DELETE FROM zdemo_abap_tab1.
|
||||||
|
DELETE FROM zdemo_abap_tab2.
|
||||||
|
MODIFY zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 1 char1 = 'a' char2 = 'y' )
|
||||||
|
( key_field = 2 char1 = 'b' char2 = 'z' ) ) ).
|
||||||
|
MODIFY zdemo_abap_tab2 FROM TABLE @( VALUE #( ( key_field = 1 char1 = 'a' )
|
||||||
|
( key_field = 2 char1 = 'a' )
|
||||||
|
( key_field = 3 char1 = 'b' )
|
||||||
|
( key_field = 4 ) ) ).
|
||||||
|
|
||||||
|
"Note that for the entry 'key_field = 4' no char1 value was passed.
|
||||||
|
"char1 is a shared column of the two database tables, and which is used in
|
||||||
|
"the ON condition of the join. Since there is no entry in char1 for 'key_field = 4',
|
||||||
|
"the joined values are null in that case.
|
||||||
|
"The coalesce function is used to replace null values produced by an outer join with
|
||||||
|
"a different value.
|
||||||
|
SELECT tab2~key_field,
|
||||||
|
coalesce( tab1~char1, '-' ) AS coalesced1,
|
||||||
|
coalesce( tab1~char2, '#' ) AS coalesced2,
|
||||||
|
"A coalesce function is a short form of a complex
|
||||||
|
"case distinction such as the following:
|
||||||
|
CASE WHEN tab1~char1 IS NOT NULL THEN tab1~char1
|
||||||
|
ELSE '?'
|
||||||
|
END AS coalesced3
|
||||||
|
|
||||||
|
FROM zdemo_abap_tab2 AS tab2
|
||||||
|
LEFT OUTER JOIN zdemo_abap_tab1 AS tab1 ON tab1~char1 = tab2~char1
|
||||||
|
INTO TABLE @DATA(join_w_null).
|
||||||
|
|
||||||
|
out->write( data = join_w_null name = `join_w_null` ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `19) Aggregate Expressions` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `19) Aggregate Expressions` ) ).
|
||||||
@@ -864,64 +875,121 @@ CLASS zcl_demo_abap_sql IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `20) More SQL Expressions` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `20a) Arithmetic Expressions` ) ).
|
||||||
|
|
||||||
"Arithmetic expressions to perform arithmetic calculations
|
SELECT SINGLE
|
||||||
"Cast expressions to convert the value of operands to a dedicated
|
carrid,
|
||||||
" dictionary type. Note that there are special conversion rules.
|
|
||||||
"String expressions using the operator && to concatenate character
|
"Arithmethic expressions
|
||||||
" strings.
|
"operators + - *
|
||||||
"Case distinctions to carry out either a simple (comparison of the
|
"Note that / is not allowed in integer expressions as the one below
|
||||||
" values of a dedicated operand) or complex (searched case;
|
( 1 + 2 ) * 3 AS calc,
|
||||||
" evaluation of multiple logical expressions) case distinction.
|
|
||||||
|
"/ used in an expression using type adjustment in ABAP SQL.
|
||||||
|
"A cast expression converts the value of the operands to the
|
||||||
|
"specified dictionary type. The result is a representation of the
|
||||||
|
"source value in the specified type.
|
||||||
|
CAST( 1 AS D34N ) / CAST( 2 AS D34N ) AS ratio
|
||||||
|
|
||||||
|
FROM zdemo_abap_carr
|
||||||
|
WHERE carrid = 'AA'
|
||||||
|
INTO @DATA(arithmetic_sql_expr).
|
||||||
|
|
||||||
|
out->write( data = arithmetic_sql_expr name = `arithmetic_sql_expr` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `20b) Cast Expressions` ) ).
|
||||||
|
|
||||||
|
SELECT SINGLE
|
||||||
|
carrid,
|
||||||
|
|
||||||
|
"A cast expression converts the value of the operands to the
|
||||||
|
"specified dictionary type. The result is a representation of the
|
||||||
|
"source value in the specified type.
|
||||||
|
CAST( 1 AS D34N ) / CAST( 2 AS D34N ) AS ratio,
|
||||||
|
CAST( connid AS INT4 ) AS connidnum,
|
||||||
|
CAST( @( cl_abap_context_info=>get_system_date( ) ) AS CHAR ) AS dat
|
||||||
|
|
||||||
|
FROM zdemo_abap_fli
|
||||||
|
WHERE carrid = 'AA'
|
||||||
|
INTO @DATA(cast_expr).
|
||||||
|
|
||||||
|
out->write( data = cast_expr name = `cast_expr` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `20c) String Expressions` ) ).
|
||||||
|
|
||||||
|
SELECT SINGLE
|
||||||
|
carrid,
|
||||||
|
|
||||||
|
"String expression using && to concatenate two character strings;
|
||||||
|
"the result of the concatenation must not be longer than
|
||||||
|
"255 characters.
|
||||||
|
carrid && char`_` && carrname AS concat
|
||||||
|
|
||||||
|
FROM zdemo_abap_carr
|
||||||
|
WHERE carrid = 'AA'
|
||||||
|
INTO @DATA(string_expr).
|
||||||
|
|
||||||
|
out->write( data = string_expr name = `string_expr` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `20d) Case Expressions` ) ).
|
||||||
|
|
||||||
SELECT SINGLE
|
SELECT SINGLE
|
||||||
carrid,
|
carrid,
|
||||||
|
|
||||||
"Arithmethic expressions
|
|
||||||
"operators + - *
|
|
||||||
"Note that / is not allowed in integer expressions as the
|
|
||||||
"one below.
|
|
||||||
( 1 + 2 ) * 3 AS calc,
|
|
||||||
|
|
||||||
"/ used in an expression using type adjustment in ABAP SQL.
|
|
||||||
"A cast expression converts the value of the operands to the
|
|
||||||
"specified dictionary type. The result is a representation of
|
|
||||||
"the source value in the specified type.
|
|
||||||
CAST( 1 AS D34N ) / CAST( 2 AS D34N ) AS ratio,
|
|
||||||
|
|
||||||
"String expression using && to concatenate two character strings;
|
|
||||||
"the result of the concatenation must not be longer than
|
|
||||||
"255 characters.
|
|
||||||
carrid && carrname AS concat,
|
|
||||||
|
|
||||||
"Case distinction
|
|
||||||
"Simple case distinction
|
"Simple case distinction
|
||||||
"The expression compares the values of an operand with other
|
"The expression compares the values of an operand with other
|
||||||
"operands. Result: The first operand after THEN for which the
|
"operands. Result: The first operand after THEN for which the
|
||||||
"comparison is true. If no matches are found, the result
|
"comparison is true. If no matches are found, the result specified
|
||||||
"specified after ELSE is selected.
|
"after ELSE is selected.
|
||||||
CASE currcode
|
CASE currcode
|
||||||
WHEN 'EUR' THEN 'A'
|
WHEN 'EUR' THEN 'A'
|
||||||
WHEN 'USD' THEN 'B'
|
WHEN 'USD' THEN 'B'
|
||||||
ELSE 'C'
|
ELSE 'C'
|
||||||
END AS case_simple,
|
END AS case_simple,
|
||||||
|
|
||||||
"Complex case distinction
|
"Complex case distinction
|
||||||
"The expression evaluates logical expressions. Result: The first
|
"The expression evaluates logical expressions. Result: The first
|
||||||
"operand after THEN for which the logical expression is true. If
|
"operand after THEN for which the logical expression is true. If no
|
||||||
"no logical expressions are true, the result specified after ELSE
|
"logical expressions are true, the result specified after ELSE is
|
||||||
"is selected.
|
"selected.
|
||||||
CASE WHEN length( carrname ) <= 5 THEN 'small'
|
CASE WHEN length( carrname ) <= 5 THEN 'small'
|
||||||
WHEN length( carrname ) BETWEEN 6 AND 10 THEN 'mid'
|
WHEN length( carrname ) BETWEEN 6 AND 10 THEN 'mid'
|
||||||
WHEN length( carrname ) BETWEEN 11 AND 15 THEN 'large'
|
WHEN length( carrname ) BETWEEN 11 AND 15 THEN 'large'
|
||||||
ELSE 'huge'
|
ELSE 'huge'
|
||||||
END AS case_complex
|
END AS case_complex
|
||||||
FROM zdemo_abap_carr
|
|
||||||
WHERE carrid = 'AA'
|
|
||||||
INTO @DATA(more_sql_expr).
|
|
||||||
|
|
||||||
out->write( data = more_sql_expr name = `more_sql_expr` ).
|
FROM zdemo_abap_carr
|
||||||
|
WHERE carrid = 'AA'
|
||||||
|
INTO @DATA(case_expr).
|
||||||
|
|
||||||
|
out->write( data = case_expr name = `case_expr` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `20e) Null Expressions` ) ).
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
carrid,
|
||||||
|
carrname,
|
||||||
|
"The type of the null value is determined by the context.
|
||||||
|
"When the null value is passed to the internal table,
|
||||||
|
"it is converted to the initial value. In the first case,
|
||||||
|
"it is ' '. In the second case, it is 0..
|
||||||
|
CASE WHEN length( carrname ) > 12 THEN char`X`
|
||||||
|
ELSE NULL
|
||||||
|
END AS long_name,
|
||||||
|
CAST( NULL AS INT1 ) AS null_val
|
||||||
|
|
||||||
|
FROM zdemo_abap_carr
|
||||||
|
INTO TABLE @DATA(null_expr).
|
||||||
|
|
||||||
|
out->write( data = null_expr name = `null_expr` ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -1049,6 +1117,239 @@ CLASS zcl_demo_abap_sql IMPLEMENTATION.
|
|||||||
|
|
||||||
out->write( data = itab_like_in name = `itab_like_in` ).
|
out->write( data = itab_like_in name = `itab_like_in` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `25b) SQL conditions (4)` ) ).
|
||||||
|
|
||||||
|
"---- SQL conditions demonstrated with the WHERE clause ----
|
||||||
|
"Note:
|
||||||
|
"- For most of the self-contained examples, an internal table is used as the
|
||||||
|
" data source of SELECT statements to work with simple data.
|
||||||
|
"- For some examples that are covered, such as subqueries, demo database tables
|
||||||
|
" from the cheat sheet repository are used in addition.
|
||||||
|
"- Dynamic specifications are also possible. They are not covered here. See
|
||||||
|
" the Dynamic Programming cheat sheet.
|
||||||
|
|
||||||
|
"---- Types and internal table to work with in the examples ----
|
||||||
|
"Note: You cannot use type string columns in WHERE conditions.
|
||||||
|
TYPES: BEGIN OF demo_struc,
|
||||||
|
id TYPE i,
|
||||||
|
name TYPE c LENGTH 15,
|
||||||
|
"name TYPE string,
|
||||||
|
END OF demo_struc.
|
||||||
|
DATA itab_sql_cond TYPE SORTED TABLE OF demo_struc WITH UNIQUE KEY id.
|
||||||
|
"Populating internal table with data to work with in the examples
|
||||||
|
itab_sql_cond = VALUE #( ( id = 1 name = 'bear' )
|
||||||
|
( id = 2 name = 'camel' )
|
||||||
|
( id = 3 name = 'rabbit' )
|
||||||
|
( id = 4 name = 'zebra' )
|
||||||
|
( id = 5 name = 'dog' )
|
||||||
|
( id = 6 name = 'deer' )
|
||||||
|
( id = 7 name = 'squirrel' )
|
||||||
|
( id = 8 name = 'cheetah' )
|
||||||
|
( id = 9 name = 'elephant' )
|
||||||
|
( id = 10 name = 'donkey' )
|
||||||
|
( id = 11 name = 'fish' )
|
||||||
|
( id = 12 name = 'sheep' ) ).
|
||||||
|
|
||||||
|
"---- =, <>, >, >= (as a selection of possible comparison operators) ----
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE name = 'bear' INTO TABLE @DATA(it).
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE name <> 'bear' INTO TABLE @it.
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE id > 10 INTO TABLE @it.
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE id >= 10 INTO TABLE @it.
|
||||||
|
|
||||||
|
"---- Combining logical expressions using AND, OR and parentheses ----
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE id = 1 AND name = 'bear' INTO TABLE @it.
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE name = 'bear' OR name = 'sheep' INTO TABLE @it.
|
||||||
|
|
||||||
|
"In the following example, the resulting table is initial. One of the expressions
|
||||||
|
"in parentheses is false (AND is used between the expressions in parentheses).
|
||||||
|
"In contrast, the example below returns an entry because of using OR.
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab
|
||||||
|
WHERE ( id = 1 AND name = 'bear' )
|
||||||
|
AND ( id = 20 AND name = 'camel' )
|
||||||
|
INTO TABLE @it.
|
||||||
|
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab
|
||||||
|
WHERE ( id = 1 AND name = 'bear' )
|
||||||
|
OR ( id = 20 AND name = 'camel' )
|
||||||
|
INTO TABLE @it.
|
||||||
|
|
||||||
|
"------------------------ [NOT] BETWEEN ------------------------
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE id BETWEEN 1 AND 4 INTO TABLE @it.
|
||||||
|
"The condition with BETWEEN above corresponds to the following condition.
|
||||||
|
"The example makes use of a condition specified in parentheses to combine multiple
|
||||||
|
"expressions.
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE ( id >= 1 AND id <= 4 ) INTO TABLE @it.
|
||||||
|
"Negation with NOT
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE id NOT BETWEEN 1 AND 4 INTO TABLE @it.
|
||||||
|
|
||||||
|
"------------------------ IS [NOT] INITIAL ------------------------
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE id IS NOT INITIAL INTO TABLE @it.
|
||||||
|
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE id IS INITIAL INTO TABLE @it.
|
||||||
|
|
||||||
|
"------------------------ [NOT] LIKE ------------------------
|
||||||
|
"For (not) matching a specified pattern
|
||||||
|
"Note: % (any character string), _ (any character).
|
||||||
|
SELECT name FROM @itab_sql_cond AS tab
|
||||||
|
WHERE name LIKE '%ee%'
|
||||||
|
OR name LIKE '_o%'
|
||||||
|
INTO TABLE @DATA(names). "dog,deer,cheetah,donkey,sheep
|
||||||
|
|
||||||
|
SELECT name FROM @itab_sql_cond AS tab
|
||||||
|
WHERE name NOT LIKE '%ee%'
|
||||||
|
INTO TABLE @names.
|
||||||
|
|
||||||
|
"ESCAPE addition for defining a single-character escape character
|
||||||
|
"In the following example, this character is #. It is placed before
|
||||||
|
"the % character in the specification after LIKE. In this case, %
|
||||||
|
"is escaped and does then not stand for any character string in the
|
||||||
|
"evaluation.
|
||||||
|
"Adding a table entry for this syntax example.
|
||||||
|
itab_sql_cond = VALUE #( BASE itab_sql_cond ( id = 13 name = '100%' ) ).
|
||||||
|
"Any character sequence followed by the % character
|
||||||
|
SELECT name FROM @itab_sql_cond AS tab
|
||||||
|
WHERE name LIKE '%#%' ESCAPE '#'
|
||||||
|
INTO TABLE @names.
|
||||||
|
|
||||||
|
"Deleting the entry because it is not relevant for the further examples.
|
||||||
|
DELETE itab_sql_cond INDEX 13.
|
||||||
|
|
||||||
|
"------------------------ [NOT] IN (using a value set) ------------------------
|
||||||
|
"For (not) matching a value in a set of values specified in parentheses.
|
||||||
|
|
||||||
|
"Single operands on the left side of IN
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab
|
||||||
|
WHERE name IN ( 'camel', 'rabbit', 'dog', 'snake' )
|
||||||
|
INTO TABLE @it.
|
||||||
|
|
||||||
|
"Negation NOT IN; note to use host variables/expressions for local/global data objects
|
||||||
|
DATA(animal) = 'sheep'.
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab
|
||||||
|
WHERE name NOT IN ( 'fish', @animal )
|
||||||
|
INTO TABLE @it.
|
||||||
|
|
||||||
|
"Operand list (a parenthesized comma-separated list) on the left side of IN
|
||||||
|
"For (not) matching value tuples from a set of value tuples specified in parentheses on the right side.
|
||||||
|
"In the following example, two values are specified in the operand list on the left. Consequently,
|
||||||
|
"two values with appropriate types must be specified in parentheses on the right.
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab
|
||||||
|
WHERE ( id, name ) IN ( ( 1, 'bear' ), ( 3, 'rabbit' ), ( 8, 'zebra' ), ( 20, 'dog' ) )
|
||||||
|
INTO TABLE @it.
|
||||||
|
|
||||||
|
|
||||||
|
"------------------------ [NOT] IN (using a subquery) ------------------------
|
||||||
|
"[NOT] IN for matching a value contained in the result set of a subquery
|
||||||
|
|
||||||
|
"In the following example, the subquery reads data from a demo database table.
|
||||||
|
"For a representative result, the table is cleared, and then filled with 'suitable'
|
||||||
|
"data sets.
|
||||||
|
DELETE FROM zdemo_abap_tab1.
|
||||||
|
MODIFY zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 11 num1 = 11 )
|
||||||
|
( key_field = 12 num1 = 12 )
|
||||||
|
( key_field = 13 num1 = 13 )
|
||||||
|
( key_field = 14 num1 = 14 ) ) ).
|
||||||
|
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab
|
||||||
|
WHERE id IN ( SELECT key_field FROM zdemo_abap_tab1 ) INTO TABLE @it.
|
||||||
|
|
||||||
|
"------------------------ [NOT] IN (using a ranges table) ------------------------
|
||||||
|
"[NOT] IN for checking whether the operands on the left side match a ranges condition in a ranges table
|
||||||
|
|
||||||
|
"Declaring a ranges table
|
||||||
|
DATA rangestab TYPE RANGE OF i.
|
||||||
|
"Populating a ranges table using the VALUE operator
|
||||||
|
rangestab = VALUE #( ( sign = 'I' option = 'BT' low = 1 high = 3 )
|
||||||
|
( sign = 'I' option = 'GE' low = 10 ) ).
|
||||||
|
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE id IN @rangestab INTO TABLE @it.
|
||||||
|
|
||||||
|
|
||||||
|
"You cannot use logical operators such as CP (conforms to pattern) in the WHERE clause.
|
||||||
|
"In a ranges table, they are possible.
|
||||||
|
"Note:
|
||||||
|
"- Regarding CP: * (any character sequence), + (any character), # (escape character)
|
||||||
|
"- An equivalent example above uses the LIKE addition.
|
||||||
|
DATA rt TYPE RANGE OF demo_struc-name.
|
||||||
|
rt = VALUE #( ( sign = 'I' option = 'CP' low = '*ee*' ) "ee in a string
|
||||||
|
( sign = 'I' option = 'CP' low = '+o*' ) ). "o in second position
|
||||||
|
SELECT name FROM @itab_sql_cond AS tab
|
||||||
|
WHERE name IN @rt
|
||||||
|
INTO TABLE @names.
|
||||||
|
|
||||||
|
"------------------------ EXISTS ------------------------
|
||||||
|
"For checking the result set of a subquery.
|
||||||
|
"The following example reads all entries from the internal table if entries having
|
||||||
|
"the same key also exist in the database table.
|
||||||
|
"Note: The SELECT list in the subquery only contains a literal to determine that
|
||||||
|
"the entry exists. Specifying explicit column names is not relevant.
|
||||||
|
SELECT id FROM @itab_sql_cond AS tab WHERE
|
||||||
|
EXISTS ( SELECT @abap_true FROM zdemo_abap_tab1 WHERE key_field = tab~id )
|
||||||
|
INTO TABLE @it.
|
||||||
|
|
||||||
|
"------------------------ IS [NOT] NULL ------------------------
|
||||||
|
"The null value is a special value that is returned by a database. It indicates an
|
||||||
|
"undefined value or result. Note that, in ABAP, there are no special null values. Do
|
||||||
|
"not confuse the null value with a type-dependent initial value. When using SELECT
|
||||||
|
"statements to read data, null values can be produced by, for example, outer joins.
|
||||||
|
"When the null values are passed to a data object, they are transformed to the
|
||||||
|
"type-dependent initial values. For more information, refer to the ABAP Keyword Documentation.
|
||||||
|
"The following example uses a left outer join to intentionally create null values. For
|
||||||
|
"this purpose, two demo database tables of the cheat sheet repository are cleared and
|
||||||
|
"populated with specific values to visualize null values.
|
||||||
|
DELETE FROM zdemo_abap_tab1.
|
||||||
|
DELETE FROM zdemo_abap_tab2.
|
||||||
|
MODIFY zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 1 char1 = 'a' char2 = 'y' )
|
||||||
|
( key_field = 2 char1 = 'b' char2 = 'z' ) ) ).
|
||||||
|
MODIFY zdemo_abap_tab2 FROM TABLE @( VALUE #( ( key_field = 1 char1 = 'a' )
|
||||||
|
( key_field = 2 char1 = 'a' )
|
||||||
|
( key_field = 3 char1 = 'b' )
|
||||||
|
( key_field = 4 ) ) ).
|
||||||
|
|
||||||
|
"Note that for the entry 'key_field = 4' no char1 value was passed.
|
||||||
|
"char1 is a shared column of the two database tables, and which is used in
|
||||||
|
"the ON condition of the join. Since there is no entry in char1 for 'key_field = 4',
|
||||||
|
"the joined values are null in that case. The WHERE clause uses the addition IS NULL.
|
||||||
|
"Therefore, the result only contains this entry. char2 is assigned the type-initial
|
||||||
|
"value in the result.
|
||||||
|
SELECT tab2~key_field, tab1~char2
|
||||||
|
FROM zdemo_abap_tab2 AS tab2
|
||||||
|
LEFT OUTER JOIN zdemo_abap_tab1 AS tab1 ON tab1~char1 = tab2~char1
|
||||||
|
WHERE tab1~char1 IS NULL
|
||||||
|
INTO TABLE @DATA(joined_tab).
|
||||||
|
|
||||||
|
"The following example visualizes the null values. The INDICATORS addition of the
|
||||||
|
"INTO clause is used to specify indicators such as the null indicator. In the
|
||||||
|
"example, an appropriate target table is defined to also store information about
|
||||||
|
"which columns of the result set contain the null value and which do not.
|
||||||
|
"For more information on the syntax, refer to the ABAP Keyword Documentation.
|
||||||
|
TYPES: BEGIN OF st4null,
|
||||||
|
BEGIN OF s2,
|
||||||
|
key_field TYPE zdemo_abap_tab2-key_field,
|
||||||
|
char2 TYPE zdemo_abap_tab1-char2,
|
||||||
|
END OF s2,
|
||||||
|
BEGIN OF nulls,
|
||||||
|
key_field TYPE c LENGTH 1,
|
||||||
|
char2 TYPE c LENGTH 1,
|
||||||
|
END OF nulls,
|
||||||
|
END OF st4null.
|
||||||
|
DATA joined_tab_w_null_ind TYPE TABLE OF st4null WITH EMPTY KEY.
|
||||||
|
|
||||||
|
SELECT tab2~key_field, tab1~char2
|
||||||
|
FROM zdemo_abap_tab2 AS tab2
|
||||||
|
LEFT OUTER JOIN zdemo_abap_tab1 AS tab1 ON tab1~char1 = tab2~char1
|
||||||
|
INTO TABLE @joined_tab_w_null_ind INDICATORS NULL STRUCTURE nulls.
|
||||||
|
|
||||||
|
"Negation IS NOT NULL
|
||||||
|
SELECT tab2~key_field, tab1~char2
|
||||||
|
FROM zdemo_abap_tab2 AS tab2
|
||||||
|
LEFT OUTER JOIN zdemo_abap_tab1 AS tab1 ON tab1~char1 = tab2~char1
|
||||||
|
WHERE tab1~char1 IS NOT NULL
|
||||||
|
INTO TABLE @joined_tab.
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `Further clauses in SELECT statements` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `Further clauses in SELECT statements` ) ).
|
||||||
@@ -1261,6 +1562,60 @@ CLASS zcl_demo_abap_sql IMPLEMENTATION.
|
|||||||
|
|
||||||
out->write( data = itab_union name = `itab_union` ).
|
out->write( data = itab_union name = `itab_union` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `33b) Returning distinct rows of a result set using INTERSECT` ) ).
|
||||||
|
|
||||||
|
SELECT zdemo_abap_flsch~carrid, zdemo_abap_carr~carrname
|
||||||
|
FROM zdemo_abap_flsch
|
||||||
|
INNER JOIN zdemo_abap_carr ON zdemo_abap_carr~carrid = zdemo_abap_flsch~carrid
|
||||||
|
ORDER BY zdemo_abap_flsch~carrid
|
||||||
|
INTO TABLE @DATA(itab_no_intersect).
|
||||||
|
|
||||||
|
out->write( data = itab_no_intersect name = `itab_no_intersect` ).
|
||||||
|
out->write( |\n| ).
|
||||||
|
|
||||||
|
"Using INTERSECT; the result set contains distinct rows
|
||||||
|
SELECT zdemo_abap_flsch~carrid, zdemo_abap_carr~carrname
|
||||||
|
FROM zdemo_abap_flsch
|
||||||
|
INNER JOIN zdemo_abap_carr ON zdemo_abap_carr~carrid = zdemo_abap_flsch~carrid
|
||||||
|
INTERSECT
|
||||||
|
SELECT carrid, carrname
|
||||||
|
FROM zdemo_abap_carr
|
||||||
|
ORDER BY carrid
|
||||||
|
INTO TABLE @DATA(itab_w_intersect).
|
||||||
|
|
||||||
|
out->write( data = itab_no_intersect name = `itab_w_intersect` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `33c) Returning distinct rows of a result set using EXCEPT` ) ).
|
||||||
|
|
||||||
|
"Selecting all carrier IDs from a database table that do not exist in an
|
||||||
|
"internal table
|
||||||
|
TYPES: ty_demo_tab TYPE TABLE OF zdemo_abap_flsch WITH EMPTY KEY.
|
||||||
|
DATA(itab_except) = VALUE ty_demo_tab( ( carrid = 'LH' ) ( carrid = 'LH' ) ( carrid = 'LH' )
|
||||||
|
( carrid = 'AA' ) ( carrid = 'AA' ) ).
|
||||||
|
|
||||||
|
|
||||||
|
"Selecting all carrier IDs for comparison
|
||||||
|
SELECT carrid
|
||||||
|
FROM zdemo_abap_carr
|
||||||
|
INTO TABLE @DATA(all_carrids).
|
||||||
|
|
||||||
|
"Using EXCEPT; the result set excludes those carrier IDs present in the
|
||||||
|
"internal table
|
||||||
|
SELECT carrid
|
||||||
|
FROM zdemo_abap_carr
|
||||||
|
EXCEPT
|
||||||
|
SELECT it~carrid
|
||||||
|
FROM @itab_except AS it
|
||||||
|
INNER JOIN zdemo_abap_carr ON zdemo_abap_carr~carrid = it~carrid
|
||||||
|
ORDER BY carrid ASCENDING
|
||||||
|
INTO TABLE @DATA(itab_w_except).
|
||||||
|
|
||||||
|
out->write( data = itab_w_except name = `itab_w_except` ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `34) Common Table Expressions (CTE) (1)` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `34) Common Table Expressions (CTE) (1)` ) ).
|
||||||
@@ -1606,6 +1961,226 @@ CLASS zcl_demo_abap_sql IMPLEMENTATION.
|
|||||||
select_from_dbtab( ).
|
select_from_dbtab( ).
|
||||||
out->write( data = itab_res name = `itab_res` ).
|
out->write( data = itab_res name = `itab_res` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `47) Exploring ABAP SQL statements using constructor expressions created in place` ) ).
|
||||||
|
|
||||||
|
TYPES it_type TYPE TABLE OF zdemo_abap_tab1 WITH EMPTY KEY.
|
||||||
|
DELETE FROM zdemo_abap_tab1.
|
||||||
|
|
||||||
|
"--- VALUE ---
|
||||||
|
"VALUE operator as shown above, creating an internal table in place
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 1 char1 = 'aaa' char2 = 'bbb' num1 = 10 num2 = 100 )
|
||||||
|
( key_field = 2 char1 = 'ccc' char2 = 'ddd' num1 = 20 num2 = 200 ) ) ).
|
||||||
|
|
||||||
|
"FOR LOOP with VALUE
|
||||||
|
DATA(it_f) = VALUE it_type( ( key_field = 3 char1 = 'ee' char2 = 'ff' num1 = 30 num2 = 300 )
|
||||||
|
( key_field = 4 char1 = 'gg' char2 = 'hh' num1 = 40 num2 = 400 )
|
||||||
|
( key_field = 5 char1 = 'ii' char2 = 'jj' num1 = 50 num2 = 500 ) ).
|
||||||
|
|
||||||
|
"In the example, the internal table from above is looped across. The index value is
|
||||||
|
"stored and used to modify field values of the internal table. In doing so, the modified
|
||||||
|
"internal table values are inserted into the database table.
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( FOR wa IN it_f INDEX INTO idx ( key_field = wa-key_field
|
||||||
|
char1 = wa-char1 && idx
|
||||||
|
char2 = wa-char2 && idx
|
||||||
|
num1 = wa-num1 + idx
|
||||||
|
num2 = wa-num2 + idx ) ) ).
|
||||||
|
|
||||||
|
"Using a constructor expression with VALUE and BASE in an UPDATE statement
|
||||||
|
"The example assumes selecting an entry from a database, modifying it, and updating it again,
|
||||||
|
"but the non-modified entries shall remain unchanged.
|
||||||
|
INSERT zdemo_abap_tab1 FROM @( VALUE #( key_field = 100 char1 = 'xxx' char2 = 'yyy' num1 = 100 num2 = 101 ) ).
|
||||||
|
|
||||||
|
SELECT SINGLE * FROM zdemo_abap_tab1 WHERE key_field = 100 INTO @DATA(read_line).
|
||||||
|
UPDATE zdemo_abap_tab1 FROM @( VALUE #( BASE read_line char2 = '#' num1 = 1 ) ).
|
||||||
|
|
||||||
|
"--- CORRESPONDING ---
|
||||||
|
TYPES: BEGIN OF s1,
|
||||||
|
key_field TYPE i,
|
||||||
|
char1 TYPE c LENGTH 5,
|
||||||
|
num1 TYPE i,
|
||||||
|
END OF s1,
|
||||||
|
it_type_s1 TYPE TABLE OF s1 WITH EMPTY KEY,
|
||||||
|
BEGIN OF s2,
|
||||||
|
key TYPE i,
|
||||||
|
char TYPE c LENGTH 5,
|
||||||
|
number1 TYPE i,
|
||||||
|
num2 TYPE p LENGTH 8 DECIMALS 2,
|
||||||
|
END OF s2,
|
||||||
|
it_type_s2 TYPE TABLE OF s2 WITH EMPTY KEY.
|
||||||
|
|
||||||
|
"Identical component names in the internal table
|
||||||
|
"The example includes compatible and convertible types.
|
||||||
|
DATA(it_g) = VALUE it_type_s1( ( key_field = 6 char1 = 'kkk' num1 = 60 )
|
||||||
|
( key_field = 7 char1 = 'lll' num1 = 70 ) ).
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( CORRESPONDING #( it_g ) ).
|
||||||
|
|
||||||
|
"Non-identical component names in the internal table; using the MAPPING/EXCEPT additions
|
||||||
|
"The example includes compatible and convertible types.
|
||||||
|
DATA(it_h) = VALUE it_type_s2( ( key = 8 char = 'mmm' number1 = 80 num2 = '1.23' )
|
||||||
|
( key = 9 char = 'nnn' number1 = 90 num2 = '4.56' ) ).
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( CORRESPONDING #( it_h MAPPING key_field = key char2 = char num1 = number1 EXCEPT num2 ) ).
|
||||||
|
|
||||||
|
SELECT * FROM zdemo_abap_tab1 INTO TABLE @DATA(itab_constr).
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `48) Evaluating ABAP System Fields after ABAP SQL Statements` ) ).
|
||||||
|
|
||||||
|
"Clearing a demo database table
|
||||||
|
DELETE FROM zdemo_abap_tab1.
|
||||||
|
|
||||||
|
"--------------------- INSERT ---------------------
|
||||||
|
INSERT zdemo_abap_tab1 FROM @( VALUE #( key_field = 1 ) ).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 2 )
|
||||||
|
( key_field = 3 ) ) ).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
ASSERT sy-dbcnt = 2.
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 2 )
|
||||||
|
( key_field = 3 ) ) ) ACCEPTING DUPLICATE KEYS.
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 4.
|
||||||
|
ASSERT sy-dbcnt = 0.
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 3 )
|
||||||
|
( key_field = 4 ) ) ) ACCEPTING DUPLICATE KEYS.
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 4.
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
"--------------------- UPDATE ---------------------
|
||||||
|
UPDATE zdemo_abap_tab1 FROM @( VALUE #( key_field = 1 num1 = 1 ) ).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
UPDATE zdemo_abap_tab1 FROM @( VALUE #( key_field = 9999 num1 = 9999 ) ).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 4.
|
||||||
|
ASSERT sy-dbcnt = 0.
|
||||||
|
|
||||||
|
UPDATE zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 2 num1 = 2 )
|
||||||
|
( key_field = 3 num1 = 3 ) ) ).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
ASSERT sy-dbcnt = 2.
|
||||||
|
|
||||||
|
UPDATE zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 4 num1 = 4 )
|
||||||
|
( key_field = 1111 num1 = 1111 ) ) ).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 4.
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
"--------------------- MODIFY ---------------------
|
||||||
|
MODIFY zdemo_abap_tab1 FROM @( VALUE #( key_field = 1 num1 = 11 ) ).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
MODIFY zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 2 num1 = 22 ) "Entry modified
|
||||||
|
( key_field = 5 num1 = 5 ) ) ). "Entry inserted
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
ASSERT sy-dbcnt = 2.
|
||||||
|
|
||||||
|
"--------------------- SELECT ---------------------
|
||||||
|
|
||||||
|
SELECT *
|
||||||
|
FROM zdemo_abap_tab1
|
||||||
|
INTO TABLE @DATA(tab).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
ASSERT sy-dbcnt = 5.
|
||||||
|
ASSERT sy-dbcnt = lines( tab ).
|
||||||
|
|
||||||
|
SELECT *
|
||||||
|
FROM zdemo_abap_tab1
|
||||||
|
WHERE key_field <= 3
|
||||||
|
INTO TABLE @DATA(tab2).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
ASSERT sy-dbcnt = 3.
|
||||||
|
|
||||||
|
SELECT *
|
||||||
|
FROM zdemo_abap_tab1
|
||||||
|
WHERE key_field > 10
|
||||||
|
INTO TABLE @DATA(tab3).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 4.
|
||||||
|
ASSERT sy-dbcnt = 0.
|
||||||
|
|
||||||
|
"--------------------- DELETE ---------------------
|
||||||
|
DELETE zdemo_abap_tab1 FROM @( VALUE #( key_field = 1 ) ).
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
DELETE zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 1 ) "Entry not existent
|
||||||
|
( key_field = 2 )
|
||||||
|
( key_field = 3 ) ) ).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 4.
|
||||||
|
ASSERT sy-dbcnt = 2.
|
||||||
|
|
||||||
|
DELETE FROM zdemo_abap_tab1 WHERE key_field >= 5.
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
"Only one entry left in the database table
|
||||||
|
DELETE FROM zdemo_abap_tab1.
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
SELECT *
|
||||||
|
FROM zdemo_abap_tab1
|
||||||
|
INTO TABLE @DATA(tab4).
|
||||||
|
|
||||||
|
ASSERT sy-subrc = 4.
|
||||||
|
ASSERT sy-dbcnt = 0.
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `49) Typed literals` ) ).
|
||||||
|
|
||||||
|
"Miscellaneous typed literals in an ABAP SQL statement
|
||||||
|
"Note that typed literals can be specified in read
|
||||||
|
"positions where host variables are possible.
|
||||||
|
DATA(tmstamp) = CONV timestamp( '20240808112517' ).
|
||||||
|
DATA(some_string) = `Some string`.
|
||||||
|
SELECT SINGLE
|
||||||
|
FROM zdemo_abap_fli
|
||||||
|
FIELDS
|
||||||
|
carrid,
|
||||||
|
@some_string AS host_var,
|
||||||
|
char`X` AS flag,
|
||||||
|
int8`32984723948723` AS int8,
|
||||||
|
raw`11` AS raw,
|
||||||
|
numc`1234` AS numc,
|
||||||
|
utclong`2024-01-01T10:01:02,2` AS utc,
|
||||||
|
tims`101507` AS tims,
|
||||||
|
curr`173.95` AS curr,
|
||||||
|
"Multiple cast expressions splitting a time stamp into date and time parts
|
||||||
|
CAST( CAST( div( @tmstamp, 1000000 ) AS CHAR ) AS DATS ) AS date,
|
||||||
|
CAST( substring( CAST( @tmstamp AS CHAR ), 9, 6 ) AS TIMS ) AS time,
|
||||||
|
"Untyped literal
|
||||||
|
'ABAP' AS txt
|
||||||
|
WHERE fldate = datn`20240102`
|
||||||
|
INTO @DATA(misc_typed_literals).
|
||||||
|
|
||||||
|
out->write( data = misc_typed_literals name = `misc_typed_literals` ).
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +1,11 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>Grouping internal tables</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: ABAP SQL - Grouping Internal Tables
|
"! <p>The example class demonstrates syntax options when grouping internal tables.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* Example to demonstrate syntax options when grouping internal tables.
|
"! <h2>Note</h2>
|
||||||
*
|
"! <p>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
|
||||||
* - 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
|
|
||||||
* 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)
|
|
||||||
* 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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: ABAP SQL - Grouping internal tables</p>
|
|
||||||
"! Example to demonstrate grouping internal tables.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_sql_group_by DEFINITION
|
CLASS zcl_demo_abap_sql_group_by DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<VSEOCLASS>
|
<VSEOCLASS>
|
||||||
<CLSNAME>ZCL_DEMO_ABAP_SQL_GROUP_BY</CLSNAME>
|
<CLSNAME>ZCL_DEMO_ABAP_SQL_GROUP_BY</CLSNAME>
|
||||||
<LANGU>E</LANGU>
|
<LANGU>E</LANGU>
|
||||||
<DESCRIPT>ABAP cheat sheet: ABAP SQL - Grouping Internal Tables</DESCRIPT>
|
<DESCRIPT>ABAP cheat sheet: ABAP SQL - Grouping internal tables</DESCRIPT>
|
||||||
<STATE>1</STATE>
|
<STATE>1</STATE>
|
||||||
<CLSCCINCL>X</CLSCCINCL>
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
<FIXPT>X</FIXPT>
|
<FIXPT>X</FIXPT>
|
||||||
|
|||||||
@@ -1,44 +1,11 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>String processing</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: String processing
|
"! <p>The example class demonstrates various syntax options for processing character strings.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Example to demonstrate various syntax options for processing
|
"! <h2>Note</h2>
|
||||||
* character strings.
|
"! <p>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* - Topics covered: Creating strings and assigning values, chaining strings,
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
|
||||||
* string templates, concatenating/splitting/modifying strings, searching
|
|
||||||
* and replacing, regular expressions
|
|
||||||
*
|
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
|
||||||
* - 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
|
|
||||||
* 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)
|
|
||||||
* 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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: String processing</p>
|
|
||||||
"! Example to demonstrate string processing.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_string_proc DEFINITION
|
CLASS zcl_demo_abap_string_proc DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -99,14 +66,14 @@ CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
|
|||||||
DATA(str_a6) = `efgh`. "Type string
|
DATA(str_a6) = `efgh`. "Type string
|
||||||
|
|
||||||
"Note: Variable is of type c length 4. Characters are truncated.
|
"Note: Variable is of type c length 4. Characters are truncated.
|
||||||
"In newer ABAP releases, the following statement shows a syntax
|
"In newer ABAP releases, the following statement shows a syntax
|
||||||
"warning that the value of the literal (intentionally specified
|
"warning that the value of the literal (intentionally specified
|
||||||
"here like this) is not an admissable value for the target type.
|
"here like this) is not an admissable value for the target type.
|
||||||
"Therefore, the example is provided differently to circumvent the
|
"Therefore, the example is provided differently to circumvent the
|
||||||
"syntax warning.
|
"syntax warning.
|
||||||
|
|
||||||
"char_a2 = 'ijklmnopq'.
|
"char_a2 = 'ijklmnopq'.
|
||||||
|
|
||||||
TYPES c_l9 TYPE c LENGTH 9.
|
TYPES c_l9 TYPE c LENGTH 9.
|
||||||
DATA some_char TYPE c_l9 VALUE 'ijklmnopq'.
|
DATA some_char TYPE c_l9 VALUE 'ijklmnopq'.
|
||||||
char_a2 = some_char.
|
char_a2 = some_char.
|
||||||
@@ -302,7 +269,7 @@ CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `6) Concatenating Strings` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `6a) Concatenating Strings` ) ).
|
||||||
|
|
||||||
DATA(str_f1) = `Hallo`.
|
DATA(str_f1) = `Hallo`.
|
||||||
DATA(str_f2) = `world`.
|
DATA(str_f2) = `world`.
|
||||||
@@ -381,6 +348,58 @@ CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
|
|||||||
out->write( |\n| ).
|
out->write( |\n| ).
|
||||||
out->write( data = alphabet5 name = `alphabet5` ).
|
out->write( data = alphabet5 name = `alphabet5` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `6b) Literal Operator` ) ).
|
||||||
|
|
||||||
|
"Literal operator
|
||||||
|
"Used to combine character literals of the same type into a single character literal
|
||||||
|
DATA(abap) = 'AB' & 'AP'.
|
||||||
|
|
||||||
|
"Note an upper limit of 255 characters
|
||||||
|
"If you remove the comment, which results in a combined character literal
|
||||||
|
"of 256 characters, a syntax error is displayed.
|
||||||
|
DATA(c_limit_255) =
|
||||||
|
'##################################################' & "50 x #
|
||||||
|
'##################################################' &
|
||||||
|
'##################################################' &
|
||||||
|
'##################################################' &
|
||||||
|
'##################################################' &
|
||||||
|
'#####'
|
||||||
|
"& '#'
|
||||||
|
.
|
||||||
|
|
||||||
|
"Trailing blanks are respected
|
||||||
|
DATA(char_with_blanks) = 'AB' & 'AP' & ' '.
|
||||||
|
|
||||||
|
"Using RTTI to get type information, retrieving the output length of the combined literal
|
||||||
|
DATA(output_length) = CAST cl_abap_elemdescr( cl_abap_typedescr=>describe_by_data( char_with_blanks ) )->output_length.
|
||||||
|
out->write( data = output_length name = `output_length` ).
|
||||||
|
out->write( |\n| ).
|
||||||
|
|
||||||
|
DATA(ch1) = 'AB'.
|
||||||
|
DATA(ch2) = 'AP'.
|
||||||
|
"Not possible as the operands are not character literals but data objects
|
||||||
|
"DATA(combined_ch) = ch1 & ch2.
|
||||||
|
|
||||||
|
"Not to be confused with the concatenation operator && to concatenate
|
||||||
|
"character-like operands; at runtime, any number of character-like operands
|
||||||
|
"are possible
|
||||||
|
"The result in the example is of type string.
|
||||||
|
DATA(combined_ch_with_conc_op) = ch1 && ch2.
|
||||||
|
|
||||||
|
"Concatenation similar to the example above
|
||||||
|
"As the result is of type string using the concatenation operator, the
|
||||||
|
"trailing blanks are not respected.
|
||||||
|
DATA(char_with_blanks_conc_op) = 'AB' && 'AP' && ' '.
|
||||||
|
|
||||||
|
DATA(len1) = strlen( char_with_blanks_conc_op ).
|
||||||
|
DATA(len2) = numofchar( char_with_blanks_conc_op ).
|
||||||
|
|
||||||
|
out->write( data = len1 name = `len1` ).
|
||||||
|
out->write( |\n| ).
|
||||||
|
out->write( data = len2 name = `len2` ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `7) Splitting Strings` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `7) Splitting Strings` ) ).
|
||||||
@@ -427,6 +446,11 @@ CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
|
|||||||
ENDTRY.
|
ENDTRY.
|
||||||
ENDDO.
|
ENDDO.
|
||||||
|
|
||||||
|
"SPLIT statement specifying a colon after INTO
|
||||||
|
DATA(some_text) = `Lorem ipsum dolor sit amet, consectetur adipiscing elit`.
|
||||||
|
|
||||||
|
SPLIT some_text AT ` ` INTO: DATA(str1) DATA(str2) DATA(str3) DATA(str4), TABLE DATA(tab).
|
||||||
|
|
||||||
out->write( data = str_g2 name = `str_g2` ).
|
out->write( data = str_g2 name = `str_g2` ).
|
||||||
out->write( |\n| ).
|
out->write( |\n| ).
|
||||||
out->write( data = str_g3 name = `str_g3` ).
|
out->write( data = str_g3 name = `str_g3` ).
|
||||||
@@ -446,6 +470,16 @@ CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
|
|||||||
out->write( data = itab_g2 name = `itab_g2` ).
|
out->write( data = itab_g2 name = `itab_g2` ).
|
||||||
out->write( |\n| ).
|
out->write( |\n| ).
|
||||||
out->write( data = seg_nom name = `seg_nom` ).
|
out->write( data = seg_nom name = `seg_nom` ).
|
||||||
|
out->write( |\n| ).
|
||||||
|
out->write( data = str1 name = `str1` ).
|
||||||
|
out->write( |\n| ).
|
||||||
|
out->write( data = str2 name = `str2` ).
|
||||||
|
out->write( |\n| ).
|
||||||
|
out->write( data = str3 name = `str3` ).
|
||||||
|
out->write( |\n| ).
|
||||||
|
out->write( data = str4 name = `str4` ).
|
||||||
|
out->write( |\n| ).
|
||||||
|
out->write( data = tab name = `tab` ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
@@ -1558,6 +1592,7 @@ CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
|
|||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `25) Complex Searching Using ` &&
|
out->write( zcl_demo_abap_aux=>heading( `25) Complex Searching Using ` &&
|
||||||
`Regular Expressions` ) ).
|
`Regular Expressions` ) ).
|
||||||
|
"Also note the cheat sheet example on regular expressions in ABAP.
|
||||||
|
|
||||||
DATA(str_y) = `Cathy's black cat was fast asleep on the mat. ` &&
|
DATA(str_y) = `Cathy's black cat was fast asleep on the mat. ` &&
|
||||||
`Later that day, the cat played with Matt.`.
|
`Later that day, the cat played with Matt.`.
|
||||||
@@ -2247,5 +2282,159 @@ CLASS zcl_demo_abap_string_proc IMPLEMENTATION.
|
|||||||
ENDIF.
|
ENDIF.
|
||||||
|
|
||||||
out->write( data = match name = `match` ).
|
out->write( data = match name = `match` ).
|
||||||
|
|
||||||
|
***********************************************************************
|
||||||
|
|
||||||
|
"------------------------ Byte String Processing ------------------------
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `34) Determining the Length of xstrings` ) ).
|
||||||
|
|
||||||
|
DATA(hi) = `Hello world`.
|
||||||
|
|
||||||
|
DATA(conv_xstring) = cl_abap_conv_codepage=>create_out( codepage = `UTF-8` )->convert( hi ).
|
||||||
|
|
||||||
|
DATA(len_str) = strlen( CONV string( conv_xstring ) ).
|
||||||
|
out->write( data = len_str name = `len_str` ).
|
||||||
|
|
||||||
|
DATA(len_xstr) = xstrlen( conv_xstring ).
|
||||||
|
out->write( data = len_xstr name = `len_xstr` ).
|
||||||
|
|
||||||
|
***********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `35) Character String and Byte String Processing with ABAP Statements` ) ).
|
||||||
|
|
||||||
|
DATA off TYPE i.
|
||||||
|
DATA(abc_str) = `abc def ghi jkl mno pqr stu vwx yz`.
|
||||||
|
DATA(copy_str) = abc_str.
|
||||||
|
|
||||||
|
"-----------------------------------------------------------------------------
|
||||||
|
"------------------------ FIND and REPLACE statements ------------------------
|
||||||
|
"-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
"------------------------ IN CHARACTER MODE addition ------------------------
|
||||||
|
|
||||||
|
"Searching for the first blank in the string
|
||||||
|
FIND ` ` IN abc_str IN CHARACTER MODE MATCH OFFSET off.
|
||||||
|
|
||||||
|
"The following example is the same as the previous as the IN CHARACTER MODE
|
||||||
|
"addition is optional. The FIRST OCCURRENCE OF addition is also optional.
|
||||||
|
"Just using FIND without FIRST OCCURRENCE OF means searching for the first
|
||||||
|
"occurrence by default.
|
||||||
|
FIND FIRST OCCURRENCE OF ` ` IN abc_str MATCH OFFSET off.
|
||||||
|
|
||||||
|
"Searching for all blanks in the string
|
||||||
|
FIND ALL OCCURRENCES OF ` ` IN abc_str IN CHARACTER MODE RESULTS DATA(res).
|
||||||
|
DATA(offsets_of_findings) = concat_lines_of(
|
||||||
|
table = VALUE string_table( FOR wa IN res ( condense( val = CONV string( wa-offset ) to = `` ) ) ) sep = `, ` ).
|
||||||
|
|
||||||
|
"Replacing the first blank in the string
|
||||||
|
REPLACE ` ` IN abc_str WITH `#` IN CHARACTER MODE.
|
||||||
|
|
||||||
|
abc_str = copy_str.
|
||||||
|
|
||||||
|
"Replacing all blanks in the string
|
||||||
|
REPLACE ALL OCCURRENCES OF ` ` IN abc_str WITH `#` IN CHARACTER MODE.
|
||||||
|
|
||||||
|
abc_str = copy_str.
|
||||||
|
|
||||||
|
"------------------------ IN BYTE MODE addition ------------------------
|
||||||
|
|
||||||
|
"Converting to xstring
|
||||||
|
DATA(abc_xstr) = cl_abap_conv_codepage=>create_out( )->convert( abc_str ).
|
||||||
|
DATA(blank_xstr) = cl_abap_conv_codepage=>create_out( )->convert( ` ` ).
|
||||||
|
DATA(repl_xstr) = cl_abap_conv_codepage=>create_out( )->convert( `#` ).
|
||||||
|
DATA(copy_xstr) = abc_xstr.
|
||||||
|
|
||||||
|
"Searching for the first byte that represents a blank in the UTF-8 code page
|
||||||
|
FIND blank_xstr IN abc_xstr IN BYTE MODE MATCH OFFSET off.
|
||||||
|
|
||||||
|
FIND ALL OCCURRENCES OF blank_xstr IN abc_xstr IN BYTE MODE RESULTS res.
|
||||||
|
DATA(offsets_of_findings_xstr) = concat_lines_of(
|
||||||
|
table = VALUE string_table( FOR wa IN res ( condense( val = CONV string( wa-offset ) to = `` ) ) ) sep = `, ` ).
|
||||||
|
|
||||||
|
"Replacing the first byte that represents a blank in the UTF-8 code page
|
||||||
|
REPLACE blank_xstr IN abc_xstr WITH repl_xstr IN BYTE MODE.
|
||||||
|
|
||||||
|
abc_xstr = copy_xstr.
|
||||||
|
|
||||||
|
"Replacing all bytes that represent a blank in the UTF-8 code page
|
||||||
|
REPLACE ALL OCCURRENCES OF blank_xstr IN abc_xstr WITH repl_xstr IN BYTE MODE.
|
||||||
|
|
||||||
|
"-----------------------------------------------------------------------------
|
||||||
|
"--------------------------- CONCATENATE statements --------------------------
|
||||||
|
"-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
DATA(part_str1) = `abc`.
|
||||||
|
DATA(part_str2) = `def`.
|
||||||
|
|
||||||
|
CONCATENATE part_str1 part_str2 INTO DATA(concat_str) IN CHARACTER MODE.
|
||||||
|
|
||||||
|
CONCATENATE part_str1 part_str2 INTO concat_str SEPARATED BY `/` IN CHARACTER MODE.
|
||||||
|
|
||||||
|
"Same as above
|
||||||
|
CONCATENATE part_str1 part_str2 INTO concat_str.
|
||||||
|
CONCATENATE part_str1 part_str2 INTO concat_str SEPARATED BY `/`.
|
||||||
|
|
||||||
|
DATA(part_xstr1) = cl_abap_conv_codepage=>create_out( )->convert( part_str1 ).
|
||||||
|
DATA(part_xstr2) = cl_abap_conv_codepage=>create_out( )->convert( part_str2 ).
|
||||||
|
DATA(sep_xstr) = cl_abap_conv_codepage=>create_out( )->convert( `/` ).
|
||||||
|
|
||||||
|
CONCATENATE part_xstr1 part_xstr2 INTO DATA(concat_xstr) IN BYTE MODE.
|
||||||
|
|
||||||
|
DATA(concat_xstr_converted) = cl_abap_conv_codepage=>create_in( )->convert( concat_xstr ).
|
||||||
|
|
||||||
|
CONCATENATE part_xstr1 part_xstr2 INTO concat_xstr SEPARATED BY sep_xstr IN BYTE MODE.
|
||||||
|
|
||||||
|
concat_xstr_converted = cl_abap_conv_codepage=>create_in( )->convert( concat_xstr ).
|
||||||
|
|
||||||
|
"Creating a table of type xstring
|
||||||
|
DATA(xstr_table) = VALUE xstring_table( ( part_xstr1 ) ( part_xstr2 ) ).
|
||||||
|
|
||||||
|
CONCATENATE LINES OF xstr_table INTO DATA(concat_xstr_tab) IN BYTE MODE.
|
||||||
|
|
||||||
|
DATA(concat_xstr_tab_converted) = cl_abap_conv_codepage=>create_in( )->convert( concat_xstr_tab ).
|
||||||
|
|
||||||
|
"-----------------------------------------------------------------------------
|
||||||
|
"------------------------------- SHIFT statements ----------------------------
|
||||||
|
"-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
DATA(test_string) = `abcdef`.
|
||||||
|
DATA(copy) = test_string.
|
||||||
|
|
||||||
|
SHIFT test_string IN CHARACTER MODE.
|
||||||
|
|
||||||
|
test_string = copy.
|
||||||
|
|
||||||
|
"Same as
|
||||||
|
SHIFT test_string.
|
||||||
|
|
||||||
|
test_string = copy.
|
||||||
|
|
||||||
|
DATA(test_xstr) = cl_abap_conv_codepage=>create_out( )->convert( test_string ).
|
||||||
|
|
||||||
|
SHIFT test_xstr IN BYTE MODE.
|
||||||
|
|
||||||
|
"-----------------------------------------------------------------------------
|
||||||
|
"------------------------------- SPLIT statements ----------------------------
|
||||||
|
"-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
test_string = `abc def`.
|
||||||
|
|
||||||
|
SPLIT test_string AT space INTO DATA(test_str1) DATA(test_str2) IN CHARACTER MODE.
|
||||||
|
SPLIT test_string AT space INTO TABLE DATA(tab_str) IN CHARACTER MODE.
|
||||||
|
|
||||||
|
"Same as above
|
||||||
|
SPLIT test_string AT space INTO test_str1 test_str2.
|
||||||
|
SPLIT test_string AT space INTO TABLE tab_str.
|
||||||
|
|
||||||
|
test_xstr = cl_abap_conv_codepage=>create_out( )->convert( test_string ).
|
||||||
|
|
||||||
|
blank_xstr = cl_abap_conv_codepage=>create_out( )->convert( ` ` ).
|
||||||
|
|
||||||
|
SPLIT test_xstr AT blank_xstr INTO DATA(xstr1) DATA(xstr2) IN BYTE MODE.
|
||||||
|
SPLIT test_xstr AT blank_xstr INTO TABLE DATA(xstr_tab) IN BYTE MODE.
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|||||||
@@ -1,44 +1,11 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>Structures</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: Structures
|
"! <p>The example class demonstrates various syntax options for working with structures.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Example to demonstrate various syntax options for working with
|
"! <h2>Note</h2>
|
||||||
* structures.
|
"! <p>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* - Topics covered: creating structures and structured types, variants
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
|
||||||
* of structures, accessing components of structures, filling structures,
|
|
||||||
* clearing structures, structures in use in the context of tables
|
|
||||||
*
|
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
|
||||||
* - 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
|
|
||||||
* 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)
|
|
||||||
* 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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: Structures</p>
|
|
||||||
"! Example to demonstrate working with structures.<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_structures DEFINITION
|
CLASS zcl_demo_abap_structures DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -146,11 +113,35 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
METHOD if_oo_adt_classrun~main.
|
METHOD if_oo_adt_classrun~main.
|
||||||
|
|
||||||
out->write( |ABAP Cheat Sheet Example: Structures\n\n| ).
|
out->write( |ABAP cheat sheet example: Structures\n\n| ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( |1) Creating structures and structured types\n| ).
|
out->write( |1) Globally available structures and structured types\n| ).
|
||||||
|
|
||||||
|
"Creating structures based on globally available structured types
|
||||||
|
"Database table
|
||||||
|
DATA struc_from_dbtab TYPE zdemo_abap_fli.
|
||||||
|
"CDS view entity
|
||||||
|
DATA struc_from_cds_ve TYPE zdemo_abap_fli.
|
||||||
|
"CDS abstract entity
|
||||||
|
DATA struc_from_cds_abs TYPE zdemo_abap_abstract_ent.
|
||||||
|
"CDS table function
|
||||||
|
DATA struc_from_cds_tab_func TYPE zdemo_abap_table_function.
|
||||||
|
|
||||||
|
"Globally available structured type in the public visibility section of
|
||||||
|
"classes/interfaces
|
||||||
|
DATA struc_from_struc_type_in_cl TYPE zcl_demo_abap_amdp=>fli_struc.
|
||||||
|
|
||||||
|
"Creating structured types based on globally available structured types
|
||||||
|
TYPES ty_struc_from_dbtab TYPE zdemo_abap_fli.
|
||||||
|
TYPES ty_struc_from_cds_ve TYPE zdemo_abap_fli.
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `2) Nested structure` ) ).
|
||||||
|
|
||||||
"The following declarations are just included for demonstration purposes
|
"The following declarations are just included for demonstration purposes
|
||||||
"to show how declarations of local structures and structured
|
"to show how declarations of local structures and structured
|
||||||
@@ -213,12 +204,12 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
"Declaring structure inline and populating it using the VALUE operator
|
"Declaring structure inline and populating it using the VALUE operator
|
||||||
DATA(struc_inl2) = VALUE lty_struc( num1 = 1 num2 = 2 ).
|
DATA(struc_inl2) = VALUE lty_struc( num1 = 1 num2 = 2 ).
|
||||||
|
|
||||||
out->write( `No output for this section. See the code.` ).
|
out->write( zcl_demo_abap_aux=>no_output ).
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `Variants of structures` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `Variants of structures` ) ).
|
||||||
out->write( |2) Flat structure with default values\n\n| ).
|
out->write( |3) Flat structure with default values\n\n| ).
|
||||||
|
|
||||||
"Flat structures only contain elementary data types
|
"Flat structures only contain elementary data types
|
||||||
|
|
||||||
@@ -235,7 +226,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `3) Nested structure` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `4) Nested structure` ) ).
|
||||||
|
|
||||||
"Nested structures contain at least one structure as component
|
"Nested structures contain at least one structure as component
|
||||||
|
|
||||||
@@ -260,7 +251,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `4) Deep structure with strings` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `5) Deep structure with strings` ) ).
|
||||||
|
|
||||||
"Deep structures contain at least one deep component, for
|
"Deep structures contain at least one deep component, for
|
||||||
"example, internal tables, strings.
|
"example, internal tables, strings.
|
||||||
@@ -276,7 +267,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `5) Deep structure with internal table as component` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `6) Deep structure with internal table as component` ) ).
|
||||||
|
|
||||||
"Structured type for nested internal table
|
"Structured type for nested internal table
|
||||||
TYPES: BEGIN OF lty_flights,
|
TYPES: BEGIN OF lty_flights,
|
||||||
@@ -308,7 +299,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `Accessing and populating structures` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `Accessing and populating structures` ) ).
|
||||||
out->write( |6) Populating structure components using the component selector\n\n| ).
|
out->write( |7) Populating structure components using the component selector\n\n| ).
|
||||||
|
|
||||||
gs_struc-num1 = 1.
|
gs_struc-num1 = 1.
|
||||||
gs_struc-num2 = 2.
|
gs_struc-num2 = 2.
|
||||||
@@ -320,7 +311,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `7) Populating structure components ` &&
|
out->write( zcl_demo_abap_aux=>heading( `8) Populating structure components ` &&
|
||||||
`using the VALUE operator` ) ).
|
`using the VALUE operator` ) ).
|
||||||
|
|
||||||
"Value assignments by addressing the structure components individually
|
"Value assignments by addressing the structure components individually
|
||||||
@@ -373,7 +364,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `8) Creating and populating a new structure ` &&
|
out->write( zcl_demo_abap_aux=>heading( `9) Creating and populating a new structure ` &&
|
||||||
`using the VALUE operator` ) ).
|
`using the VALUE operator` ) ).
|
||||||
|
|
||||||
"In the example below in which a new structure is created by declaring
|
"In the example below in which a new structure is created by declaring
|
||||||
@@ -391,7 +382,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `9) Accessing individual components using the ` &&
|
out->write( zcl_demo_abap_aux=>heading( `10) Accessing individual components using the ` &&
|
||||||
`component selector` ) ).
|
`component selector` ) ).
|
||||||
|
|
||||||
"Assigning value of individual component to a variable
|
"Assigning value of individual component to a variable
|
||||||
@@ -412,7 +403,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `10) Excursion: Addressing components of a variable` &&
|
out->write( zcl_demo_abap_aux=>heading( `11) Excursion: Addressing components of a variable` &&
|
||||||
` referring to a structure ` ) ).
|
` referring to a structure ` ) ).
|
||||||
|
|
||||||
"Creating a data reference variable.
|
"Creating a data reference variable.
|
||||||
@@ -433,7 +424,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `11) Using structure components for ` &&
|
out->write( zcl_demo_abap_aux=>heading( `12) Using structure components for ` &&
|
||||||
`data type and data object declarations` ) ).
|
`data type and data object declarations` ) ).
|
||||||
|
|
||||||
TYPES: lty_1 TYPE gty_struc-num1,
|
TYPES: lty_1 TYPE gty_struc-num1,
|
||||||
@@ -448,7 +439,39 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `12) Copying content of a structure to another ` &&
|
out->write( zcl_demo_abap_aux=>heading( `13) Creating and populating an anonymous structure ` &&
|
||||||
|
`using the NEW operator` ) ).
|
||||||
|
|
||||||
|
"In the example below in which a new structure is created by declaring
|
||||||
|
"a variable inline the '#' sign cannot be used before the parentheses
|
||||||
|
"because a type cannot be derived. Instead, the type must be
|
||||||
|
"specified before the parentheses explicitly.
|
||||||
|
|
||||||
|
"Creating a data reference variable
|
||||||
|
TYPES struc_type LIKE ls_flat_address.
|
||||||
|
DATA addr_ref1 TYPE REF TO struc_type.
|
||||||
|
|
||||||
|
"Populating the anonymous structure
|
||||||
|
addr_ref1 = NEW #( name = `Mr. Duncan Pea`
|
||||||
|
street = `Vegetable Lane 11`
|
||||||
|
city = `349875 Botanica` ).
|
||||||
|
|
||||||
|
addr_ref1->name = `Mrs. Jane Doe`.
|
||||||
|
|
||||||
|
"Declaring an anonymous structure/a data reference variable inline
|
||||||
|
DATA(addr_ref2) = NEW struc_type( name = `Mr. Duncan Pea`
|
||||||
|
street = `Vegetable Lane 11`
|
||||||
|
city = `349875 Botanica` ).
|
||||||
|
|
||||||
|
out->write( data = addr_ref2->* name = `addr_ref2->*` ).
|
||||||
|
|
||||||
|
addr_ref2->* = VALUE #( BASE addr_ref2->* name = `Mr. John Doe` ).
|
||||||
|
|
||||||
|
out->write( data = addr_ref2->* name = `addr_ref2->*` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `14) Copying content of a structure to another ` &&
|
||||||
` that has the same type using the assignment operator` ) ).
|
` that has the same type using the assignment operator` ) ).
|
||||||
|
|
||||||
"Note: In the case below, a MOVE-CORRESPONDING statement as shown
|
"Note: In the case below, a MOVE-CORRESPONDING statement as shown
|
||||||
@@ -463,7 +486,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `13) Copying content of a structure to another` &&
|
out->write( zcl_demo_abap_aux=>heading( `15) Copying content of a structure to another` &&
|
||||||
` that has an incompatible type using` &&
|
` that has an incompatible type using` &&
|
||||||
` MOVE-CORRESPONDING statemtns and the CORRESPONDING operator` ) ).
|
` MOVE-CORRESPONDING statemtns and the CORRESPONDING operator` ) ).
|
||||||
|
|
||||||
@@ -532,7 +555,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `14) Copying content of a deep ` &&
|
out->write( zcl_demo_abap_aux=>heading( `16) Copying content of a deep ` &&
|
||||||
`structure to another` ) ).
|
`structure to another` ) ).
|
||||||
out->write( |Original content of deep structures:\n\n| ).
|
out->write( |Original content of deep structures:\n\n| ).
|
||||||
|
|
||||||
@@ -545,7 +568,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `15) MOVE-CORRESPONDING without additions` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `17) MOVE-CORRESPONDING without additions` ) ).
|
||||||
|
|
||||||
"Notes on the result:
|
"Notes on the result:
|
||||||
"- Existing content of identically named components is replaced.
|
"- Existing content of identically named components is replaced.
|
||||||
@@ -569,7 +592,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `16) MOVE-CORRESPONDING with the ` &&
|
out->write( zcl_demo_abap_aux=>heading( `18) MOVE-CORRESPONDING with the ` &&
|
||||||
`EXPANDING NESTED TABLES addition` ) ).
|
`EXPANDING NESTED TABLES addition` ) ).
|
||||||
|
|
||||||
"Notes on the result:
|
"Notes on the result:
|
||||||
@@ -591,7 +614,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `17) MOVE-CORRESPONDING with the` &&
|
out->write( zcl_demo_abap_aux=>heading( `19) MOVE-CORRESPONDING with the` &&
|
||||||
` KEEPING TARGET LINES addition` ) ).
|
` KEEPING TARGET LINES addition` ) ).
|
||||||
|
|
||||||
"Notes on the result:
|
"Notes on the result:
|
||||||
@@ -615,7 +638,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `18) MOVE-CORRESPONDING with the ` &&
|
out->write( zcl_demo_abap_aux=>heading( `20) MOVE-CORRESPONDING with the ` &&
|
||||||
`EXPANDING NESTED TABLES KEEPING TARGET LINES addition` ) ).
|
`EXPANDING NESTED TABLES KEEPING TARGET LINES addition` ) ).
|
||||||
|
|
||||||
"Notes on the result:
|
"Notes on the result:
|
||||||
@@ -640,7 +663,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `19) CORRESPONDING operator without additions` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `21) CORRESPONDING operator without additions` ) ).
|
||||||
|
|
||||||
"Notes on the result:
|
"Notes on the result:
|
||||||
"- Existing content of identically named components is replaced.
|
"- Existing content of identically named components is replaced.
|
||||||
@@ -661,7 +684,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `20) CORRESPONDING operator with the` &&
|
out->write( zcl_demo_abap_aux=>heading( `22) CORRESPONDING operator with the` &&
|
||||||
` DEEP addition` ) ).
|
` DEEP addition` ) ).
|
||||||
|
|
||||||
"Notes on the result:
|
"Notes on the result:
|
||||||
@@ -683,7 +706,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `21) CORRESPONDING operator with the` &&
|
out->write( zcl_demo_abap_aux=>heading( `23) CORRESPONDING operator with the` &&
|
||||||
` BASE addition` ) ).
|
` BASE addition` ) ).
|
||||||
|
|
||||||
"Notes on the result:
|
"Notes on the result:
|
||||||
@@ -707,7 +730,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `22) CORRESPONDING operator with the ` &&
|
out->write( zcl_demo_abap_aux=>heading( `24) CORRESPONDING operator with the ` &&
|
||||||
`DEEP BASE addition` ) ).
|
`DEEP BASE addition` ) ).
|
||||||
|
|
||||||
"Notes on the result:
|
"Notes on the result:
|
||||||
@@ -730,7 +753,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `23) CORRESPONDING operator with the ` &&
|
out->write( zcl_demo_abap_aux=>heading( `25) CORRESPONDING operator with the ` &&
|
||||||
`APPENDING addition` ) ).
|
`APPENDING addition` ) ).
|
||||||
|
|
||||||
"Notes on the result:
|
"Notes on the result:
|
||||||
@@ -754,7 +777,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `24) CORRESPONDING operator with the ` &&
|
out->write( zcl_demo_abap_aux=>heading( `26) CORRESPONDING operator with the ` &&
|
||||||
`DEEP APPENDING addition` ) ).
|
`DEEP APPENDING addition` ) ).
|
||||||
|
|
||||||
"Notes on the result:
|
"Notes on the result:
|
||||||
@@ -777,7 +800,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `25) Clearing individual components of a ` &&
|
out->write( zcl_demo_abap_aux=>heading( `27) Clearing individual components of a ` &&
|
||||||
`structure and the complete structure` ) ).
|
`structure and the complete structure` ) ).
|
||||||
|
|
||||||
"Clearing individual component
|
"Clearing individual component
|
||||||
@@ -791,11 +814,23 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
out->write( data = gs_struc name = `gs_struc` ).
|
out->write( data = gs_struc name = `gs_struc` ).
|
||||||
|
|
||||||
|
"Note: An assignment using the VALUE operator without entries in the parentheses clears the structure.
|
||||||
|
ls_flat_address = VALUE #( name = `Mr. Duncan Pea` ).
|
||||||
|
ls_flat_address = VALUE #( ).
|
||||||
|
|
||||||
|
ASSERT ls_flat_address IS INITIAL.
|
||||||
|
|
||||||
|
"The same applies to data reference variables pointing to structures.
|
||||||
|
addr_ref2 = NEW struc_type( name = `Mr. Duncan Pea` ).
|
||||||
|
addr_ref2 = NEW #( ).
|
||||||
|
|
||||||
|
ASSERT addr_ref2->* IS INITIAL.
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `Processing structures` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `Processing structures` ) ).
|
||||||
out->write( |Reading a row from a database table into a structure ...\n\n| ).
|
out->write( |Reading a row from a database table into a structure ...\n\n| ).
|
||||||
out->write( |26) ... that has a compatible type\n\n| ).
|
out->write( |28) ... that has a compatible type\n\n| ).
|
||||||
|
|
||||||
"The first entry that is found according to the WHERE condition is
|
"The first entry that is found according to the WHERE condition is
|
||||||
"returned. Instead of creating a structure having a compatible type,
|
"returned. Instead of creating a structure having a compatible type,
|
||||||
@@ -819,7 +854,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `27) ... that has a different type` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `29) ... that has a different type` ) ).
|
||||||
|
|
||||||
"Creating structure having a different type.
|
"Creating structure having a different type.
|
||||||
DATA: BEGIN OF ls_fli_diff,
|
DATA: BEGIN OF ls_fli_diff,
|
||||||
@@ -842,7 +877,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `Reading a line from an internal table into a structure ...` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `Reading a line from an internal table into a structure ...` ) ).
|
||||||
out->write( |28) ... using a SELECT statement\n\n| ).
|
out->write( |30) ... using a SELECT statement\n\n| ).
|
||||||
|
|
||||||
"Creating and filling an internal table to be read from
|
"Creating and filling an internal table to be read from
|
||||||
DATA itab TYPE TABLE OF zdemo_abap_flsch WITH EMPTY KEY.
|
DATA itab TYPE TABLE OF zdemo_abap_flsch WITH EMPTY KEY.
|
||||||
@@ -862,7 +897,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `29) ... using a READ TABLE statement` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `31) ... using a READ TABLE statement` ) ).
|
||||||
|
|
||||||
"The example shows the reading of one line into a work area, field
|
"The example shows the reading of one line into a work area, field
|
||||||
"symbol and a data reference variable, all representing structured
|
"symbol and a data reference variable, all representing structured
|
||||||
@@ -886,7 +921,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `30) ... using a table expression` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `32) ... using a table expression` ) ).
|
||||||
"The line number, that is, the index, is specified in square
|
"The line number, that is, the index, is specified in square
|
||||||
"brackets.
|
"brackets.
|
||||||
|
|
||||||
@@ -897,7 +932,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `Sequentially reading ...` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `Sequentially reading ...` ) ).
|
||||||
out->write( |31) ... a row from a database table into a structure\n\n| ).
|
out->write( |33) ... a row from a database table into a structure\n\n| ).
|
||||||
|
|
||||||
"In the given simple example, the line that is found and returned
|
"In the given simple example, the line that is found and returned
|
||||||
"in a structure, that is declared inline, is simply added to an
|
"in a structure, that is declared inline, is simply added to an
|
||||||
@@ -916,7 +951,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `32) ... a line from an internal table into a structure` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `34) ... a line from an internal table into a structure` ) ).
|
||||||
|
|
||||||
"The given example covers the reading of a line into a field symbol.
|
"The given example covers the reading of a line into a field symbol.
|
||||||
"Within the loop, a modification is carried out on a component
|
"Within the loop, a modification is carried out on a component
|
||||||
@@ -930,7 +965,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `33) Inserting a single row ` &&
|
out->write( zcl_demo_abap_aux=>heading( `35) Inserting a single row ` &&
|
||||||
`into a database table from a structure` ) ).
|
`into a database table from a structure` ) ).
|
||||||
|
|
||||||
"The statements in the given example can be considered as
|
"The statements in the given example can be considered as
|
||||||
@@ -969,7 +1004,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `34) Updating a single row ` &&
|
out->write( zcl_demo_abap_aux=>heading( `36) Updating a single row ` &&
|
||||||
`in a database table from a structure` ) ).
|
`in a database table from a structure` ) ).
|
||||||
|
|
||||||
ls_struc_db = VALUE #( key_field = 2
|
ls_struc_db = VALUE #( key_field = 2
|
||||||
@@ -991,7 +1026,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `35) Updating a single row ` &&
|
out->write( zcl_demo_abap_aux=>heading( `37) Updating a single row ` &&
|
||||||
`in a database table from a structure without overwriting specific ` &&
|
`in a database table from a structure without overwriting specific ` &&
|
||||||
`components` ) ).
|
`components` ) ).
|
||||||
|
|
||||||
@@ -1014,7 +1049,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `36) Updating or creating a single` &&
|
out->write( zcl_demo_abap_aux=>heading( `38) Updating or creating a single` &&
|
||||||
` row in a database table from a structure using MODIFY` ) ).
|
` row in a database table from a structure using MODIFY` ) ).
|
||||||
|
|
||||||
"You can update or create an individual row in a database table
|
"You can update or create an individual row in a database table
|
||||||
@@ -1056,7 +1091,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `36) Adding rows to and updating single rows` &&
|
out->write( zcl_demo_abap_aux=>heading( `39) Adding rows to and updating single rows` &&
|
||||||
` in an internal table from a structure` ) ).
|
` in an internal table from a structure` ) ).
|
||||||
|
|
||||||
"INSERT and MODIFY are ABAP statements in this context, not ABAP SQL
|
"INSERT and MODIFY are ABAP statements in this context, not ABAP SQL
|
||||||
@@ -1111,7 +1146,7 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
out->write( zcl_demo_abap_aux=>heading( `37) Including structures` ) ).
|
out->write( zcl_demo_abap_aux=>heading( `40) Including structures` ) ).
|
||||||
|
|
||||||
"The example shows the inclusion of structured types and data
|
"The example shows the inclusion of structured types and data
|
||||||
"objects in another structure. First, three structured types as
|
"objects in another structure. First, three structured types as
|
||||||
@@ -1160,6 +1195,277 @@ CLASS zcl_demo_abap_structures IMPLEMENTATION.
|
|||||||
address-name_city = `Botanica`.
|
address-name_city = `Botanica`.
|
||||||
|
|
||||||
out->write( data = address name = `address` ).
|
out->write( data = address name = `address` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `41) Getting Structured Type Information and Creating Structures at Runtime` ) ).
|
||||||
|
|
||||||
|
TYPES: BEGIN OF demo_struc_type,
|
||||||
|
comp1 TYPE c LENGTH 3,
|
||||||
|
comp2 TYPE i,
|
||||||
|
comp3 TYPE string,
|
||||||
|
END OF demo_struc_type.
|
||||||
|
DATA demo_struc TYPE demo_struc_type.
|
||||||
|
|
||||||
|
DATA(tdo_c) = cl_abap_typedescr=>describe_by_data( demo_struc ).
|
||||||
|
"DATA(tdo_c) = cl_abap_typedescr=>describe_by_name( 'DEMO_STRUC_TYPE' ).
|
||||||
|
|
||||||
|
"Cast to get more specific information
|
||||||
|
DATA(tdo_struc) = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( demo_struc ) ).
|
||||||
|
"DATA(tdo_struc) = CAST cl_abap_structdescr( tdo_c ).
|
||||||
|
|
||||||
|
DATA(type_category_struc) = tdo_struc->kind.
|
||||||
|
DATA(relative_name_struc) = tdo_struc->get_relative_name( ).
|
||||||
|
... "Explore more options by positioning the cursor behind -> and choosing CTRL + Space
|
||||||
|
DATA(type_of_struc) = tdo_struc->struct_kind.
|
||||||
|
DATA(struc_comps) = tdo_struc->components.
|
||||||
|
DATA(struc_comps_more_details) = tdo_struc->get_components( ).
|
||||||
|
DATA(struc_has_include) = tdo_struc->has_include.
|
||||||
|
DATA(struc_incl_view) = tdo_struc->get_included_view( ).
|
||||||
|
DATA(applies_to_data_struc) = tdo_struc->applies_to_data( `some string` ).
|
||||||
|
|
||||||
|
"Example: "Looping" across a structure
|
||||||
|
"For example, this may also be done using a DO loop and dynamic assignments.
|
||||||
|
"Demo structure, all components are convertible to type string
|
||||||
|
TYPES: BEGIN OF ty_struc,
|
||||||
|
comp1 TYPE c LENGTH 3,
|
||||||
|
comp2 TYPE string,
|
||||||
|
comp3 TYPE i,
|
||||||
|
comp4 TYPE n LENGTH 4,
|
||||||
|
END OF ty_struc.
|
||||||
|
DATA(struct) = VALUE ty_struc( comp1 = 'abc' comp2 = `ABAP` comp3 = 123 comp4 = '9876' ).
|
||||||
|
DATA looped_struc TYPE string.
|
||||||
|
|
||||||
|
"In the loop, a string is populated, component by component.
|
||||||
|
LOOP AT CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( struct ) )->components INTO DATA(comp).
|
||||||
|
looped_struc = |{ looped_struc }{ COND #( WHEN sy-tabix <> 1 THEN ` / ` ) }Name: "{ CONV string( comp-name ) }", Value: "{ struct-(comp-name) }"|.
|
||||||
|
ENDLOOP.
|
||||||
|
|
||||||
|
out->write( data = looped_struc name = `looped_struc` ).
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
out->write( zcl_demo_abap_aux=>heading( `42) sy Structure` ) ).
|
||||||
|
|
||||||
|
"Demonstrating prominent sy components that can be used in ABAP for Cloud Development
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"------------------ sy-subrc: Return code of ABAP statements ------------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
"Many ABAP statements set a sy-subrc value. Check the ABAP Keyword Documentation
|
||||||
|
"for individual statements. Usually, the value 0 indicates a successful execution.
|
||||||
|
|
||||||
|
DATA(some_string) = `ABAP`.
|
||||||
|
|
||||||
|
"FIND statements
|
||||||
|
"Found
|
||||||
|
FIND `P` IN some_string.
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
|
||||||
|
"Not found
|
||||||
|
FIND `p` IN some_string RESPECTING CASE.
|
||||||
|
ASSERT sy-subrc = 4.
|
||||||
|
|
||||||
|
DATA(some_itab) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ( `d` ) ).
|
||||||
|
|
||||||
|
"READ TABLE statements
|
||||||
|
"Entry available
|
||||||
|
READ TABLE some_itab INTO DATA(wa1) INDEX 3.
|
||||||
|
ASSERT sy-subrc = 0.
|
||||||
|
|
||||||
|
"Entry not available
|
||||||
|
READ TABLE some_itab INTO DATA(wa2) INDEX 7.
|
||||||
|
ASSERT sy-subrc = 4.
|
||||||
|
|
||||||
|
"ABAP SQL statements
|
||||||
|
DELETE FROM zdemo_abap_tab1.
|
||||||
|
IF sy-subrc = 0.
|
||||||
|
out->write( `DELETE: All rows were deleted.` ).
|
||||||
|
ELSE.
|
||||||
|
out->write( `DELETE: No row was deleted because it was already empty.` ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 1 ) ( key_field = 2 ) ) ).
|
||||||
|
IF sy-subrc = 0.
|
||||||
|
out->write( `INSERT: All rows of the internal table were inserted.` ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 3 ) ( key_field = 3 ) ) ) ACCEPTING DUPLICATE KEYS.
|
||||||
|
IF sy-subrc = 4.
|
||||||
|
out->write( `INSERT ... ACCEPTING DUPLICATE KEYS: sy-subrc has the value 4 in this case. Not all rows of the ` &&
|
||||||
|
`internal table were inserted because a row with the key already exists.` ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
DELETE FROM zdemo_abap_tab1 WHERE key_field = 3.
|
||||||
|
IF sy-subrc = 0.
|
||||||
|
out->write( `DELETE: The row matching the WHERE condition was deleted.` ).
|
||||||
|
ELSE.
|
||||||
|
out->write( `DELETE: No match according to the WHERE condition.` ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
DELETE FROM zdemo_abap_tab1 WHERE key_field = 3.
|
||||||
|
IF sy-subrc = 0.
|
||||||
|
out->write( `DELETE: The row matching the WHERE condition was deleted.` ).
|
||||||
|
ELSE.
|
||||||
|
out->write( `DELETE: No match according to the WHERE condition.` ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"--------------------------- sy-index: Loop indexes ---------------------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
CLEAR some_string.
|
||||||
|
|
||||||
|
"DO loops
|
||||||
|
DO 5 TIMES.
|
||||||
|
some_string = some_string && sy-index.
|
||||||
|
ENDDO.
|
||||||
|
|
||||||
|
ASSERT some_string = `12345`.
|
||||||
|
|
||||||
|
CLEAR some_string.
|
||||||
|
|
||||||
|
DO 10 TIMES.
|
||||||
|
some_string = some_string && sy-index.
|
||||||
|
IF sy-index = 7.
|
||||||
|
EXIT.
|
||||||
|
ENDIF.
|
||||||
|
ENDDO.
|
||||||
|
|
||||||
|
ASSERT some_string = `1234567`.
|
||||||
|
|
||||||
|
CLEAR some_string.
|
||||||
|
|
||||||
|
DATA number TYPE i.
|
||||||
|
|
||||||
|
"WHILE loop
|
||||||
|
WHILE number < 9.
|
||||||
|
number = sy-index.
|
||||||
|
some_string = some_string && number.
|
||||||
|
ENDWHILE.
|
||||||
|
|
||||||
|
ASSERT some_string = `123456789`.
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"------------------- sy-tabix: Row index of internal tables -------------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
"Demo standard internal table with 5 entries
|
||||||
|
DATA(std_itab) = VALUE string_table( ( `a` ) ( `b` ) ( `c` ) ( `d` ) ( `e` ) ).
|
||||||
|
|
||||||
|
"READ TABLE statement using a free key
|
||||||
|
READ TABLE std_itab INTO DATA(wa3) WITH KEY table_line = `b`.
|
||||||
|
ASSERT sy-tabix = 2.
|
||||||
|
|
||||||
|
"Demo hashed internal table with 5 entries
|
||||||
|
DATA(hashed_itab) = VALUE string_hashed_table( ( `a` ) ( `b` ) ( `c` ) ( `d` ) ( `e` ) ).
|
||||||
|
|
||||||
|
"READ TABLE statement using a free key
|
||||||
|
READ TABLE hashed_itab INTO DATA(wa4) WITH KEY table_line = `b`.
|
||||||
|
"Hashed tables do not have a primary table index.
|
||||||
|
ASSERT sy-tabix = 0.
|
||||||
|
|
||||||
|
CLEAR some_string.
|
||||||
|
|
||||||
|
"LOOP statements
|
||||||
|
LOOP AT std_itab INTO DATA(wa5).
|
||||||
|
some_string = some_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT some_string = `12345`.
|
||||||
|
|
||||||
|
CLEAR some_string.
|
||||||
|
"Step addition
|
||||||
|
"In the example, the table is looped across backwards
|
||||||
|
"indicated by the negative value. The step size 1 indicates
|
||||||
|
"that each line is respected.
|
||||||
|
LOOP AT std_itab INTO DATA(wa6) STEP -1.
|
||||||
|
some_string = some_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT some_string = `54321`.
|
||||||
|
|
||||||
|
CLEAR some_string.
|
||||||
|
"Forward loop, step size = 2
|
||||||
|
LOOP AT std_itab INTO DATA(wa7) STEP 2.
|
||||||
|
some_string = some_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT some_string = `135`.
|
||||||
|
|
||||||
|
CLEAR some_string.
|
||||||
|
"FROM/TO additions
|
||||||
|
LOOP AT std_itab INTO DATA(wa8) FROM 2 TO 4.
|
||||||
|
some_string = some_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT some_string = `234`.
|
||||||
|
|
||||||
|
CLEAR some_string.
|
||||||
|
"STEP/FROM additions
|
||||||
|
LOOP AT std_itab INTO DATA(wa9) STEP 2 FROM 2.
|
||||||
|
some_string = some_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT some_string = `24`.
|
||||||
|
|
||||||
|
CLEAR some_string.
|
||||||
|
"Hashed table
|
||||||
|
LOOP AT hashed_itab INTO DATA(wa10).
|
||||||
|
some_string = some_string && sy-tabix.
|
||||||
|
ENDLOOP.
|
||||||
|
ASSERT some_string = `00000`.
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"------------------------ sy-dbcnt: Edited table rows -------------------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
DELETE FROM zdemo_abap_tab1.
|
||||||
|
DATA(dbcnt) = sy-dbcnt.
|
||||||
|
|
||||||
|
out->write( |Dbtab rows deleted: { dbcnt }| ).
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 1 ) ( key_field = 2 ) ) ).
|
||||||
|
ASSERT sy-dbcnt = 2.
|
||||||
|
|
||||||
|
INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 3 ) ( key_field = 3 ) ) ) ACCEPTING DUPLICATE KEYS.
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
MODIFY zdemo_abap_tab1 FROM @( VALUE #( key_field = 1 char1 = 'aaa' ) ).
|
||||||
|
ASSERT sy-dbcnt = 1.
|
||||||
|
|
||||||
|
UPDATE zdemo_abap_tab1 SET char2 = 'bbb'.
|
||||||
|
ASSERT sy-dbcnt = 3.
|
||||||
|
|
||||||
|
DELETE FROM zdemo_abap_tab1 WHERE num1 IS INITIAL.
|
||||||
|
ASSERT sy-dbcnt = 3.
|
||||||
|
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"------------- sy-fdpos: Occurrence in byte or character strings --------------
|
||||||
|
"------------------------------------------------------------------------------
|
||||||
|
"For example, relevant in comparison expressions such as CS (constains string).
|
||||||
|
"If the comparison is true, sy-fdpos contains the offset of the found value. If it
|
||||||
|
"is false, sy-fdpos contains the length of the searched string.
|
||||||
|
|
||||||
|
some_string = `###abap###`.
|
||||||
|
|
||||||
|
IF some_string CS `p`.
|
||||||
|
out->write( |The substring is found. Offset of first finding: { sy-fdpos }| ).
|
||||||
|
ELSE.
|
||||||
|
out->write( |The substring is not found. Length of searched string: { sy-fdpos }| ).
|
||||||
|
ASSERT sy-fdpos = strlen( some_string ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
IF some_string CS `#`.
|
||||||
|
out->write( |The substring is found. Offset of first finding: { sy-fdpos }| ).
|
||||||
|
ELSE.
|
||||||
|
out->write( |The substring is not found. Length of searched string: { sy-fdpos }| ).
|
||||||
|
ASSERT sy-fdpos = strlen( some_string ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
IF some_string CS `Y`.
|
||||||
|
out->write( |The substring is found. Offset of first finding: { sy-fdpos }| ).
|
||||||
|
ELSE.
|
||||||
|
out->write( |The substring is not found. Length of searched string: { sy-fdpos }| ).
|
||||||
|
ASSERT sy-fdpos = strlen( some_string ).
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,58 +1,24 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>ABAP Unit tests</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP Cheat Sheet: ABAP Unit Tests
|
"! <p>The example class demonstrates ABAP unit tests.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class. To run all unit tests of the class, choose Ctrl/Cmd + Shift + F10.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Example to demonstrate ABAP unit tests.
|
"! <h2>Running ABAP Unit tests</h2>
|
||||||
* - Topics covered: Test classes and test methods, special methods,
|
"! <ol><li>Open the class with the ABAP development tools for Eclipse (ADT).</li>
|
||||||
* implementing and injecting test doubles (constructor injection,
|
"! <li>Choose Ctrl/Cmd + Shift + F10 to launch all tests in the class.
|
||||||
* back door injection, test seams)
|
"! You can also right-click somewhere in the class and choose Run as -> ABAP Unit Test.
|
||||||
*
|
"! <li>The results of a test run are displayed in the ABAP Unit tab in ADT
|
||||||
* ----------------------- RUN ABAP UNIT TEST---------------------------
|
"! and can be evaluated. The Failure Trace section provides information
|
||||||
* - Open the class with the ABAP development tools for Eclipse (ADT).
|
"! on errors found.</li>
|
||||||
* - Choose Ctrl/Cmd + Shift + F10 to launch all tests in the class.
|
"! <li>If you are interested in test coverage, you can choose Ctrl/Cmd + Shift + F11,
|
||||||
* You can also right-click somewhere in the class and choose
|
"! or make a right-click, choose Run as -> ABAP Unit Test With..., select the Coverage
|
||||||
* Run as -> ABAP Unit Test.
|
"! checkbox and choose Execute. You can then check the results in the ABAP Coverage tab,
|
||||||
* - The results of a test run are displayed in the ABAP Unit tab in ADT
|
"! what code is tested and what not.</li>
|
||||||
* and can be evaluated. The Failure Trace section provides information
|
"! </ol>
|
||||||
* on errors found.
|
"!
|
||||||
* - If you are interested in test coverage, you can choose
|
"! <h2>Note</h2>
|
||||||
* Ctrl/Cmd + Shift + F11, or make a right-click, choose Run as ->
|
"! <p>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* ABAP Unit Test With..., select the Coverage checkbox and choose
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
|
||||||
* Execute. You can then check the results in the ABAP Coverage tab,
|
|
||||||
* what code is tested and what not.
|
|
||||||
*
|
|
||||||
* ----------------------- RUN CLASS -----------------------------
|
|
||||||
* - 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, check the notes
|
|
||||||
* included in the class as comments or refer to the respective topic
|
|
||||||
* in the ABAP Keyword Documentation.
|
|
||||||
* - Due to the amount of output in the console, the examples include
|
|
||||||
* numbers (e. g. 1) ..., 2) ..., 3) ...) for the individual example
|
|
||||||
* sections. Plus, the variable name is displayed in most cases. Hence,
|
|
||||||
* to easier and faster find the relevant output in the console, just
|
|
||||||
* search in the console for the number/variable name (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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: Unit tests</p>
|
|
||||||
"! Example to demonstrate ABAP unit tests.<br>Choose F9 in ADT to run the class.
|
|
||||||
"! To run all unit tests of the class, choose Ctrl/Cmd + Shift + F10.
|
|
||||||
CLASS zcl_demo_abap_unit_test DEFINITION
|
CLASS zcl_demo_abap_unit_test DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
CREATE PUBLIC.
|
CREATE PUBLIC.
|
||||||
|
|||||||
@@ -1,47 +1,11 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>Working with XML and JSON in ABAP</strong><br/>ABAP cheat sheet example class</p>
|
||||||
*
|
"!
|
||||||
* ABAP cheat sheet: Working with XML and JSON in ABAP
|
"! <p>The example class demonstrates working with XML and JSON in ABAP.<br/>
|
||||||
*
|
"! Choose F9 in ADT to run the class.</p>
|
||||||
* -------------------------- PURPOSE ----------------------------------
|
"!
|
||||||
* - Example that demonstrates working with XML and JSON in ABAP.
|
"! <h2>Note</h2>
|
||||||
* - The following topics are covered:*
|
"! <p>Find information on <strong>getting started with the example class</strong> and the
|
||||||
* - Processing XML using class libraries (iXML, sXML)
|
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
|
||||||
* - XML Transformations using XSLT and Simple Transformations
|
|
||||||
* - CALL TRANSFORMATION syntax
|
|
||||||
* - Dealing with JSON data, XCO classes for JSON
|
|
||||||
* - Excursions: Converting string <-> xstring, compressing and
|
|
||||||
* decompressing binary data
|
|
||||||
*
|
|
||||||
* ----------------------- GETTING STARTED -----------------------------
|
|
||||||
* - 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
|
|
||||||
* 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)
|
|
||||||
* 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
|
|
||||||
* errors or their consequences that may occur when using the the example
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">ABAP cheat sheet: Working with XML and JSON in ABAP</p>
|
|
||||||
"! Example that demonstrates working with XML and JSON in ABAP..<br>Choose F9 in ADT to run the class.
|
|
||||||
CLASS zcl_demo_abap_xml_json DEFINITION
|
CLASS zcl_demo_abap_xml_json DEFINITION
|
||||||
PUBLIC
|
PUBLIC
|
||||||
FINAL
|
FINAL
|
||||||
@@ -1582,4 +1546,4 @@ CLASS zcl_demo_abap_xml_json IMPLEMENTATION.
|
|||||||
attr_lowercase_str = to_lower( attr_string_a && attr_string_b ).
|
attr_lowercase_str = to_lower( attr_string_a && attr_string_b ).
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|||||||
120
src/zcx_demo_abap_error_a.clas.abap
Normal file
120
src/zcx_demo_abap_error_a.clas.abap
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
CLASS zcx_demo_abap_error_a DEFINITION
|
||||||
|
PUBLIC
|
||||||
|
INHERITING FROM cx_dynamic_check
|
||||||
|
FINAL
|
||||||
|
CREATE PUBLIC .
|
||||||
|
|
||||||
|
PUBLIC SECTION.
|
||||||
|
|
||||||
|
INTERFACES if_t100_message.
|
||||||
|
|
||||||
|
CONSTANTS message_class TYPE symsgid VALUE 'ZDEMO_ABAP_MESSAGES'.
|
||||||
|
|
||||||
|
CONSTANTS:
|
||||||
|
BEGIN OF zcx_demo_abap_error_a,
|
||||||
|
msgid TYPE symsgid VALUE message_class,
|
||||||
|
msgno TYPE symsgno VALUE '001',
|
||||||
|
attr1 TYPE scx_attrname VALUE '',
|
||||||
|
attr2 TYPE scx_attrname VALUE '',
|
||||||
|
attr3 TYPE scx_attrname VALUE '',
|
||||||
|
attr4 TYPE scx_attrname VALUE '',
|
||||||
|
END OF zcx_demo_abap_error_a.
|
||||||
|
|
||||||
|
CONSTANTS:
|
||||||
|
BEGIN OF error_002,
|
||||||
|
msgid TYPE symsgid VALUE message_class,
|
||||||
|
msgno TYPE symsgno VALUE '002',
|
||||||
|
attr1 TYPE scx_attrname VALUE '',
|
||||||
|
attr2 TYPE scx_attrname VALUE '',
|
||||||
|
attr3 TYPE scx_attrname VALUE '',
|
||||||
|
attr4 TYPE scx_attrname VALUE '',
|
||||||
|
END OF error_002.
|
||||||
|
|
||||||
|
CONSTANTS:
|
||||||
|
BEGIN OF error_003,
|
||||||
|
msgid TYPE symsgid VALUE message_class,
|
||||||
|
msgno TYPE symsgno VALUE '003',
|
||||||
|
attr1 TYPE scx_attrname VALUE 'P_003_A',
|
||||||
|
attr2 TYPE scx_attrname VALUE 'P_003_B',
|
||||||
|
attr3 TYPE scx_attrname VALUE '',
|
||||||
|
attr4 TYPE scx_attrname VALUE '',
|
||||||
|
END OF error_003.
|
||||||
|
|
||||||
|
CONSTANTS:
|
||||||
|
BEGIN OF error_004,
|
||||||
|
msgid TYPE symsgid VALUE message_class,
|
||||||
|
msgno TYPE symsgno VALUE '004',
|
||||||
|
attr1 TYPE scx_attrname VALUE 'P_004_A',
|
||||||
|
attr2 TYPE scx_attrname VALUE 'P_004_B',
|
||||||
|
attr3 TYPE scx_attrname VALUE 'P_004_C',
|
||||||
|
attr4 TYPE scx_attrname VALUE 'P_004_D',
|
||||||
|
END OF error_004.
|
||||||
|
|
||||||
|
CONSTANTS:
|
||||||
|
BEGIN OF error_005,
|
||||||
|
msgid TYPE symsgid VALUE message_class,
|
||||||
|
msgno TYPE symsgno VALUE '005',
|
||||||
|
attr1 TYPE scx_attrname VALUE 'P_005_A',
|
||||||
|
attr2 TYPE scx_attrname VALUE 'P_005_B',
|
||||||
|
attr3 TYPE scx_attrname VALUE 'P_005_C',
|
||||||
|
attr4 TYPE scx_attrname VALUE 'P_005_D',
|
||||||
|
END OF error_005.
|
||||||
|
|
||||||
|
DATA p_003_a TYPE string.
|
||||||
|
DATA p_003_b TYPE string.
|
||||||
|
DATA p_004_a TYPE string.
|
||||||
|
DATA p_004_b TYPE string.
|
||||||
|
DATA p_004_c TYPE string.
|
||||||
|
DATA p_004_d TYPE string.
|
||||||
|
DATA p_005_a TYPE string.
|
||||||
|
DATA p_005_b TYPE string.
|
||||||
|
DATA p_005_c TYPE string.
|
||||||
|
DATA p_005_d TYPE string.
|
||||||
|
|
||||||
|
METHODS constructor
|
||||||
|
IMPORTING
|
||||||
|
textid LIKE if_t100_message=>t100key OPTIONAL
|
||||||
|
previous LIKE previous OPTIONAL
|
||||||
|
p_003_a TYPE string OPTIONAL
|
||||||
|
p_003_b TYPE string OPTIONAL
|
||||||
|
p_004_a TYPE string OPTIONAL
|
||||||
|
p_004_b TYPE string OPTIONAL
|
||||||
|
p_004_c TYPE string OPTIONAL
|
||||||
|
p_004_d TYPE string OPTIONAL
|
||||||
|
p_005_a TYPE string OPTIONAL
|
||||||
|
p_005_b TYPE string OPTIONAL
|
||||||
|
p_005_c TYPE string OPTIONAL
|
||||||
|
p_005_d TYPE string OPTIONAL
|
||||||
|
.
|
||||||
|
PROTECTED SECTION.
|
||||||
|
PRIVATE SECTION.
|
||||||
|
ENDCLASS.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CLASS zcx_demo_abap_error_a IMPLEMENTATION.
|
||||||
|
|
||||||
|
|
||||||
|
METHOD constructor ##ADT_SUPPRESS_GENERATION.
|
||||||
|
|
||||||
|
super->constructor( previous = previous ).
|
||||||
|
|
||||||
|
me->p_003_a = p_003_a.
|
||||||
|
me->p_003_b = p_003_b.
|
||||||
|
me->p_004_a = p_004_a.
|
||||||
|
me->p_004_b = p_004_b.
|
||||||
|
me->p_004_c = p_004_c.
|
||||||
|
me->p_004_d = p_004_d.
|
||||||
|
me->p_005_a = p_005_a.
|
||||||
|
me->p_005_b = p_005_b.
|
||||||
|
me->p_005_c = p_005_c.
|
||||||
|
me->p_005_d = p_005_d.
|
||||||
|
|
||||||
|
CLEAR me->textid.
|
||||||
|
IF textid IS INITIAL.
|
||||||
|
if_t100_message~t100key = if_t100_message=>default_textid.
|
||||||
|
ELSE.
|
||||||
|
if_t100_message~t100key = textid.
|
||||||
|
ENDIF.
|
||||||
|
ENDMETHOD.
|
||||||
|
ENDCLASS.
|
||||||
17
src/zcx_demo_abap_error_a.clas.xml
Normal file
17
src/zcx_demo_abap_error_a.clas.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||||
|
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||||
|
<asx:values>
|
||||||
|
<VSEOCLASS>
|
||||||
|
<CLSNAME>ZCX_DEMO_ABAP_ERROR_A</CLSNAME>
|
||||||
|
<LANGU>E</LANGU>
|
||||||
|
<DESCRIPT>ABAP cheat sheet exception class</DESCRIPT>
|
||||||
|
<CATEGORY>40</CATEGORY>
|
||||||
|
<STATE>1</STATE>
|
||||||
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
|
<FIXPT>X</FIXPT>
|
||||||
|
<UNICODE>X</UNICODE>
|
||||||
|
</VSEOCLASS>
|
||||||
|
</asx:values>
|
||||||
|
</asx:abap>
|
||||||
|
</abapGit>
|
||||||
33
src/zcx_demo_abap_error_b.clas.abap
Normal file
33
src/zcx_demo_abap_error_b.clas.abap
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
CLASS zcx_demo_abap_error_b DEFINITION
|
||||||
|
PUBLIC
|
||||||
|
INHERITING FROM cx_static_check
|
||||||
|
FINAL
|
||||||
|
CREATE PUBLIC .
|
||||||
|
|
||||||
|
PUBLIC SECTION.
|
||||||
|
|
||||||
|
INTERFACES if_t100_message.
|
||||||
|
INTERFACES if_t100_dyn_msg.
|
||||||
|
|
||||||
|
METHODS constructor
|
||||||
|
IMPORTING
|
||||||
|
textid LIKE if_t100_message=>t100key OPTIONAL
|
||||||
|
previous LIKE previous OPTIONAL.
|
||||||
|
PROTECTED SECTION.
|
||||||
|
PRIVATE SECTION.
|
||||||
|
ENDCLASS.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CLASS zcx_demo_abap_error_b IMPLEMENTATION.
|
||||||
|
METHOD constructor ##ADT_SUPPRESS_GENERATION.
|
||||||
|
super->constructor( previous = previous ).
|
||||||
|
|
||||||
|
CLEAR me->textid.
|
||||||
|
IF textid IS INITIAL.
|
||||||
|
if_t100_message~t100key = if_t100_message=>default_textid.
|
||||||
|
ELSE.
|
||||||
|
if_t100_message~t100key = textid.
|
||||||
|
ENDIF.
|
||||||
|
ENDMETHOD.
|
||||||
|
ENDCLASS.
|
||||||
17
src/zcx_demo_abap_error_b.clas.xml
Normal file
17
src/zcx_demo_abap_error_b.clas.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||||
|
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||||
|
<asx:values>
|
||||||
|
<VSEOCLASS>
|
||||||
|
<CLSNAME>ZCX_DEMO_ABAP_ERROR_B</CLSNAME>
|
||||||
|
<LANGU>E</LANGU>
|
||||||
|
<DESCRIPT>ABAP cheat sheet exception class</DESCRIPT>
|
||||||
|
<CATEGORY>40</CATEGORY>
|
||||||
|
<STATE>1</STATE>
|
||||||
|
<CLSCCINCL>X</CLSCCINCL>
|
||||||
|
<FIXPT>X</FIXPT>
|
||||||
|
<UNICODE>X</UNICODE>
|
||||||
|
</VSEOCLASS>
|
||||||
|
</asx:values>
|
||||||
|
</asx:abap>
|
||||||
|
</abapGit>
|
||||||
@@ -1,23 +1,8 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>Interface supporting the ABAP Unit Tests example class </strong>
|
||||||
* ---------------------------- PURPOSE --------------------------------
|
"! <br/>ABAP cheat sheet example interface</p>
|
||||||
* Interface to support the ABAP cheat sheet: ABAP Unit Tests
|
"!
|
||||||
*
|
"! <h2>Note</h2>
|
||||||
* ----------------------------- NOTE ----------------------------------
|
"! <p>Find the <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
|
||||||
* The code presented in this class is only meant for supporting 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 and not to
|
|
||||||
* solve concrete programming tasks. For production application programs,
|
|
||||||
* a dedicated solution should therefore always be worked out for each
|
|
||||||
* individual case. There is no guarantee for either the correctness or
|
|
||||||
* the completeness of the code. In addition, there is no legal
|
|
||||||
* responsibility or liability for possible errors or their consequences
|
|
||||||
* which occur through the use of the example code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">Interface for ABAP cheat sheet example</p>
|
|
||||||
"! The interface supports the ABAP cheat sheet: ABAP Unit Tests.
|
|
||||||
INTERFACE zdemo_abap_get_data_itf
|
INTERFACE zdemo_abap_get_data_itf
|
||||||
PUBLIC.
|
PUBLIC.
|
||||||
|
|
||||||
|
|||||||
44
src/zdemo_abap_messages.msag.xml
Normal file
44
src/zdemo_abap_messages.msag.xml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<abapGit version="v1.0.0" serializer="LCL_OBJECT_MSAG" serializer_version="v1.0.0">
|
||||||
|
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||||
|
<asx:values>
|
||||||
|
<T100A>
|
||||||
|
<ARBGB>ZDEMO_ABAP_MESSAGES</ARBGB>
|
||||||
|
<MASTERLANG>E</MASTERLANG>
|
||||||
|
<STEXT>ABAP cheat sheet message class</STEXT>
|
||||||
|
</T100A>
|
||||||
|
<T100>
|
||||||
|
<T100>
|
||||||
|
<SPRSL>E</SPRSL>
|
||||||
|
<ARBGB>ZDEMO_ABAP_MESSAGES</ARBGB>
|
||||||
|
<MSGNR>001</MSGNR>
|
||||||
|
<TEXT>An error occured (Nr. 001)</TEXT>
|
||||||
|
</T100>
|
||||||
|
<T100>
|
||||||
|
<SPRSL>E</SPRSL>
|
||||||
|
<ARBGB>ZDEMO_ABAP_MESSAGES</ARBGB>
|
||||||
|
<MSGNR>002</MSGNR>
|
||||||
|
<TEXT>Exception raised (Nr. 002)</TEXT>
|
||||||
|
</T100>
|
||||||
|
<T100>
|
||||||
|
<SPRSL>E</SPRSL>
|
||||||
|
<ARBGB>ZDEMO_ABAP_MESSAGES</ARBGB>
|
||||||
|
<MSGNR>003</MSGNR>
|
||||||
|
<TEXT>Test message (Nr. 003) &1 &2</TEXT>
|
||||||
|
</T100>
|
||||||
|
<T100>
|
||||||
|
<SPRSL>E</SPRSL>
|
||||||
|
<ARBGB>ZDEMO_ABAP_MESSAGES</ARBGB>
|
||||||
|
<MSGNR>004</MSGNR>
|
||||||
|
<TEXT>Message (Nr. 004) p1: "&1" p2: "&2" p3: "&3" p4: "&4"</TEXT>
|
||||||
|
</T100>
|
||||||
|
<T100>
|
||||||
|
<SPRSL>E</SPRSL>
|
||||||
|
<ARBGB>ZDEMO_ABAP_MESSAGES</ARBGB>
|
||||||
|
<MSGNR>005</MSGNR>
|
||||||
|
<TEXT>&1 &2 &3 &4</TEXT>
|
||||||
|
</T100>
|
||||||
|
</T100>
|
||||||
|
</asx:values>
|
||||||
|
</asx:abap>
|
||||||
|
</abapGit>
|
||||||
@@ -1,31 +1,16 @@
|
|||||||
***********************************************************************
|
"! <p class="shorttext"><strong>Interface supporting the ABAP object orientation example class</strong>
|
||||||
* ---------------------------- PURPOSE --------------------------------
|
"! <br/>ABAP cheat sheet example interface</p>
|
||||||
* Interface to support the ABAP cheat sheet ABAP object orientation.
|
"!
|
||||||
*
|
"! <h2>Note</h2>
|
||||||
* ----------------------------- NOTE ----------------------------------
|
"! <p>Find the <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</p>
|
||||||
* The code presented in this class is only meant for supporting 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 and not to
|
|
||||||
* solve concrete programming tasks. For production application programs,
|
|
||||||
* a dedicated solution should therefore always be worked out for each
|
|
||||||
* individual case. There is no guarantee for either the correctness or
|
|
||||||
* the completeness of the code. In addition, there is no legal
|
|
||||||
* responsibility or liability for possible errors or their consequences
|
|
||||||
* which occur through the use of the example code.
|
|
||||||
*
|
|
||||||
***********************************************************************
|
|
||||||
"! <p class="shorttext synchronized">Interface for ABAP cheat sheet example</p>
|
|
||||||
"! The interface supporta the ABAP cheat sheet on object orientation and demonstrates the use of interfaces.
|
|
||||||
INTERFACE zdemo_abap_objects_interface
|
INTERFACE zdemo_abap_objects_interface
|
||||||
PUBLIC.
|
PUBLIC.
|
||||||
|
|
||||||
METHODS: double IMPORTING i_op TYPE i
|
METHODS: double IMPORTING i_op TYPE i
|
||||||
RETURNING VALUE(r_double) TYPE i,
|
RETURNING VALUE(r_double) TYPE i,
|
||||||
|
|
||||||
triple DEFAULT IGNORE IMPORTING i_op TYPE i
|
triple DEFAULT IGNORE IMPORTING i_op TYPE i
|
||||||
RETURNING VALUE(r_triple) TYPE i .
|
RETURNING VALUE(r_triple) TYPE i .
|
||||||
|
|
||||||
DATA in_str TYPE string.
|
DATA in_str TYPE string.
|
||||||
|
|
||||||
@@ -36,4 +21,15 @@ INTERFACE zdemo_abap_objects_interface
|
|||||||
|
|
||||||
CONSTANTS const_intf TYPE i VALUE 987.
|
CONSTANTS const_intf TYPE i VALUE 987.
|
||||||
|
|
||||||
|
TYPES c3 TYPE c LENGTH 3.
|
||||||
|
DATA add_result TYPE i.
|
||||||
|
CLASS-DATA: subtr_result TYPE i.
|
||||||
|
METHODS addition IMPORTING num1 TYPE i
|
||||||
|
num2 TYPE i.
|
||||||
|
CLASS-METHODS subtraction IMPORTING num1 TYPE i
|
||||||
|
num2 TYPE i.
|
||||||
|
|
||||||
|
METHODS meth_ignore DEFAULT IGNORE RETURNING VALUE(int) TYPE i.
|
||||||
|
METHODS meth_fail DEFAULT FAIL RETURNING VALUE(int) TYPE i.
|
||||||
|
|
||||||
ENDINTERFACE.
|
ENDINTERFACE.
|
||||||
|
|||||||
Reference in New Issue
Block a user