Update
This commit is contained in:
@@ -656,7 +656,7 @@ DATA(it_d) = VALUE string_table( ( `aaa` )
|
||||
( `bbb` ) ).
|
||||
|
||||
"Not providing any table lines means the table is initial
|
||||
"and has the same effect as the declaration of it46.
|
||||
"and has the same effect as the declaration of it_f.
|
||||
DATA(it_e) = VALUE string_table( ).
|
||||
DATA it_f TYPE string_table.
|
||||
|
||||
|
||||
277
02_Structures.md
277
02_Structures.md
@@ -23,6 +23,7 @@
|
||||
- [Structures in Statements for Processing Internal Tables](#structures-in-statements-for-processing-internal-tables)
|
||||
- [Including Structures](#including-structures)
|
||||
- [Getting Structured Type Information and Creating Structures at Runtime](#getting-structured-type-information-and-creating-structures-at-runtime)
|
||||
- [sy Structure](#sy-structure)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
## Introduction
|
||||
@@ -1005,6 +1006,282 @@ ENDLOOP.
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
|
||||
## sy Structure
|
||||
|
||||
- The `sy` (or `syst`) structure is a built-in data object.
|
||||
- The components of the structure represent ABAP system fields.
|
||||
- These fields, filled by the [ABAP runtime framework](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_runtime_frmwk_glosry.htm), can be used to query system information and more.
|
||||
- Typically, they should only be read, and not overwritten.
|
||||
- Prominent system fields are the following
|
||||
- `sy-subrc`: Return code of many ABAP statements; typically, the value 0 indicates success
|
||||
- `sy-tabix`: Row index of internal tables
|
||||
- `sy-index`: Loop pass index
|
||||
- These ones and others can be used in [ABAP for Cloud Development](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_for_cloud_dev_glosry.htm). However, most of the fields should not be used in ABAP for Cloud Development (indicated by a syntax warning) because they refer to [Standard ABAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstandard_abap_glosry.htm) contexts (e.g. classic dynpros and lists), or their values are not relevant in a cloud context.
|
||||
- More information about the purpose of the individual components is available at [ABAP System Fields (F1 documentation for Standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensystem_fields.htm).
|
||||
|
||||
|
||||
The following example demonstrates a selection of ABAP system fields. It uses artifacts from the ABAP cheat sheet repository. Note the comments in the code because a syntax warning will be displayed when inserting the code in a demo class. It is meant to emphasize that multiple system fields should not to be used in ABAP for Cloud Development.
|
||||
To try the example out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console.
|
||||
|
||||
```abap
|
||||
CLASS zcl_some_class DEFINITION
|
||||
PUBLIC
|
||||
FINAL
|
||||
CREATE PUBLIC .
|
||||
|
||||
PUBLIC SECTION.
|
||||
INTERFACES if_oo_adt_classrun.
|
||||
PROTECTED SECTION.
|
||||
PRIVATE SECTION.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
CLASS zcl_some_class IMPLEMENTATION.
|
||||
METHOD if_oo_adt_classrun~main.
|
||||
|
||||
"In ABAP for Cloud Development, the following statement will show a syntax warning saying that
|
||||
"sy should not be used. Here, it is used for demonstration purposes.
|
||||
"In the example, RTTI is used to get all component names of the built-in data object sy. In the loop,
|
||||
"ABAP statements are created (they represent simple assignments using the various sy components) and
|
||||
"output to the console. You can insert all the output DATA(...) = ... statements in the demo class's
|
||||
"main method implementation. The purpose is to demonstrate that most of the sy components should not be
|
||||
"used in ABAP for Cloud Development. Most of the statements will show a syntax warning in ABAP for Cloud
|
||||
"Development. Check the ABAP Keyword Documentation (for Standard ABAP) and the F2 information for the
|
||||
"purpose of the individual sy components.
|
||||
LOOP AT CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_data( sy ) )->components INTO DATA(co).
|
||||
DATA(sycomp) = to_lower( co-name ).
|
||||
DATA(code) = |DATA(sy{ sycomp }) = sy-{ sycomp }.|.
|
||||
out->write( code ).
|
||||
ENDLOOP.
|
||||
out->write( |\n| ).
|
||||
out->write( |\n| ).
|
||||
|
||||
"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.
|
||||
ENDCLASS.
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
|
||||
## Executable Example
|
||||
[zcl_demo_abap_structures](./src/zcl_demo_abap_structures.clas.abap)
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ SELECT FROM source "What data source read from
|
||||
- However, in certain cases, older syntax variants are still valid and usable. An example is the `SELECT` list, that can also be specified using the more modern `FIELDS` addition.
|
||||
- As mentioned, choose `F1` for the keywords and additions to get all the details in the ABAP Keyword Documentation.
|
||||
- Further information in the context of Standard ABAP: [Release-Dependent Syntax Check Modes (F1 docu for standard ABAP)](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_sql_strict_modes.htm).
|
||||
- To mentioned some examples of modern ABAP SQL statements.
|
||||
- To mention some examples of modern ABAP SQL statements.
|
||||
- The `INTO` clause should be placed after the other clauses.
|
||||
- [Host variables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhost_variable_glosry.htm "Glossary Entry") or [host expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenhost_expression_glosry.htm "Glossary Entry") are required for data objects and expressions, i. e. they must be preceded by `@` or `@( ... )`. Host variables represent data objects that are declared in ABAP programs. They are specified in an [operand position](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenoperand_position_glosry.htm) of an ABAP SQL statement. Also see the [SQL Operands](#sql-operands) section.
|
||||
- The `SELECT` list, i. e. the fields that are specified, can also be specified following the `SELECT` keyword before the `FROM` clause - without `FIELDS`. The following two `SELECT` statements are basically the same but differently arranged. The code snippets in the cheat sheet randomly use one syntax or the other.
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
- [ABAP Object Orientation](#abap-object-orientation)
|
||||
- [Classes and Objects](#classes-and-objects)
|
||||
- [Creating Classes](#creating-classes)
|
||||
- [Creating a Local Class](#creating-a-local-class)
|
||||
- [Creating a Global Class](#creating-a-global-class)
|
||||
- [Creating a Local Class](#creating-a-local-class)
|
||||
- [Excursion: Class Pool and Include Programs](#excursion-class-pool-and-include-programs)
|
||||
- [Visibility of Components](#visibility-of-components)
|
||||
- [Creating the Visibility Sections](#creating-the-visibility-sections)
|
||||
@@ -15,7 +15,8 @@
|
||||
- [Methods](#methods)
|
||||
- [Parameter Interface](#parameter-interface)
|
||||
- [Formal and Actual Parameters](#formal-and-actual-parameters)
|
||||
- [Defingin Parameters as Optional](#defingin-parameters-as-optional)
|
||||
- [Defining Parameters as Optional](#defining-parameters-as-optional)
|
||||
- [Defining Input Parameters as Preferred](#defining-input-parameters-as-preferred)
|
||||
- [Constructors](#constructors)
|
||||
- [Example for Method Definitions](#example-for-method-definitions)
|
||||
- [Working with Objects and Components](#working-with-objects-and-components)
|
||||
@@ -43,6 +44,7 @@
|
||||
- [Friendship between Global and Local Classes](#friendship-between-global-and-local-classes)
|
||||
- [Events](#events)
|
||||
- [Examples for Design Patterns: Factory Methods and Singletons](#examples-for-design-patterns-factory-methods-and-singletons)
|
||||
- [Class-Based Exceptions](#class-based-exceptions)
|
||||
- [More Information](#more-information)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
@@ -119,26 +121,6 @@ Basic structure of classes:
|
||||
- [Implementation part](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenimplementation_part_glosry.htm "Glossary Entry") that includes method implementations.
|
||||
- Both are introduced by `CLASS` and ended by `ENDCLASS`.
|
||||
|
||||
#### Creating a Local Class
|
||||
|
||||
``` abap
|
||||
"Declaration part
|
||||
CLASS local_class DEFINITION.
|
||||
|
||||
... "Here go the declarations for all components and visibility sections.
|
||||
"You should place the declarations at the beginning of the program.
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
"Implementation part
|
||||
CLASS local_class IMPLEMENTATION.
|
||||
|
||||
... "Here go the method implementations.
|
||||
"Only required if you declare methods in the declaration part.
|
||||
|
||||
ENDCLASS.
|
||||
```
|
||||
|
||||
#### Creating a Global Class
|
||||
The code snippet shows a basic skeleton of a global class. There are [further
|
||||
additions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapclass_options.htm)
|
||||
@@ -177,6 +159,37 @@ ENDCLASS.
|
||||
> - `... DEFINITION DEFERRED.`: Making a local class known in a program before the actual class definition. It is typically used in test classes of ABAP Unit. Find more information [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapclass_deferred.htm).
|
||||
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
#### Creating a Local Class
|
||||
|
||||
- You can create local classes, for example, in the [CCIMP include](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenccimp_glosry.htm) (*Local Types* tab in ADT) of a [class pool](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclass_pool_glosry.htm).
|
||||
- Local classes are used in their own ABAP program. While dynamic access beyond program boundaries is possible, it is not recommended.
|
||||
- The cheat sheet's focus is on global classes. Local classes are also mentioned in the [friendship](#friendship) section.
|
||||
|
||||
The following snippet shows the skeleton of local class declaration.
|
||||
- It does not specify any class options after `DEFINITION`.
|
||||
- The `PUBLIC` addition makes a class a global class in the class library. Not possible in the context of local classes.
|
||||
- It does not specify `CREATE ...`. Note that `CREATE PUBLIC` is the default, which means that not specifying any `CREATE ...` addition makes the class implicitly specified with `CREATE PUBLIC`.
|
||||
|
||||
``` abap
|
||||
"Declaration part
|
||||
CLASS local_class DEFINITION.
|
||||
|
||||
... "Here go the declarations for all components and visibility sections.
|
||||
"You should place the declarations at the beginning of the program.
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
"Implementation part
|
||||
CLASS local_class IMPLEMENTATION.
|
||||
|
||||
... "Here go the method implementations.
|
||||
"Only required if you declare methods in the declaration part.
|
||||
|
||||
ENDCLASS.
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
#### Excursion: Class Pool and Include Programs
|
||||
@@ -522,7 +535,7 @@ In the simplest form, methods can have no parameter at all. Apart from that, met
|
||||
|`EXPORTING`|Defines one or more output parameters to be exported by the method. |
|
||||
|`CHANGING`|Defines one or more input or output parameters, i. e. that can be both imported and exported. |
|
||||
|`RETURNING`|For [functional methods](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfunctional_method_glosry.htm "Glossary Entry"), i. e. such methods have only one `RETURNING` parameter that can be defined. As an output parameter like the `EXPORTING` parameter, `RETURNING` parameters pass back values (note that the formal parameters of returning parameters must be passed by value as covered below; the parameter must be [completely typed](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencomplete_typing_glosry.htm)). In contrast to `EXPORTING` for which multiple parameters can be specified, only one `RETURNING` parameter can be specified in a method. If you only need one output parameter, you can benefit from using a `RETURNING` parameter by shortening the method call and enabling method chaining. Another big plus is that such functional methods can, for example, be used in expressions. In case of standalone method calls, the returned value can be accessed using the addition `RECEIVING`. |
|
||||
|`RAISING` | Used to declare the [class-based exceptions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclass_based_exception_glosry.htm "Glossary Entry") that can be propagated from the method to the caller. |
|
||||
|`RAISING` | Used to declare the [class-based exceptions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclass_based_exception_glosry.htm "Glossary Entry") that can be propagated from the method to the caller. It can also be specified with the addition `RESUMABLE` for [resumable exceptions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenresumable_exception_glosry.htm). Find more information in the [Exceptions and Runtime Errors](27_Exceptions.md) cheat sheet. |
|
||||
|
||||
|
||||
> **💡 Note**<br>
|
||||
@@ -532,8 +545,6 @@ In the simplest form, methods can have no parameter at all. Apart from that, met
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
#### Formal and Actual Parameters
|
||||
- [Formal parameter](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenformal_parameter_glosry.htm "Glossary Entry")
|
||||
versus [actual parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenactual_parameter_glosry.htm "Glossary Entry"):
|
||||
|
||||
- [Formal parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenformal_parameter_glosry.htm "Glossary Entry"): You define method parameters by specifying a name with a type which can be a [generic](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abengeneric_data_type_glosry.htm "Glossary Entry") or [complete](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencomplete_data_type_glosry.htm "Glossary Entry")
|
||||
type.
|
||||
@@ -544,15 +555,15 @@ In the simplest form, methods can have no parameter at all. Apart from that, met
|
||||
- This formal parameter includes the specification of how the value passing should happen. Parameters can be passed by ...
|
||||
- [reference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpass_by_reference_glosry.htm "Glossary Entry"): `... REFERENCE(param) ...`; note that just specifying the parameter name `... param ...` - as a shorter syntax - means passing by reference by default)
|
||||
- [value](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenpass_by_value_glosry.htm "Glossary Entry"): `... VALUE(param) ...`
|
||||
- The [actual parameters](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenactual_parameter_glosry.htm "Glossary Entry") represents the data object whose content is passed to or copied from a formal parameter as an argument when a procedure is called.
|
||||
- An [Actual parameter](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenactual_parameter_glosry.htm "Glossary Entry") represents the data object whose content is passed to or copied from a formal parameter as an argument when a procedure is called.
|
||||
- If passing by reference is used, a local data object is not created for the actual parameter. Instead, the procedure is given a [reference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreference_glosry.htm "Glossary Entry") to the actual parameter during the call and works with the actual parameter itself.
|
||||
- Note that parameters that are input and passed by reference cannot be modified in the procedure. However, the use of a reference is beneficial regarding the performance compared to creating a local data object.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
#### Defingin Parameters as Optional
|
||||
#### Defining Parameters as Optional
|
||||
|
||||
- Parameters can be defined as optional using the `OPTIONAL` and `DEFAULT` additions:
|
||||
- Parameters specified after `IMPORTING` and `CHANGING` can be defined as optional using the `OPTIONAL` and `DEFAULT` additions:
|
||||
- [`OPTIONAL`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmethods_parameters.htm#!ABAP_ONE_ADD@1@): It is then not mandatory to pass an actual
|
||||
parameter.
|
||||
- [`DEFAULT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapmethods_parameters.htm#!ABAP_ONE_ADD@1@): Also makes the passing of an actual parameter optional. However, when using this addition, as the name implies, a default value is set.
|
||||
@@ -560,6 +571,92 @@ In the simplest form, methods can have no parameter at all. Apart from that, met
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
#### Defining Input Parameters as Preferred
|
||||
|
||||
- Using the `PREFERRED PARAMETER` addition, you can flag an input parameter from the list as preferred.
|
||||
- All parameters must be optional (i.e. specified with `OPTIONAL` or `DEFAULT`).
|
||||
- The preferred parameter is implicitly optional, but you should explicitly specify it as `OPTIONAL` or `DEFAULT`, or a warning will be displayed.
|
||||
- When you call a method and specify a single actual parameter without specifying the name of the formal parameter in an assignment, the actual parameter is automatically assigned to the preferred parameter.
|
||||
|
||||
The following example shows a simple method with input parameters of type `i` (an addition is performed using the actual parameter values), where one parameter is preferred. The `IS SUPPLIED` addition in `COND` statements checks whether parameters are supplied. The final output shows the preferred parameter assigned automatically when the formal parameter is not specified explicitly.
|
||||
To try the example out, create a demo class named `zcl_some_class` and paste the code into it. After activation, choose *F9* in ADT to execute the class. The example is set up to display output in the console. The example should display the following:
|
||||
|
||||
```
|
||||
IS SUPPLIED: num1 "X", num2 "X", num3 "X" / Addition result "9"
|
||||
IS SUPPLIED: num1 "X", num2 "X", num3 "" / Addition result "7"
|
||||
IS SUPPLIED: num1 "", num2 "X", num3 "X" / Addition result "6"
|
||||
IS SUPPLIED: num1 "X", num2 "", num3 "X" / Addition result "6"
|
||||
IS SUPPLIED: num1 "", num2 "X", num3 "" / Addition result "4"
|
||||
IS SUPPLIED: num1 "", num2 "", num3 "X" / Addition result "3"
|
||||
IS SUPPLIED: num1 "", num2 "", num3 "" / Addition result "1"
|
||||
IS SUPPLIED: num1 "X", num2 "", num3 "" / Addition result "4"
|
||||
```
|
||||
|
||||
Example code:
|
||||
|
||||
```abap
|
||||
CLASS zcl_some_class DEFINITION
|
||||
PUBLIC
|
||||
FINAL
|
||||
CREATE PUBLIC .
|
||||
|
||||
PUBLIC SECTION.
|
||||
INTERFACES if_oo_adt_classrun.
|
||||
|
||||
CLASS-METHODS meth
|
||||
IMPORTING num1 TYPE i OPTIONAL
|
||||
num2 TYPE i OPTIONAL
|
||||
num3 TYPE i DEFAULT 1
|
||||
PREFERRED PARAMETER num1
|
||||
RETURNING VALUE(text) TYPE string.
|
||||
PROTECTED SECTION.
|
||||
PRIVATE SECTION.
|
||||
ENDCLASS.
|
||||
|
||||
CLASS zcl_some_class IMPLEMENTATION.
|
||||
METHOD if_oo_adt_classrun~main.
|
||||
|
||||
DATA(text1) = meth( num1 = 3 num2 = 3 num3 = 3 ).
|
||||
out->write( text1 ).
|
||||
|
||||
DATA(text2) = meth( num1 = 3 num2 = 3 ).
|
||||
out->write( text2 ).
|
||||
|
||||
DATA(text3) = meth( num2 = 3 num3 = 3 ).
|
||||
out->write( text3 ).
|
||||
|
||||
DATA(text4) = meth( num1 = 3 num3 = 3 ).
|
||||
out->write( text4 ).
|
||||
|
||||
DATA(text5) = meth( num2 = 3 ).
|
||||
out->write( text5 ).
|
||||
|
||||
DATA(text6) = meth( num3 = 3 ).
|
||||
out->write( text6 ).
|
||||
|
||||
DATA(text7) = meth( ).
|
||||
out->write( text7 ).
|
||||
|
||||
"Not specifying the name of the formal parameter. The
|
||||
"actual parameter is assigned to the preferred input
|
||||
"parameter.
|
||||
DATA(text8) = meth( 3 ).
|
||||
out->write( text8 ).
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD meth.
|
||||
DATA(addition) = num1 + num2 + num3.
|
||||
text = |IS SUPPLIED: num1 "{ COND #( WHEN num1 IS SUPPLIED THEN 'X' ELSE '' ) }", | &&
|
||||
|num2 "{ COND #( WHEN num2 IS SUPPLIED THEN 'X' ELSE '' ) }", | &&
|
||||
|num3 "{ COND #( WHEN num3 IS SUPPLIED THEN 'X' ELSE '' ) }" / | &&
|
||||
|Addition result "{ addition }"|.
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
#### Constructors
|
||||
|
||||
- [Constructors](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_glosry.htm "Glossary Entry")
|
||||
@@ -3547,6 +3644,13 @@ obj_factory = class=>factory_method( par = ... ).
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
### Class-Based Exceptions
|
||||
|
||||
- [Catchable exceptions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencatchable_exception_glosry.htm) are represented by exception objects of exception classes.
|
||||
- Find an overview in the [Exceptions and Runtime Errors](27_Exceptions.md) cheat sheet.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## More Information
|
||||
You can check the subtopics of
|
||||
|
||||
|
||||
@@ -1096,22 +1096,12 @@ DATA(methods) = CAST cl_abap_objectdescr(
|
||||
|
||||
## COND
|
||||
|
||||
- The
|
||||
[`COND`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconditional_expression_cond.htm)
|
||||
operator is used for either creating a result depending on [logical
|
||||
expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenlogical_expression_glosry.htm "Glossary Entry")
|
||||
or raising a [class-based
|
||||
exception](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclass_based_exception_glosry.htm "Glossary Entry")
|
||||
(which is specified within the parentheses after the addition
|
||||
[`THROW`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconditional_expression_result.htm)).
|
||||
- There can be multiple logical expressions initiated by
|
||||
`WHEN` followed by the result specified after
|
||||
`THEN`. If none of the logical expressions are true, you can
|
||||
specify an `ELSE` clause at the end. If this clause is not
|
||||
specified, the result is the initial value of the specified or
|
||||
derived data type.
|
||||
- Note that all operands specified after `THEN` must be
|
||||
convertible to the specified or derived data type.
|
||||
- The [`COND`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconditional_expression_cond.htm) operator is used for creating a result depending on [logical expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenlogical_expression_glosry.htm "Glossary Entry")
|
||||
- It can also be used to raise [class-based exceptions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclass_based_exception_glosry.htm "Glossary Entry") or [runtime errors](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenruntime_error_glosry.htm) with the [`THROW`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconditional_expression_result.htm) addition.
|
||||
- Find examples on the `THROW` addition in the [Exceptions and Runtime Errors](27_Exceptions.md) cheat sheet.
|
||||
- There can be multiple logical expressions initiated by `WHEN` followed by the result specified after `THEN`. If none of the logical expressions are true, you can
|
||||
specify an `ELSE` clause at the end. If this clause is not specified, the result is the initial value of the specified or derived data type.
|
||||
- Note that all operands specified after `THEN` must be convertible to the specified or derived data type.
|
||||
|
||||
Example:
|
||||
``` abap
|
||||
@@ -1166,13 +1156,8 @@ div = COND decfloat34( WHEN num1 <> 0 AND num2 <> 0 THEN num1 / num2
|
||||
|
||||
## SWITCH
|
||||
|
||||
The
|
||||
[`SWITCH`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconditional_expression_switch.htm)
|
||||
operator is fairly similar to the `COND` operator and works in
|
||||
the style of
|
||||
[`CASE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcase.htm)
|
||||
statements, i. e. it uses the value of only a single variable that is
|
||||
checked in the case distinction.
|
||||
- The [`SWITCH`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconditional_expression_switch.htm) operator is fairly similar to the `COND` operator and works in the style of [`CASE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcase.htm) statements, i. e. it uses the value of only a single variable that is checked in the case distinction.
|
||||
- Also here, `SWITCH` can be used to raise [class-based exceptions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenclass_based_exception_glosry.htm "Glossary Entry") or [runtime errors](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenruntime_error_glosry.htm) with the [`THROW`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconditional_expression_result.htm) addition. Find examples on the `THROW` addition in the [Exceptions and Runtime Errors](27_Exceptions.md) cheat sheet.
|
||||
|
||||
Examples:
|
||||
|
||||
|
||||
@@ -298,7 +298,7 @@ ENDIF.
|
||||
|
||||
> **💡 Note**<br>
|
||||
> - Control structures can be nested. It is recommended that you do not include more than 5 nested control structures since the code will
|
||||
> get really hard to understand. Better go for outsourcing functionality into methods to reduce nested control control structures.
|
||||
> get really hard to understand. Better go for outsourcing functionality into methods to reduce nested control structures.
|
||||
> - Keep the number of consecutive control structures low.
|
||||
> - If you are convinced that a specified logical expression must always be true, you might include a statement like `ASSERT 1 = 0.` to go
|
||||
> sure - as implied in the example's `ELSE` statement above. However, an `ELSE` statement that is never executed might be a hint that
|
||||
@@ -579,7 +579,7 @@ Function modules ...
|
||||
...
|
||||
ENDFUNCTION.
|
||||
```
|
||||
- have a parameter interface that's similar to ABAP classes. Note: In ADT, the parameter interface of a function module is defined in ABAP pseudo syntax. These statements are not compiled like genuine ABAP statements and are not subject to the regular ABAP syntax checks. Find more information on the parameter inteface in the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfunction.htm).
|
||||
- have a parameter interface that's similar to ABAP classes. Note: In ADT, the parameter interface of a function module is defined in ABAP pseudo syntax. These statements are not compiled like genuine ABAP statements and are not subject to the regular ABAP syntax checks. Find more information on the parameter interface in the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfunction.htm).
|
||||
- are called using `CALL FUNCTION` statements.
|
||||
|
||||
Function pools ...
|
||||
|
||||
@@ -28,8 +28,9 @@
|
||||
- [CONVERT ... INTO TIME STAMP: Local Date/Time -\> Time Stamp in Packed Numbers](#convert--into-time-stamp-local-datetime---time-stamp-in-packed-numbers)
|
||||
- [CL\_ABAP\_TSTMP: Calculating and Converting Time Stamps in Packed Numbers](#cl_abap_tstmp-calculating-and-converting-time-stamps-in-packed-numbers)
|
||||
- [Excursion: Unix Time Stamps](#excursion-unix-time-stamps)
|
||||
- [Date, Time, and Time Stamps in String Templates](#date-time-and-time-stamps-in-string-templates)
|
||||
- [Excursion: Date and Time Functions in ABAP SQL and ABAP CDS](#excursion-date-and-time-functions-in-abap-sql-and-abap-cds)
|
||||
- [Excursions](#excursions)
|
||||
- [Date, Time, and Time Stamps in String Templates](#date-time-and-time-stamps-in-string-templates)
|
||||
- [Date and Time Functions in ABAP SQL and ABAP CDS](#date-and-time-functions-in-abap-sql-and-abap-cds)
|
||||
- [More Information](#more-information)
|
||||
- [Executable Example](#executable-example)
|
||||
|
||||
@@ -1121,7 +1122,9 @@ DATA(ts_from_unix2) = utclong_add( val = CONV utclong( '1970-01-01 00:00:00' )
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Date, Time, and Time Stamps in String Templates
|
||||
## Excursions
|
||||
|
||||
### Date, Time, and Time Stamps in String Templates
|
||||
|
||||
More information: [String Processing cheat sheet](07_String_Processing.md#string-templates) and the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenstring_templates.htm)
|
||||
|
||||
@@ -1158,7 +1161,8 @@ tz_str = |{ utclong_current( ) TIMEZONE = 'EST' COUNTRY = 'US ' }|. "12/30/2024
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## Excursion: Date and Time Functions in ABAP SQL and ABAP CDS
|
||||
|
||||
### Date and Time Functions in ABAP SQL and ABAP CDS
|
||||
|
||||
> **💡 Note**<br>
|
||||
> - Date and time functions are available for both [ABAP SQL](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_sql_date_time_functions.htm) and [ABAP CDS](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_date_time_functions_v2.htm). They have the same names. See the [overview](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenddic_date_time_functions.htm) to find out which functions are available. The followig code snippet uses ABAP SQL.
|
||||
|
||||
@@ -49,7 +49,7 @@ This cheat sheet ...
|
||||
- They provide the same functionality as the local types that can be defined in ABAP programs with `TYPES` statements.
|
||||
- DDIC also enables the creation of additional objects, such as database tables, which are then created in the underlying database.
|
||||
- Furthermore, the DDIC includes objects that support development in various contexts, such as lock objects related to the [SAP LUW concept](17_SAP_LUW.md) and more. They are not outlined here.
|
||||
- DDIC offers many objects and functionalities particularly suited for classic ABAP technologies and user interfaces, such as dynpros. However, these are not relevant in ABAP Cloud and are not covered in this cheat sheet. For example, DDIC search helps (that are used to created value lists for input fields on dynpros) can be replaced by CDS-based search helps.
|
||||
- DDIC offers many objects and functionalities particularly suited for classic ABAP technologies and user interfaces, such as dynpros. However, these are not relevant in ABAP Cloud and are not covered in this cheat sheet. For example, DDIC search helps (that are used to create value lists for input fields on dynpros) can be replaced by CDS-based search helps.
|
||||
- The more modern concept, ABAP CDS, is integrated into the DDIC, allowing for the creation of dedicated CDS objects that can replace DDIC objects to be used in newer concepts like RAP.
|
||||
- DDIC objects are transportable.
|
||||
- In terms of repository objects in ABAP Cloud, you can use only those SAP-delivered repository objects that are released as APIs for the ABAP language version ABAP for Cloud Development, in addition to your custom repository objects. See a list of released APIs [here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreleased_apis.htm). Also, ABAP development tools for Eclipse (ADT) are the only supported tools for creating repository objects.
|
||||
@@ -183,7 +183,7 @@ DATA char1_dtel TYPE zdemo_abap_dtel_do.
|
||||
|
||||
"Data element based on a reference type
|
||||
TYPES ty_dtel3 TYPE zdemo_abap_dtel_ref.
|
||||
DATA char10_dtel_ref TYPE zdemo_abap_dtel_do.
|
||||
DATA char10_dtel_ref TYPE zdemo_abap_dtel_ref.
|
||||
```
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
@@ -939,17 +939,19 @@ msgv4 = sy-msgv4. "H
|
||||
|
||||
- This section provides examples of `RAISE EXCEPTION` statements and the `THROW` addition to the `COND` and `SWITCH` operators.
|
||||
- Note that the `RESUMABLE` addition is not covered. See more details above.
|
||||
- The variants of statements covered in the example include the use of these additions:
|
||||
- The variants of statements covered in the example include the use of these additions. Check the ABAP Keyword Documentation for details and all possible syntax options.
|
||||
- `RAISE EXCEPTION TYPE ...`
|
||||
- `RAISE EXCEPTION TYPE ... EXPORTING ...`
|
||||
- `RAISE EXCEPTION object_reference_variable.`
|
||||
- `RAISE EXCEPTION TYPE ... MESSAGE ...`
|
||||
- `RAISE EXCEPTION TYPE ... MESSAGE ... WITH ...`
|
||||
- `RAISE EXCEPTION TYPE ... MESSAGE ID ... TYPE ... NUMBER ...`
|
||||
- `RAISE EXCEPTION TYPE ... MESSAGE ID ... TYPE ... NUMBER ... WITH ...`
|
||||
- `RAISE EXCEPTION TYPE ... USING MESSAGE.`
|
||||
- `... THROW exc( ) ...`
|
||||
- `... THROW exc( ... ) ...`
|
||||
- `... THROW exc( MESSAGE ... ) ...`
|
||||
- `... THROW exc( MESSAGE ... WITH ... ) ...`
|
||||
- `... THROW exc( MESSAGE ID ... TYPE ... NUMBER ... ) ...`
|
||||
- `... THROW exc( MESSAGE ID ... TYPE ... NUMBER ... WITH ... ) ...`
|
||||
- `... THROW exc( USING MESSAGE ) ...`
|
||||
@@ -1029,6 +1031,8 @@ RAISE EXCEPTION TYPE zcx_demo_abap_error_a MESSAGE ID msgid TYPE msgtype NUMBER
|
||||
"Note that the positions of the operands determine which placeholders are replaced.
|
||||
"The first specified operand replaces &1 and so on.
|
||||
|
||||
RAISE EXCEPTION TYPE zcx_demo_abap_error_b MESSAGE e005(zdemo_abap_messages) WITH 'Hello' 'world'.
|
||||
|
||||
RAISE EXCEPTION TYPE zcx_demo_abap_error_b MESSAGE ID 'ZDEMO_ABAP_MESSAGES'
|
||||
TYPE 'E'
|
||||
NUMBER '004'
|
||||
@@ -1097,20 +1101,24 @@ DATA(cond_w_throw_3) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_a( MESSAGE e005(zdemo_abap_messages)
|
||||
p_005_a = `An exception raised with COND` ) ).
|
||||
|
||||
"MESSAGE addition including ID, TYPE, NUMBER
|
||||
DATA(cond_w_throw_4) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_b( MESSAGE e005(zdemo_abap_messages)
|
||||
WITH 'Lorem' 'ipsum' ) ).
|
||||
|
||||
"MESSAGE addition including ID, TYPE, NUMBER
|
||||
DATA(cond_w_throw_5) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_a( MESSAGE ID 'ZDEMO_ABAP_MESSAGES'
|
||||
TYPE 'E'
|
||||
NUMBER '002' ) ).
|
||||
|
||||
DATA(cond_w_throw_5) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
DATA(cond_w_throw_6) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_a( MESSAGE ID 'ZDEMO_ABAP_MESSAGES'
|
||||
TYPE 'E'
|
||||
NUMBER '005'
|
||||
p_005_a = `blabla` ) ).
|
||||
|
||||
"MESSAGE addition including ID, TYPE, NUMBER, WITH
|
||||
DATA(cond_w_throw_6) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
DATA(cond_w_throw_7) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_b( MESSAGE ID 'ZDEMO_ABAP_MESSAGES'
|
||||
TYPE 'E'
|
||||
NUMBER '005'
|
||||
@@ -1119,7 +1127,7 @@ DATA(cond_w_throw_6) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
"USING MESSAGE addition
|
||||
MESSAGE e005(zdemo_abap_messages) WITH 'Some message' INTO DATA(msg6).
|
||||
|
||||
DATA(cond_w_throw_7) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
DATA(cond_w_throw_8) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_b( USING MESSAGE ) ).
|
||||
|
||||
"----------------------------------------------------------------------------
|
||||
@@ -1138,12 +1146,16 @@ DATA(switch_w_throw_3) = SWITCH #( flag WHEN '' THEN `works`
|
||||
p_005_a = `An exception raised with SWITCH` ) ).
|
||||
|
||||
DATA(switch_w_throw_4) = SWITCH #( flag WHEN '' THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_b( MESSAGE e005(zdemo_abap_messages)
|
||||
WITH 'Test' 'message' ) ).
|
||||
|
||||
DATA(switch_w_throw_5) = SWITCH #( flag WHEN '' THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_a( MESSAGE ID 'ZDEMO_ABAP_MESSAGES'
|
||||
TYPE 'E'
|
||||
NUMBER '005'
|
||||
p_005_a = `lorem ipsum` ) ).
|
||||
|
||||
DATA(switch_w_throw_5) = SWITCH #( flag WHEN '' THEN `works`
|
||||
DATA(switch_w_throw_6) = SWITCH #( flag WHEN '' THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_b( MESSAGE ID 'ZDEMO_ABAP_MESSAGES'
|
||||
TYPE 'E'
|
||||
NUMBER '005'
|
||||
@@ -1151,7 +1163,7 @@ DATA(switch_w_throw_5) = SWITCH #( flag WHEN '' THEN `works`
|
||||
|
||||
MESSAGE e005(zdemo_abap_messages) WITH 'Some message' INTO DATA(msg7).
|
||||
|
||||
DATA(switch_w_throw_6) = SWITCH #( flag WHEN '' THEN `works`
|
||||
DATA(switch_w_throw_7) = SWITCH #( flag WHEN '' THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_b( USING MESSAGE ) ).
|
||||
```
|
||||
|
||||
@@ -2175,7 +2187,7 @@ CLASS zcl_some_class IMPLEMENTATION.
|
||||
include_name = line->source_position-incl
|
||||
source_line = line->source_position-source_line ).
|
||||
ENDTRY.
|
||||
IF sy-index = 14.
|
||||
IF sy-index = 15.
|
||||
EXIT.
|
||||
ENDIF.
|
||||
ENDDO.
|
||||
@@ -2501,11 +2513,13 @@ CLASS zcl_some_class IMPLEMENTATION.
|
||||
TYPE 'E'
|
||||
NUMBER '002'.
|
||||
WHEN 4.
|
||||
RAISE EXCEPTION TYPE zcx_demo_abap_error_b MESSAGE e005(zdemo_abap_messages) WITH 'Hello' 'world'.
|
||||
WHEN 5.
|
||||
RAISE EXCEPTION TYPE zcx_demo_abap_error_b MESSAGE ID 'ZDEMO_ABAP_MESSAGES'
|
||||
TYPE 'E'
|
||||
NUMBER '004'
|
||||
WITH 'abc' 'def' 'ghi' 'jkl'.
|
||||
WHEN 5.
|
||||
WHEN 6.
|
||||
RAISE EXCEPTION TYPE zcx_demo_abap_error_b MESSAGE ID 'ZDEMO_ABAP_MESSAGES'
|
||||
TYPE 'E'
|
||||
NUMBER '005'
|
||||
@@ -2514,22 +2528,22 @@ CLASS zcl_some_class IMPLEMENTATION.
|
||||
cl_abap_context_info=>get_system_time( )
|
||||
cl_abap_context_info=>get_user_alias( ).
|
||||
|
||||
WHEN 6.
|
||||
WHEN 7.
|
||||
RAISE EXCEPTION TYPE zcx_demo_abap_error_b MESSAGE ID 'ZDEMO_ABAP_MESSAGES'
|
||||
TYPE 'E'
|
||||
NUMBER '005'
|
||||
WITH 'only two out of four' 'parameters specified'.
|
||||
WHEN 7.
|
||||
WHEN 8.
|
||||
|
||||
MESSAGE e002(zdemo_abap_messages) INTO DATA(msg).
|
||||
RAISE EXCEPTION TYPE zcx_demo_abap_error_b USING MESSAGE.
|
||||
|
||||
WHEN 8.
|
||||
WHEN 9.
|
||||
|
||||
MESSAGE e005(zdemo_abap_messages) WITH 'a' 'b' 'c' 'd' INTO msg.
|
||||
RAISE EXCEPTION TYPE zcx_demo_abap_error_b USING MESSAGE.
|
||||
|
||||
WHEN 9.
|
||||
WHEN 10.
|
||||
|
||||
DATA: mid TYPE sy-msgid VALUE 'ZDEMO_ABAP_MESSAGES',
|
||||
mtype TYPE sy-msgty VALUE 'E',
|
||||
@@ -2538,7 +2552,7 @@ CLASS zcl_some_class IMPLEMENTATION.
|
||||
MESSAGE ID mid TYPE mtype NUMBER msg_num INTO msg.
|
||||
RAISE EXCEPTION TYPE zcx_demo_abap_error_b USING MESSAGE.
|
||||
|
||||
WHEN 10.
|
||||
WHEN 11.
|
||||
"The following statements have the same effect as USING MESSAGE.
|
||||
MESSAGE ID 'ZDEMO_ABAP_MESSAGES'
|
||||
TYPE 'E'
|
||||
@@ -2552,23 +2566,23 @@ CLASS zcl_some_class IMPLEMENTATION.
|
||||
NUMBER sy-msgno
|
||||
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
|
||||
|
||||
WHEN 11.
|
||||
WHEN 12.
|
||||
DATA(cond_w_throw_1) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_b( MESSAGE e005(zdemo_abap_messages)
|
||||
WITH `An exception raised with COND,` `MESSAGE/WITH additions` ) ).
|
||||
|
||||
WHEN 12.
|
||||
WHEN 13.
|
||||
MESSAGE e005(zdemo_abap_messages) WITH 'Exception raised with COND,' 'USING MESSAGE addition' INTO msg.
|
||||
|
||||
DATA(cond_w_throw_2) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_b( USING MESSAGE ) ).
|
||||
|
||||
WHEN 13.
|
||||
WHEN 14.
|
||||
DATA(switch_w_throw_1) = SWITCH #( flag WHEN '' THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_b( MESSAGE e005(zdemo_abap_messages)
|
||||
WITH `An exception raised with SWITCH,` `MESSAGE/WITH additions` ) ).
|
||||
|
||||
WHEN 14.
|
||||
WHEN 15.
|
||||
MESSAGE e005(zdemo_abap_messages) WITH 'Exception raised with SWITCH,' 'USING MESSAGE addition' INTO msg.
|
||||
|
||||
DATA(switch_w_throw_2) = SWITCH #( flag WHEN '' THEN `works`
|
||||
|
||||
Reference in New Issue
Block a user