Update
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1225,9 +1225,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
|
||||
"Demonstrating prominent sy components that can be used in ABAP for Cloud Development
|
||||
|
||||
"------------------------------------------------------------------------------
|
||||
"------------------ sy-subrc: Return code of ABAP statements ------------------
|
||||
"------------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& 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.
|
||||
@@ -1287,9 +1287,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
out->write( `DELETE: No match according to the WHERE condition.` ).
|
||||
ENDIF.
|
||||
|
||||
"------------------------------------------------------------------------------
|
||||
"--------------------------- sy-index: Loop indexes ---------------------------
|
||||
"------------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& sy-index: Loop indexes
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
CLEAR some_string.
|
||||
|
||||
@@ -1323,10 +1323,10 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
|
||||
ASSERT some_string = `123456789`.
|
||||
|
||||
"------------------------------------------------------------------------------
|
||||
"------------------- sy-tabix: Row index of internal tables -------------------
|
||||
"------------------------------------------------------------------------------
|
||||
|
||||
*&---------------------------------------------------------------------*
|
||||
*& 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` ) ).
|
||||
|
||||
@@ -1388,9 +1388,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
ENDLOOP.
|
||||
ASSERT some_string = `00000`.
|
||||
|
||||
"------------------------------------------------------------------------------
|
||||
"------------------------ sy-dbcnt: Edited table rows -------------------------
|
||||
"------------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& sy-dbcnt: Edited table rows
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DELETE FROM zdemo_abap_tab1.
|
||||
DATA(dbcnt) = sy-dbcnt.
|
||||
@@ -1412,9 +1412,10 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
DELETE FROM zdemo_abap_tab1 WHERE num1 IS INITIAL.
|
||||
ASSERT sy-dbcnt = 3.
|
||||
|
||||
"------------------------------------------------------------------------------
|
||||
"------------- sy-fdpos: Occurrence in byte or character strings --------------
|
||||
"------------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& 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.
|
||||
@@ -1556,10 +1557,10 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
"---- Comment in/out END ----
|
||||
DO 100000 TIMES.
|
||||
|
||||
"------------------------------------------------------------------------
|
||||
"----------------------------- Comparison 1 -----------------------------
|
||||
"------------------------------------------------------------------------
|
||||
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Comparison 1
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"1) Internal table with boxed components: All boxed components empty
|
||||
|
||||
"---- Comment in/out START ----
|
||||
@@ -1578,9 +1579,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
|
||||
**************************************************************************************************
|
||||
|
||||
"------------------------------------------------------------------------
|
||||
"----------------------------- Comparison 2 -----------------------------
|
||||
"------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Comparison 2
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"3) Internal table with boxed components: All boxed components filled
|
||||
|
||||
@@ -1604,9 +1605,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
|
||||
**************************************************************************************************
|
||||
|
||||
"------------------------------------------------------------------------
|
||||
"----------------------------- Comparison 3 -----------------------------
|
||||
"------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Comparison 3
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"5) Internal table with boxed components: Only few boxed components filled
|
||||
|
||||
|
||||
@@ -2389,7 +2389,10 @@ UPDATE dbtab FROM TABLE @itab.
|
||||
UPDATE dbtab FROM TABLE @( VALUE #( ( comp1 = ... comp2 = ... )
|
||||
( comp1 = ... comp2 = ... ) ) ).
|
||||
|
||||
"-------------------------- SET addition --------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& SET addition
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Changing values of specific fields without overwriting other, non-specified
|
||||
"fields
|
||||
"Changing values of specific fields in all table rows
|
||||
@@ -2409,7 +2412,10 @@ UPDATE dbtab SET comp2 = 'X', comp3 = 'Y' WHERE comp4 > 100.
|
||||
"in the WHERE clause
|
||||
UPDATE dbtab SET comp2 = 'X' WHERE key_field = 'Y'.
|
||||
|
||||
"--------------- INDICATORS ... SET STRUCTURE addition ---------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& INDICATORS ... SET STRUCTURE addition
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Similar to SET, using the INDICATORS ... addition, you can change content
|
||||
"of specific fields without overwriting existing values of other fields by
|
||||
"specifying set indicators.
|
||||
@@ -2501,7 +2507,10 @@ For more information about constructor expressions, see the ABAP Keyword Documen
|
||||
The following examples show a selection. The previous code snippets already include the use of the `VALUE` operator with which structures and internal tables can be created in place.
|
||||
|
||||
```abap
|
||||
"--- VALUE ---
|
||||
*&---------------------------------------------------------------------*
|
||||
*& VALUE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"VALUE operator as shown above, creating an internal table in place
|
||||
INSERT dbtab FROM TABLE @( VALUE #( ( key_field = 1 comp1 = ... )
|
||||
( key_field = 2 comp1 = ... )
|
||||
@@ -2533,7 +2542,10 @@ SELECT SINGLE * FROM dbtab WHERE key_field = ... INTO @DATA(read_line).
|
||||
"original content and are not initialized when writing to the database table.
|
||||
UPDATE dbtab FROM @( VALUE #( BASE read_line comp2 = ... comp4 = ... ) ).
|
||||
|
||||
"--- CORRESPONDING ---
|
||||
*&---------------------------------------------------------------------*
|
||||
*& CORRESPONDING
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The following example assumes that some_itab has a different line type than dbtab.
|
||||
"I.e. some_itab may have more components that are not available in dbtab. The
|
||||
"corresponding fields with identical names are used. It is assumed that the components'
|
||||
@@ -2572,8 +2584,10 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
|
||||
METHOD if_oo_adt_classrun~main.
|
||||
|
||||
"--------------------------- INSERT ---------------------------
|
||||
|
||||
*&---------------------------------------------------------------------*
|
||||
*& INSERT
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Deleting the contents of a demo database table to start with an empty database table
|
||||
DELETE FROM zdemo_abap_tab1.
|
||||
|
||||
@@ -2645,9 +2659,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
SELECT * FROM zdemo_abap_tab1 INTO TABLE @DATA(itab_insert).
|
||||
out->write( data = itab_insert name = `itab_insert` ).
|
||||
|
||||
**********************************************************************
|
||||
|
||||
"--------------------------- UPDATE ---------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& UPDATE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Preparing a demo database table
|
||||
DELETE FROM zdemo_abap_tab1.
|
||||
@@ -2721,9 +2735,10 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
SELECT * FROM zdemo_abap_tab1 INTO TABLE @DATA(itab_update_set).
|
||||
out->write( data = itab_update_set name = `itab_update_set` ).
|
||||
|
||||
**********************************************************************
|
||||
*&---------------------------------------------------------------------*
|
||||
*& MODIFY
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"--------------------------- MODIFY ---------------------------
|
||||
"The examples include INSERT statements to prepare the database table.
|
||||
|
||||
"Deleting the contents of a demo database table to start with an empty database table
|
||||
@@ -2753,9 +2768,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
SELECT * FROM zdemo_abap_tab1 INTO TABLE @DATA(itab_modify).
|
||||
out->write( data = itab_modify name = `itab_modify` ).
|
||||
|
||||
**********************************************************************
|
||||
|
||||
"--------------------------- DELETE ---------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& DELETE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Deleting the contents of a demo database table to start with an empty database table
|
||||
DELETE FROM zdemo_abap_tab1.
|
||||
@@ -2790,9 +2805,10 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
SELECT * FROM zdemo_abap_tab1 INTO TABLE @itab_delete.
|
||||
out->write( data = itab_delete name = `itab_delete` ).
|
||||
|
||||
**********************************************************************
|
||||
*&-----------------------------------------------------------------------*
|
||||
*& Exploring constructor expressions for internal tables created in place
|
||||
*&-----------------------------------------------------------------------*
|
||||
|
||||
"-------- Exploring constructor expressions for internal tables created in place --------
|
||||
"For more information about constructor expressions, see the ABAP Keyword Documentation and the
|
||||
"Constructor Expressions cheat sheet. Many additions are available. The examples show a
|
||||
"selection.
|
||||
@@ -2886,7 +2902,7 @@ SELECT *
|
||||
- CDS artifacts are available that allow not only reading but also creating, updating, and deleting.
|
||||
- **Table Entities**
|
||||
- Table entities are CDS entities that define database tables on the SAP HANA database linked to AS ABAP.
|
||||
- They are - with restructions currently - considered successors of the classic DDIC database table, and also represent global structured types usable in ABAP.
|
||||
- They are - with restrictions currently - considered successors of the classic DDIC database table, and also represent global structured types usable in ABAP.
|
||||
- Syntax: `define table entity ...`.
|
||||
- For more information, refer to the ABAP Data Models guide, for example, [here](https://help.sap.com/docs/ABAP_Cloud/aaae421481034feab3e71dd9e0f643bf/100ab51935544f18b4f4be9b4abb91e8.html).
|
||||
- **Writable CDS View Entities**
|
||||
@@ -3164,7 +3180,10 @@ The following example explores the setting of `sy-subrc` and `sy-dbcnt` by ABAP
|
||||
"Clearing a demo database table
|
||||
DELETE FROM zdemo_abap_tab1.
|
||||
|
||||
"--------------------- INSERT ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& INSERT
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
INSERT zdemo_abap_tab1 FROM @( VALUE #( key_field = 1 ) ).
|
||||
|
||||
ASSERT sy-subrc = 0.
|
||||
@@ -3188,7 +3207,10 @@ INSERT zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 3 )
|
||||
ASSERT sy-subrc = 4.
|
||||
ASSERT sy-dbcnt = 1.
|
||||
|
||||
"--------------------- UPDATE ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& UPDATE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
UPDATE zdemo_abap_tab1 FROM @( VALUE #( key_field = 1 num1 = 1 ) ).
|
||||
|
||||
ASSERT sy-subrc = 0.
|
||||
@@ -3211,7 +3233,10 @@ UPDATE zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 4 num1 = 4 )
|
||||
ASSERT sy-subrc = 4.
|
||||
ASSERT sy-dbcnt = 1.
|
||||
|
||||
"--------------------- MODIFY ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& MODIFY
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
MODIFY zdemo_abap_tab1 FROM @( VALUE #( key_field = 1 num1 = 11 ) ).
|
||||
|
||||
ASSERT sy-subrc = 0.
|
||||
@@ -3223,7 +3248,9 @@ MODIFY zdemo_abap_tab1 FROM TABLE @( VALUE #( ( key_field = 2 num1 = 22 ) "E
|
||||
ASSERT sy-subrc = 0.
|
||||
ASSERT sy-dbcnt = 2.
|
||||
|
||||
"--------------------- SELECT ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& SELECT
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
SELECT *
|
||||
FROM zdemo_abap_tab1
|
||||
@@ -3249,7 +3276,10 @@ SELECT *
|
||||
ASSERT sy-subrc = 4.
|
||||
ASSERT sy-dbcnt = 0.
|
||||
|
||||
"--------------------- DELETE ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& DELETE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DELETE zdemo_abap_tab1 FROM @( VALUE #( key_field = 1 ) ).
|
||||
ASSERT sy-subrc = 0.
|
||||
ASSERT sy-dbcnt = 1.
|
||||
|
||||
@@ -414,7 +414,7 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
|
||||
METHOD if_oo_adt_classrun~main.
|
||||
|
||||
"---- The method called has formal parameters using type declarations from the CCDEF include ----
|
||||
"The method called has formal parameters using type declarations from the CCDEF include
|
||||
TRY.
|
||||
DATA(result1) = calculate( num1 = 10 operator = '+' num2 = 4 ).
|
||||
out->write( data = result1 name = `result1` ).
|
||||
@@ -436,13 +436,13 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
out->write( `Operator not allowed` ).
|
||||
ENDTRY.
|
||||
|
||||
"---- Using local class implemented in the CCIMP include ----
|
||||
"Using local class implemented in the CCIMP include
|
||||
DATA(hi1) = lcl_demo=>say_hello( ).
|
||||
out->write( data = hi1 name = `hi1` ).
|
||||
DATA(hi2) = lcl_demo=>say_hello( xco_cp=>sy->user( )->name ).
|
||||
out->write( data = hi2 name = `hi2` ).
|
||||
|
||||
"--------------- Test include (CCAU) ---------------
|
||||
"Test include (CCAU)
|
||||
"For running the ABAP Unit test, choose CTRL+Shift+F10 in ADT.
|
||||
"Or you can make a right click in the class code, choose
|
||||
"'Run As' and '4 ABAP Unit Test'.
|
||||
@@ -896,49 +896,49 @@ CLASS zcl_demo_abap DEFINITION
|
||||
"Note: The example parameters are all specified for passing
|
||||
"actual parameters by reference.
|
||||
METHODS: meth IMPORTING
|
||||
"---- Non-generic built-in ABAP types ----
|
||||
"Non-generic built-in ABAP types
|
||||
i_a TYPE i
|
||||
i_b TYPE string
|
||||
"---- ABAP DDIC types ----
|
||||
"ABAP DDIC types
|
||||
i_c TYPE land1 "elementary type
|
||||
i_d TYPE timestampl "elementary type
|
||||
i_e TYPE zdemo_abap_fli "structured type based on DDIC database table
|
||||
i_f TYPE string_hashed_table "table type
|
||||
"---- ABAP CDS types (all of the examples are structured types) ----
|
||||
"ABAP CDS types (all of the examples are structured types)
|
||||
i_g TYPE zdemo_abap_fli_ve "CDS view entity
|
||||
i_h TYPE zdemo_abap_abstract_ent "CDS abstract entity
|
||||
i_i TYPE zdemo_abap_table_function "CDS table function
|
||||
"---- Data types declared in public section of a class ----
|
||||
"Data types declared in public section of a class
|
||||
i_j TYPE zcl_demo_abap_dtype_dobj=>t_pub_text_c30 "elementary type
|
||||
i_k TYPE zcl_demo_abap_amdp=>carr_fli_struc "structured type
|
||||
i_l TYPE zcl_demo_abap_amdp=>carr_fli_tab "table type
|
||||
"---- Data types declared in an interface ----
|
||||
"Data types declared in an interface
|
||||
i_m TYPE zdemo_abap_get_data_itf=>occ_rate "elementary type
|
||||
i_n TYPE zdemo_abap_get_data_itf=>carr_tab "table type
|
||||
"---- Local types ----
|
||||
"Local types
|
||||
i_o TYPE c3 "elementary type
|
||||
i_p TYPE der_type "table type (BDEF derived type)
|
||||
"---- Note: Examples such as the following are not allowed type specifications of formal parameters. ----
|
||||
"---- In the following cases, extra (local) type declarations with TYPES are required before the --------
|
||||
"---- method declaration to type the formal parameters. -------------------------------------------------
|
||||
"Note: Examples such as the following are not allowed type specifications of formal parameters.
|
||||
"In the following cases, extra (local) type declarations with TYPES are required before the
|
||||
"method declaration to type the formal parameters.
|
||||
"i_no1 TYPE c LENGTH 3
|
||||
"i_no2 TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY
|
||||
"---- Reference types ----
|
||||
"Reference types
|
||||
i_q TYPE REF TO i "Data reference
|
||||
i_r TYPE REF TO zdemo_abap_carr "Data reference
|
||||
i_s TYPE REF TO zcl_demo_abap_unit_test "Object reference
|
||||
i_t TYPE REF TO data "Data reference (considered as complete typing, too)
|
||||
i_u TYPE REF TO object "Object reference (considered as complete typing, too)
|
||||
"---- TYPE LINE OF addition (structured type based on a table type) ----
|
||||
"TYPE LINE OF addition (structured type based on a table type)
|
||||
i_v TYPE LINE OF zcl_demo_abap_amdp=>carr_fli_tab
|
||||
i_w TYPE LINE OF der_type
|
||||
"---- LIKE addition (types based on existing data objects) ----
|
||||
"LIKE addition (types based on existing data objects)
|
||||
i_x LIKE int "Local data object
|
||||
i_y LIKE zcl_demo_abap_dtype_dobj=>comma "Constant specified in a class
|
||||
i_z LIKE zdemo_abap_objects_interface=>stat_str "Data object specified in an interface
|
||||
"---- LIKE LINE OF addition (types based on existing internal tables) ----
|
||||
"LIKE LINE OF addition (types based on existing internal tables)
|
||||
i_1 LIKE LINE OF itab "Local internal table
|
||||
"---- LIKE REF TO addition (reference types based on existing data object) ----
|
||||
"LIKE REF TO addition (reference types based on existing data object)
|
||||
i_2 LIKE REF TO int "Local elementary data object
|
||||
i_3 LIKE REF TO itab "Local internal table
|
||||
.
|
||||
@@ -985,11 +985,11 @@ CLASS zcl_demo_abap DEFINITION
|
||||
|
||||
"Example method demonstrating the generic typing of formal parameters
|
||||
METHODS: meth IMPORTING
|
||||
"---- Any data type ----
|
||||
"Any data type
|
||||
i_data TYPE data
|
||||
i_any TYPE any
|
||||
|
||||
"---- Character-like types ----
|
||||
"Character-like types
|
||||
i_c TYPE c "Text field with a generic length
|
||||
i_clike TYPE clike "Character-like (c, n, string, d, t, and character-like flat structures)
|
||||
i_csequence TYPE csequence "Text-like (c, string)
|
||||
@@ -997,12 +997,12 @@ CLASS zcl_demo_abap DEFINITION
|
||||
i_x TYPE x "Byte field with generic length
|
||||
i_xsequence TYPE xsequence "Byte-like (x, xstring)
|
||||
|
||||
"---- Numeric types ----
|
||||
"Numeric types
|
||||
i_decfloat TYPE decfloat "decfloat16 decfloat34
|
||||
i_numeric TYPE numeric "Numeric (i, int8, p, decfloat16, decfloat34, f, (b, s))
|
||||
i_p TYPE p "Packed number (generic length and number of decimal places)
|
||||
|
||||
"---- Internal table types ----
|
||||
"Internal table types
|
||||
i_any_table TYPE ANY TABLE "Internal table with any table type
|
||||
i_hashed_table TYPE HASHED TABLE
|
||||
i_index_table TYPE INDEX TABLE
|
||||
@@ -1010,7 +1010,7 @@ CLASS zcl_demo_abap DEFINITION
|
||||
i_standard_table TYPE STANDARD TABLE
|
||||
i_table TYPE table "Standard table
|
||||
|
||||
"---- Other types ----
|
||||
"Other types
|
||||
i_simple TYPE simple "Elementary data type including enumerated types and
|
||||
"structured types with exclusively character-like flat components
|
||||
.
|
||||
@@ -2189,9 +2189,9 @@ ENDCLASS.
|
||||
CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
METHOD if_oo_adt_classrun~main.
|
||||
|
||||
"----------------------------------------------------------------
|
||||
"-------- Method chaining with a functional method call ---------
|
||||
"----------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Method chaining with a functional method call
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Hallo NAME. This is an example of method chaining.
|
||||
DATA(text1) = NEW zcl_demo_abap(
|
||||
@@ -2250,9 +2250,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
|
||||
out->write( text2 ).
|
||||
|
||||
"----------------------------------------------------------------
|
||||
"-------- Method chaining with a standalone statement -----------
|
||||
"----------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Method chaining with a standalone statement
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"In the example, the final method call in the chain receives
|
||||
"the classrun instance available in the implementation of the
|
||||
@@ -2321,7 +2321,10 @@ CLASS zcl_demo_abap DEFINITION
|
||||
PUBLIC SECTION.
|
||||
INTERFACES if_oo_adt_classrun.
|
||||
|
||||
"------------------------ Attributes ------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Attributes
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Instance attributes
|
||||
DATA: inst_attr TYPE utclong,
|
||||
inst_string TYPE string.
|
||||
@@ -2335,7 +2338,10 @@ CLASS zcl_demo_abap DEFINITION
|
||||
"subclasses (note that the example class does not allow inheritance).
|
||||
CLASS-DATA read_only_attr TYPE string VALUE `read only` READ-ONLY.
|
||||
|
||||
"------------------------ Methods ------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Methods
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The parameter interfaces (signatures) of the methods are intended to
|
||||
"demonstrate various syntax options described in the cheat sheet.
|
||||
|
||||
@@ -2424,7 +2430,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
"To demonstrate 'calls from external', an instance of the class is
|
||||
"nevertheless created in the example.
|
||||
|
||||
"--------------- Constructors ---------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Constructors
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Instance constructor: Automatically called when a class is instantiated
|
||||
"and an instance is created.
|
||||
@@ -2494,7 +2502,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
DATA(d) = zcl_demo_abap=>stat_attr.
|
||||
DATA(e) = oref->stat_attr.
|
||||
|
||||
"--------------- Method calls ---------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Method calls
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Calling instance methods
|
||||
"Instance methods are called using the object component selector ->
|
||||
@@ -5920,7 +5930,9 @@ CL_ABAP_TYPEDESCR
|
||||
Examples:
|
||||
|
||||
```abap
|
||||
"------------ Object reference variables ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Object reference variables
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Static and dynamic types
|
||||
"Defining an object reference variable with a static type
|
||||
@@ -5941,7 +5953,9 @@ DATA tdo_elem TYPE REF TO cl_abap_elemdescr.
|
||||
DATA tdo_data TYPE REF TO cl_abap_datadescr.
|
||||
DATA tdo_gen_obj TYPE REF TO object.
|
||||
|
||||
"------------ Upcasts ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Upcasts
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Moving up the inheritance tree
|
||||
"Assignments:
|
||||
@@ -5980,7 +5994,9 @@ DATA(tdo_inl_cast) = CAST cl_abap_typedescr( tdo_elem ).
|
||||
|
||||
CLEAR: tdo_super, tdo_elem, tdo_data, tdo_gen_obj.
|
||||
|
||||
"------------ Downcasts ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Downcasts
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Moving down the inheritance tree
|
||||
"Assignments:
|
||||
@@ -6056,7 +6072,10 @@ ENDTRY.
|
||||
"- non-initial object reference variables, the dynamic type is checked.
|
||||
"- initial object reference variables, the static type is checked.
|
||||
|
||||
"------------ IS INSTANCE OF ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& IS INSTANCE OF
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA some_type_descr_obj TYPE REF TO cl_abap_typedescr.
|
||||
some_type_descr_obj = cl_abap_typedescr=>describe_by_data( str_table ).
|
||||
|
||||
@@ -6098,7 +6117,10 @@ ELSE.
|
||||
...
|
||||
ENDIF.
|
||||
|
||||
"------------ CASE TYPE OF ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& CASE TYPE OF
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The examples are desinged similarly to the IS INSTANCE OF examples.
|
||||
|
||||
DATA(dref) = REF #( str_table ).
|
||||
|
||||
@@ -672,8 +672,8 @@ DATA(it_val_1) = VALUE string_table( FOR GROUPS gr OF wa IN itab4grp
|
||||
The following table includes a selection of various possible additions to
|
||||
this operator. There are more variants available (also
|
||||
[RAP](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrap_glosry.htm "Glossary Entry")-specific ones)
|
||||
that are not covered. Find more information in [this
|
||||
topic](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expr_corresponding.htm) of the ABAP Keyword Documentation.
|
||||
that are not covered here. Find more information in [this
|
||||
topic](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenconstructor_expr_corresponding.htm) of the ABAP Keyword Documentation, and example snippets in the executable example.
|
||||
|
||||
|
||||
| Addition | Details |
|
||||
@@ -690,7 +690,9 @@ topic](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file
|
||||
|
||||
Examples:
|
||||
``` abap
|
||||
"-------------- Patterns -------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Patterns
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The following examples demonstrate simple assignments
|
||||
"with the CORRESPONDING operator using these syntax patterns.
|
||||
@@ -705,7 +707,9 @@ Examples:
|
||||
"... CORRESPONDING #( z EXCEPT b ) ...
|
||||
"... CORRESPONDING #( it DISCARDING DUPLICATES ) ...
|
||||
|
||||
"-------------- Structures -------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Structures
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Data objects to work with in the examples
|
||||
"Two different structures; one component differs.
|
||||
@@ -767,7 +771,9 @@ s2 = CORRESPONDING #( s1 MAPPING d = c EXCEPT * ).
|
||||
*A B D
|
||||
*0 bbbbb
|
||||
|
||||
"-------------- Internal tables -------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Internal tables
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Internal tables to work with in the examples
|
||||
DATA it1 LIKE TABLE OF s1 WITH EMPTY KEY.
|
||||
@@ -817,7 +823,10 @@ it2 = CORRESPONDING #( it1 DISCARDING DUPLICATES ).
|
||||
*4 aaa
|
||||
*5 eee
|
||||
|
||||
"-------------- DEFAULT addition when using MAPPING -------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& DEFAULT addition when using MAPPING
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"- This addition allows the assignment of values for a target component based
|
||||
" on an expression (which is evaluated before the CORRESPONDING expression).
|
||||
"- DEFAULT can be preceded by the source component. In this case, the source
|
||||
@@ -849,7 +858,10 @@ DATA itab1 LIKE TABLE OF struc1 WITH EMPTY KEY.
|
||||
"Populating structure
|
||||
struc1 = VALUE #( id1 = 1 a = `a` b = `b` c = 2 d = `d` e = 3 ).
|
||||
|
||||
"--------- Assignment using CORRESPONDING (DEFAULT only) ---------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Assignment using CORRESPONDING (DEFAULT only)
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"- Component a: It is not specified but it is mapped anyway
|
||||
" due to the identical name and not being explicitly specified
|
||||
" for mapping
|
||||
@@ -873,8 +885,11 @@ struc2 = CORRESPONDING #(
|
||||
*ID2 A B C D Z
|
||||
*1 a hallo 6 hi 28
|
||||
|
||||
"--- Assignment using CORRESPONDING (DEFAULT preceded by the source ---
|
||||
"--- component on the right-hand side) --------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Assignment using CORRESPONDING (DEFAULT preceded by the source
|
||||
*& component on the right-hand side)
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"- The example is similar to above. Various expressions are included
|
||||
" in combination with the DEFAULT addition
|
||||
"- Component a: It is not specified; see above.
|
||||
@@ -1166,6 +1181,7 @@ it6 = CORRESPONDING #( it5 FROM lookup_table USING KEY sk c = a d = b ) ##operat
|
||||
No parameters are passed for a class without an explicit
|
||||
instance constructor. See more information:
|
||||
[here](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abennew_constructor_params_class.htm).
|
||||
- The `NEW` operator is also covered as part of the [ABAP Object Orientation](04_ABAP_Object_Orientation.md) cheat sheet.
|
||||
|
||||
The following examples cover:
|
||||
- Creating anonymous data objects
|
||||
@@ -1173,7 +1189,10 @@ The following examples cover:
|
||||
|
||||
|
||||
``` abap
|
||||
"-------------- Creating anonymous data objects -------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Creating anonymous data objects
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Note that optional additions (see for VALUE expressions) when dealing
|
||||
"with anonymous data objects (e.g. BASE). They are not covered here.
|
||||
|
||||
@@ -1210,7 +1229,9 @@ DATA dref5 TYPE REF TO string_table.
|
||||
dref5 = NEW string_table( ( `c` ) ( `d` ) ).
|
||||
DATA(dref6) = NEW string_table( VALUE #( ( `a` ) ( `b` ) ) ).
|
||||
|
||||
"-------------- Creating objects/instances of classes -------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Creating objects/instances of classes
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Using a cheat sheet example class (the class does not implement constructors)
|
||||
DATA oref1 TYPE REF TO zcl_demo_abap_objects.
|
||||
@@ -1809,7 +1830,10 @@ fi_tab2 = fi_tab1.
|
||||
fi_tab3 = fi_tab1.
|
||||
fi_tab4 = fi_tab1.
|
||||
|
||||
"---------------- Basic form: Filtering using single values ----------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Basic form: Filtering using single values
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Syntax options for using a WHERE condition and the table key
|
||||
|
||||
"Using the primary table key without specifying USING KEY
|
||||
@@ -1887,7 +1911,9 @@ DATA(f10) = FILTER #( fi_tab4 EXCEPT USING KEY sec_hash_key WHERE a = 3 AND b =
|
||||
*4 ddd klm
|
||||
*5 eee nop
|
||||
|
||||
"---------------- Basic form: Filtering using a filter table ----------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Basic form: Filtering using a filter table
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"In the WHERE condition, the columns of source and filter table are compared.
|
||||
"Those lines in the source table are used for which at least one line in the
|
||||
@@ -2098,7 +2124,9 @@ DATA(itab) = VALUE itab_type( ( col1 = 'a' col2 = 1 col3 = 30 )
|
||||
( col1 = 'bb' col2 = 2 col3 = 10 )
|
||||
( col1 = 'ccc' col2 = 3 col3 = 20 ) ).
|
||||
|
||||
"-------------- Table iterations --------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Table iterations
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(it1) = VALUE itab_type( FOR wa IN itab ( col1 = wa-col1 && 'z'
|
||||
col2 = wa-col2 + 1 ) ).
|
||||
@@ -2144,7 +2172,9 @@ DATA(it3) = VALUE string_table( FOR <str> IN itab INDEX INTO idx
|
||||
*Table index 2 -> COL1: "bb" / COL2: "2" / COL3: "10"
|
||||
*Table index 3 -> COL1: "ccc" / COL2: "3" / COL3: "20"
|
||||
|
||||
"---------- Excursions ----------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Excursions
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"FOR expression are very handy, for example, in EML and other statements.
|
||||
"The following example commented out shows an EML statement in the implementation
|
||||
@@ -2293,7 +2323,10 @@ DATA(it11) = VALUE itab_type( FOR wa IN itab USING KEY primary_key ( col1 = wa-c
|
||||
*bbt 9 12
|
||||
*ccct 9 13
|
||||
|
||||
"---------- Conditional iterations ----------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Conditional iterations
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Notes:
|
||||
"- When used with VALUE/NEW for internal tables: New table lines are created in
|
||||
" iteration steps and added to result
|
||||
@@ -2386,7 +2419,9 @@ DATA(itab) = VALUE itab_type( ( col1 = 'a' col2 = 1 col3 = 30 )
|
||||
( col1 = 'bb' col2 = 2 col3 = 10 )
|
||||
( col1 = 'ccc' col2 = 3 col3 = 20 ) ).
|
||||
|
||||
"---------- Table iterations ----------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Table iterations
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Calculating the sum of values in a table column
|
||||
"Result: 6
|
||||
@@ -2443,7 +2478,9 @@ DATA(itred) = REDUCE s3_tab_type( INIT tab = VALUE s3_tab_type( )
|
||||
*1 30 31
|
||||
*2 10 12
|
||||
|
||||
"---------- Conditional iterations ----------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Conditional iterations
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"UNTIL addition
|
||||
"Iteratively calculating the sum from 1 to 10
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
- The ABAP compiler cannot check the dynamic programming feature like the `SELECT` statement mentioned above. There is no syntax warning or suchlike.
|
||||
- The checks are performed only at runtime, which has an impact on the performance.
|
||||
- The testing of [procedures](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenprocedure_glosry.htm "Glossary Entry") that include dynamic programming features may be difficult.
|
||||
- Including external input in dynamic ABAP SQL statements without an appropriate handling, there can be potential security risks. You can, for example, use the `CL_ABAP_DYN_PRG` class to manage security risks.
|
||||
- ⚠️ Dynamic programming techniques can pose significant security risks if not used correctly. You should thoroughly check or escape any dynamic content received from external sources before using it in dynamic statements. You can achieve this using the system class `CL_ABAP_DYN_PRG` or the built-in `escape` function.
|
||||
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
@@ -668,7 +668,9 @@ Excursion: Static vs. dynamic type, upcasts and downcasts
|
||||
The code snippet below demonstrates upcasts and downcasts with data reference variables, but also object reference variables to visualize moving up and down an inheritance tree. The examples in the code snippet use object reference variables to illustrate the class hierarchy of the [Runtime Type Services (RTTS)](#runtime-type-services-rtts), which is covered in more detail further down. You can find the hierarchy tree of the classes [here](#runtime-type-services-rtts).
|
||||
|
||||
``` abap
|
||||
"------------ Object reference variables ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Object reference variables
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Static and dynamic types
|
||||
"Defining an object reference variable with a static type
|
||||
@@ -689,7 +691,9 @@ DATA tdo_elem TYPE REF TO cl_abap_elemdescr.
|
||||
DATA tdo_data TYPE REF TO cl_abap_datadescr.
|
||||
DATA tdo_gen_obj TYPE REF TO object.
|
||||
|
||||
"------------ Upcasts ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Upcasts
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Moving up the inheritance tree
|
||||
"Assignments:
|
||||
@@ -728,7 +732,9 @@ DATA(tdo_inl_cast) = CAST cl_abap_typedescr( tdo_elem ).
|
||||
|
||||
CLEAR: tdo_super, tdo_elem, tdo_data, tdo_gen_obj.
|
||||
|
||||
"------------ Downcasts ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Downcasts
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Moving down the inheritance tree
|
||||
"Assignments:
|
||||
@@ -750,7 +756,9 @@ tdo_elem = CAST #( tdo_data ).
|
||||
"cl_abap_typedescr -> cl_abap_elemdescr
|
||||
tdo_elem = CAST #( tdo_super ).
|
||||
|
||||
"------------ Error prevention in downcasts ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Error prevention in downcasts
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"In the examples above, the assignments work. The following code snippets
|
||||
"deal with examples in which a downcast is not possible. An exception is
|
||||
@@ -791,7 +799,10 @@ ENDTRY.
|
||||
"- non-initial object reference variables, the dynamic type is checked.
|
||||
"- initial object reference variables, the static type is checked.
|
||||
|
||||
"------------ IS INSTANCE OF ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& IS INSTANCE OF
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA some_tdo TYPE REF TO cl_abap_typedescr.
|
||||
some_tdo = cl_abap_typedescr=>describe_by_data( str_table ).
|
||||
|
||||
@@ -833,7 +844,10 @@ ELSE.
|
||||
...
|
||||
ENDIF.
|
||||
|
||||
"------------ CASE TYPE OF ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& CASE TYPE OF
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The examples are desinged similarly to the IS INSTANCE OF examples.
|
||||
|
||||
DATA(dref) = REF #( str_table ).
|
||||
@@ -871,9 +885,9 @@ CASE TYPE OF initial_tdo.
|
||||
...
|
||||
ENDCASE.
|
||||
|
||||
**********************************************************************
|
||||
|
||||
"------------ Data reference variables ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Data reference variables
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Declaring data reference variables
|
||||
DATA ref1 TYPE REF TO i.
|
||||
@@ -1196,7 +1210,10 @@ DATA dobj TYPE string VALUE `hallo`.
|
||||
"The following examples use a field symbol with generic type
|
||||
FIELD-SYMBOLS <fs> TYPE data.
|
||||
|
||||
"------- Specifying the memory area dynamically ------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Specifying the memory area dynamically
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"I.e. the memory area is not specified directly, but as content of a
|
||||
"character-like data object in parentheses.
|
||||
"Note:
|
||||
@@ -1240,7 +1257,10 @@ DATA(some_named_dobj) = 'SOME_STRING'.
|
||||
"Development.
|
||||
"ASSIGN (some_named_dobj) TO FIELD-SYMBOL(<fs>).
|
||||
|
||||
"------- Assigning components dynamically ------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Assigning components dynamically
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"You can chain the names with the component selector (-), or, in
|
||||
"case of reference variables, the object component selector (->).
|
||||
ASSIGN st-('COL1') TO <fs>.
|
||||
@@ -1271,7 +1291,10 @@ ASSIGN st-(0) TO <fs>.
|
||||
ASSIGN COMPONENT 'COL1' OF STRUCTURE st TO <fs>.
|
||||
ASSIGN COMPONENT 3 OF STRUCTURE st TO <fs>.
|
||||
|
||||
"------- Assigning attributes of classes or interfaces dynamically ------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Assigning attributes of classes or interfaces dynamically
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The following syntax pattern shows the possible specifications.
|
||||
"... cref->(attr_name) ... "object reference variable
|
||||
"... iref->(attr_name) ... "interface reference variable
|
||||
@@ -1327,7 +1350,10 @@ ASSERT sy-subrc = 0 AND <eu> IS ASSIGNED.
|
||||
ASSIGN ('DOES_NOT_EXIST') TO <eu> ELSE UNASSIGN.
|
||||
ASSERT sy-subrc = 4 AND <eu> IS NOT ASSIGNED.
|
||||
|
||||
"------- Assigments and casting a dynamically specified type ------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Assigments and casting a dynamically specified type
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Pattern: ASSIGN ... TO <fs> CASTING TYPE (type_name).
|
||||
|
||||
"Assigning a data object to a field symbol casting a dynamically
|
||||
@@ -1369,7 +1395,9 @@ ENDLOOP.
|
||||
*Error! Exception raised: CX_SY_ASSIGN_CAST_UNKNOWN_TYPE; 'ASSIGN ... CASTING failed; NOPE is an unknown type'
|
||||
*Error! Exception raised: CX_SY_ASSIGN_CAST_ILLEGAL_CAST; 'ASSIGN ... CASTING failed: Incompatible type'
|
||||
|
||||
"------- Assigments and dynamic casting using a type description object ------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Assigments and dynamic casting using a type description object
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Note: As covered further down and in the executable example,
|
||||
"CREATE DATA and ASSIGN statements have the HANDLE addition
|
||||
@@ -1395,7 +1423,10 @@ ASSIGN dobj_c10 TO <casttype> CASTING TYPE HANDLE tdo_elem. "1234
|
||||
- You can also use type description objects and the [`TYPE HANDLE` addition](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapcreate_data_handle.htm) to create anonymous data objects dynamically. For this and the absolute names, find more information below in the section about RTTS.
|
||||
|
||||
``` abap
|
||||
"------------ CREATE DATA statement patterns ----------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& CREATE DATA statement patterns
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"CREATE DATA dref TYPE (typename) ...
|
||||
"CREATE DATA dref TYPE ... TABLE OF (typename) ...
|
||||
"CREATE DATA dref TYPE REF TO (typename).
|
||||
@@ -1404,7 +1435,9 @@ ASSIGN dobj_c10 TO <casttype> CASTING TYPE HANDLE tdo_elem. "1234
|
||||
"CREATE DATA dref TYPE (absolute_name).
|
||||
"CREATE DATA dref TYPE HANDLE type_description_object.
|
||||
|
||||
"------------ Specifying a type name dynamically ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Specifying a type name dynamically
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Anonymous data objects are created using a type determined at
|
||||
"runtime. In this case, the name of the data type is specified
|
||||
@@ -1432,8 +1465,9 @@ DATA carr_tab TYPE TABLE OF zdemo_abap_carr WITH EMPTY KEY.
|
||||
TYPES t_str_ref TYPE REF TO string.
|
||||
DATA str_ref TYPE REF TO string.
|
||||
|
||||
|
||||
"----- Pattern: TYPE (typename) ... -----
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Pattern: TYPE (typename) ...
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Creating an elementary data object
|
||||
"Specifying a literal for the dynamic type name (used in most of the
|
||||
@@ -1453,7 +1487,9 @@ CREATE DATA dref TYPE ('T_CARR_TAB').
|
||||
"Data reference
|
||||
CREATE DATA dref TYPE ('T_STR_REF').
|
||||
|
||||
"----- Pattern: TYPE ... TABLE OF (typename) ... -----
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Pattern: TYPE ... TABLE OF (typename) ...
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Creating internal tables
|
||||
"Note that the syntax with CREATE DATA does not support the specification of
|
||||
@@ -1474,7 +1510,9 @@ DATA itab TYPE SORTED TABLE OF zdemo_abap_fli WITH UNIQUE KEY carrid connid flda
|
||||
DATA(key_table) = VALUE string_table( ( `CARRID` ) ( `CONNID` ) ( `FLDATE` ) ).
|
||||
CREATE DATA dref TYPE SORTED TABLE OF ('ZDEMO_ABAP_FLI') WITH UNIQUE KEY (key_table).
|
||||
|
||||
"----- Pattern: TYPE REF TO (typename) -----
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Pattern: TYPE REF TO (typename)
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Creating data reference variables
|
||||
|
||||
@@ -1483,23 +1521,31 @@ CREATE DATA dref TYPE REF TO ('T_C3').
|
||||
CREATE DATA dref TYPE REF TO ('T_FLI_STRUC').
|
||||
CREATE DATA dref TYPE REF TO ('T_CARR_TAB').
|
||||
|
||||
"----- Pattern: TYPE LINE OF (typename) -----
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Pattern: TYPE LINE OF (typename)
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Creating structures based on table types
|
||||
CREATE DATA dref TYPE LINE OF ('T_CARR_TAB').
|
||||
|
||||
"----- Pattern: LIKE struc-(dobjname) -----
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Pattern: LIKE struc-(dobjname)
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
CREATE DATA dref LIKE fli_struc-('CARRID').
|
||||
|
||||
"----- Pattern: TYPE (absolute_name) -----
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Pattern: TYPE (absolute_name)
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
CREATE DATA dref TYPE ('\TYPE=STRING').
|
||||
"Getting an absolute type name; see more information further down
|
||||
DATA(absolute_name) = cl_abap_typedescr=>describe_by_name( 'ZDEMO_ABAP_CARR' )->absolute_name.
|
||||
CREATE DATA dref TYPE (absolute_name).
|
||||
|
||||
"----- Pattern: TYPE HANDLE type_description_object -----
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Pattern: TYPE HANDLE type_description_object
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Getting a type description object. Find more information about RTTI below.
|
||||
DATA(tdo_elem) = cl_abap_elemdescr=>get_c( 4 ). "type c length 4
|
||||
@@ -1706,9 +1752,9 @@ itab_ref = VALUE #( ( NEW demo_struct( col1 = 1 col2 = `aaa` col3 = `zzz` ) ) ).
|
||||
"- Many of the following statements provide similar additions offering dynamic
|
||||
" specifications, such as USING KEY and dynamic component name specifications.
|
||||
|
||||
"----------------------------------------------------------
|
||||
"------------------------ SORT (1) ------------------------
|
||||
"----------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& SORT (1)
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Note: See more dynamic specifications with SORT statements
|
||||
"further down.
|
||||
@@ -1719,9 +1765,9 @@ SORT itab_ek BY (field_name) DESCENDING.
|
||||
"Unnamed data object specified within parenteses
|
||||
SORT itab_ek BY ('COL2') ASCENDING.
|
||||
|
||||
"-------------------------------------------------------------
|
||||
"------------------------ READ TABLE -------------------------
|
||||
"-------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& READ TABLE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Reading by specifying keys dynamically
|
||||
"Implicitly specifying the table key values in a work area (USING KEY addition)
|
||||
@@ -1772,9 +1818,9 @@ DATA(dyn_where_cond_tab) = VALUE string_table( ( `col3` ) ( `CS` ) ( `'x'` ) ).
|
||||
READ TABLE itab INTO dyn_res WHERE (dyn_where_cond_tab).
|
||||
ASSERT sy-tabix = 3.
|
||||
|
||||
"-------------------------------------------------------------
|
||||
"------------------------ Table expressions ------------------
|
||||
"-------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Table expressions
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Similar to READ TABLE statements, you can specify table lines with 3 alternatives:
|
||||
"index read, read using free key, table key
|
||||
@@ -1801,9 +1847,9 @@ DATA(wa_te4) = itab[ KEY ('PRIMARY_KEY') COMPONENTS ('COL1') = 1 ].
|
||||
itab[ 1 ]-('COL2') = `jkl`.
|
||||
itab_ref[ 1 ]->('COL2') = `mno`.
|
||||
|
||||
"--------------------------------------------------------
|
||||
"------------------------ LOOP AT -----------------------
|
||||
"--------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& LOOP AT
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"USING KEY addition: Overriding the standard order determined by the table category
|
||||
LOOP AT itab REFERENCE INTO DATA(ref) USING KEY ('SK').
|
||||
@@ -1828,9 +1874,9 @@ LOOP AT itab REFERENCE INTO ref WHERE (cond_loop).
|
||||
...
|
||||
ENDLOOP.
|
||||
|
||||
"--------------------------------------------------------
|
||||
"------------------------ INSERT ------------------------
|
||||
"--------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& INSERT
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The USING KEY addition (which accepts a dynamic specification) affects the order in which lines are inserted.
|
||||
|
||||
@@ -1859,9 +1905,9 @@ LOOP AT itab INTO DATA(wa_pk) USING KEY ('PRIMARY_KEY').
|
||||
APPEND wa_pk TO it_primekey_idx.
|
||||
ENDLOOP.
|
||||
|
||||
"--------------------------------------------------------
|
||||
"------------------------ MODIFY ------------------------
|
||||
"--------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& MODIFY
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"In the following example, a line is modified based on a work area and a table key.
|
||||
"The component col1 is left out from the work area intentionally.
|
||||
@@ -1881,9 +1927,9 @@ MODIFY itab INDEX 2 USING KEY ('SK') FROM VALUE #( col3 = `ttt` ) TRANSPORTING (
|
||||
DATA(cond_mod) = `COL1 < 3`.
|
||||
MODIFY itab FROM VALUE #( col3 = `sss` ) TRANSPORTING ('COL3') WHERE (cond_mod).
|
||||
|
||||
"--------------------------------------------------------
|
||||
"------------------------ DELETE ------------------------
|
||||
"--------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& DELETE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"A single line or multipled lines can be deleted.
|
||||
"Note that DELETE ADJACENT DUPLICATES statements can also be specified using
|
||||
@@ -1908,9 +1954,9 @@ DATA(condition_tab) = VALUE string_table( ( `COL1 < 3` )
|
||||
( `COL3 = ``www``` ) ).
|
||||
DELETE itab WHERE (condition_tab).
|
||||
|
||||
"--------------------------------------------------------
|
||||
"------------------------ SORT (2) ------------------------
|
||||
"--------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& SORT (2)
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Sorting by dynamically specified components in a sort table, i. e.an
|
||||
"internal table of type abap_sortorder_tab.
|
||||
@@ -1995,7 +2041,9 @@ SORT it BY VALUE abap_sortorder_tab( FOR wa IN comp_names ( name = condense( to_
|
||||
### Dynamic ABAP SQL Statements
|
||||
|
||||
```abap
|
||||
"--------------------- Dynamic SELECT list ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic SELECT list
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(select_list) = `CARRID, CONNID, FLDATE`.
|
||||
DATA fli_tab TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY.
|
||||
@@ -2004,14 +2052,18 @@ SELECT (select_list)
|
||||
FROM zdemo_abap_fli
|
||||
INTO CORRESPONDING FIELDS OF TABLE @fli_tab.
|
||||
|
||||
"--------------------- Dynamic FROM clause ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic FROM clause
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(table) = 'ZDEMO_ABAP_FLI'.
|
||||
SELECT *
|
||||
FROM (table)
|
||||
INTO TABLE @fli_tab.
|
||||
|
||||
"--------------------- Excursion: Compatible target data objects ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Excursion: Compatible target data objects
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"In the examples above, the data object/type is created statically.
|
||||
|
||||
@@ -2041,7 +2093,9 @@ SELECT *
|
||||
FROM (table)
|
||||
INTO TABLE NEW @DATA(dref_tab).
|
||||
|
||||
"--------------------- Dynamic WHERE clause ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic WHERE clause
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The example includes a WHERE clause that is created as an internal
|
||||
"table with a character-like row type.
|
||||
@@ -2062,14 +2116,18 @@ SELECT *
|
||||
WHERE (where_clause_string)
|
||||
INTO TABLE NEW @DATA(tab_dyn_where_str).
|
||||
|
||||
"--------------------- Dynamic ORDER BY clause ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic ORDER BY clause
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
SELECT *
|
||||
FROM zdemo_abap_fli
|
||||
ORDER BY (`FLDATE`)
|
||||
INTO TABLE NEW @DATA(tab_dyn_order).
|
||||
|
||||
"----- SELECT statement with miscellaneous dynamic specifications -----
|
||||
*&---------------------------------------------------------------------*
|
||||
*& SELECT statement with miscellaneous dynamic specifications
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
SELECT (`CARRID, CONNID, FLDATE`)
|
||||
FROM (`ZDEMO_ABAP_FLI`)
|
||||
@@ -2077,7 +2135,9 @@ SELECT (`CARRID, CONNID, FLDATE`)
|
||||
ORDER BY (`FLDATE`)
|
||||
INTO TABLE NEW @DATA(tab_dyn_misc).
|
||||
|
||||
"--------------------- Dynamic INSERT statement ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic INSERT statement
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Creating a structure to be inserted into the database table
|
||||
SELECT SINGLE *
|
||||
@@ -2087,21 +2147,29 @@ dref_struc->('CARRID') = 'YZ'.
|
||||
|
||||
INSERT (table) FROM @dref_struc->*.
|
||||
|
||||
"--------------------- Dynamic UPDATE statement ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic UPDATE statement
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
dref_struc->('CURRENCY') = 'EUR'.
|
||||
UPDATE (table) FROM @dref_struc->*.
|
||||
|
||||
"--------------------- Dynamic MODIFY statement ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic MODIFY statement
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
dref_struc->('SEATSOCC') = 10.
|
||||
MODIFY (table) FROM @dref_struc->*.
|
||||
|
||||
"--------------------- Dynamic DELETE statement ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic DELETE statement
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DELETE FROM (table) WHERE (`CARRID = 'YZ'`).
|
||||
|
||||
"--------------------- Dynamic UPDATE ... SET ... statement ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic UPDATE ... SET ... statement
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Inserting demo data into the database table to work with
|
||||
TYPES carr_tab TYPE TABLE OF zdemo_abap_carr WITH EMPTY KEY.
|
||||
@@ -2130,7 +2198,9 @@ set_clause = `CURRCODE = 'EUR'`.
|
||||
|
||||
UPDATE ('ZDEMO_ABAP_CARR') SET (set_clause) WHERE (where_cl).
|
||||
|
||||
"--------------------- Dynamic UPDATE ... INDICATORS ... statement ---------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic UPDATE ... INDICATORS ... statement
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The statement changes values of specific fields without overwriting existing values of
|
||||
"other fields.
|
||||
@@ -2224,90 +2294,101 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
"table is looped over to output content of all database tables
|
||||
DATA(dbtabs) = VALUE string_table( ( `ZDEMO_ABAP_CARR` )
|
||||
( `ZDEMO_ABAP_FLI` )
|
||||
( `ZDEMO_WRONG_TABLE` )
|
||||
( `ZDEMO_ABAP_FLSCH` ) ).
|
||||
|
||||
LOOP AT dbtabs INTO DATA(dbtab).
|
||||
"Retrieving database content of a dynamically specified database table (up to 5 rows)
|
||||
|
||||
"Checking for allowed input
|
||||
TRY.
|
||||
SELECT *
|
||||
FROM (dbtab)
|
||||
INTO TABLE NEW @DATA(itab)
|
||||
UP TO 5 ROWS.
|
||||
CATCH cx_sy_dynamic_osql_semantics INTO DATA(sql_error).
|
||||
CLEAR itab->*.
|
||||
out->write( |Table { dbtab } does not exist.| ).
|
||||
DATA(value1) = cl_abap_dyn_prg=>check_allowlist(
|
||||
val = dbtab
|
||||
allowlist_str = `ZDEMO_ABAP_CARR,ZDEMO_ABAP_FLI,ZDEMO_ABAP_FLSCH` ).
|
||||
|
||||
"Retrieving database content of a dynamically specified database table (up to 5 rows)
|
||||
TRY.
|
||||
SELECT *
|
||||
FROM (dbtab)
|
||||
INTO TABLE NEW @DATA(itab)
|
||||
UP TO 5 ROWS.
|
||||
CATCH cx_sy_dynamic_osql_semantics INTO DATA(sql_error).
|
||||
CLEAR itab->*.
|
||||
out->write( sql_error->get_text( ) ).
|
||||
CONTINUE.
|
||||
ENDTRY.
|
||||
CATCH cx_abap_not_in_allowlist INTO DATA(not_allowed).
|
||||
out->write( not_allowed->get_text( ) ).
|
||||
CONTINUE.
|
||||
ENDTRY.
|
||||
|
||||
IF sql_error IS INITIAL.
|
||||
"Getting table component names using RTTI methods
|
||||
TRY.
|
||||
DATA(type_descr_obj_tab) = CAST cl_abap_tabledescr(
|
||||
cl_abap_typedescr=>describe_by_data( itab->* ) ).
|
||||
DATA(tab_comps) = CAST cl_abap_structdescr(
|
||||
type_descr_obj_tab->get_table_line_type( ) )->get_components( ).
|
||||
LOOP AT tab_comps ASSIGNING FIELD-SYMBOL(<comp>).
|
||||
APPEND VALUE #( name = <comp>-name len = strlen( <comp>-name ) ) TO it_comps.
|
||||
ENDLOOP.
|
||||
CATCH cx_sy_move_cast_error INTO DATA(error).
|
||||
out->write( |{ error->get_text( ) }| ).
|
||||
ENDTRY.
|
||||
"Getting table component names using RTTI methods
|
||||
TRY.
|
||||
DATA(type_descr_obj_tab) = CAST cl_abap_tabledescr(
|
||||
cl_abap_typedescr=>describe_by_data( itab->* ) ).
|
||||
DATA(tab_comps) = CAST cl_abap_structdescr(
|
||||
type_descr_obj_tab->get_table_line_type( ) )->get_components( ).
|
||||
LOOP AT tab_comps ASSIGNING FIELD-SYMBOL(<comp>).
|
||||
APPEND VALUE #( name = <comp>-name len = strlen( <comp>-name ) ) TO it_comps.
|
||||
ENDLOOP.
|
||||
CATCH cx_sy_move_cast_error INTO DATA(error).
|
||||
out->write( |{ error->get_text( ) }| ).
|
||||
ENDTRY.
|
||||
|
||||
IF error IS INITIAL.
|
||||
out->write( |\n| ).
|
||||
out->write( |Retrieved content of database table { dbtab }:| ).
|
||||
"Implementation for properly aligning the content
|
||||
"The example is implemented to check the length of the column names as well as the
|
||||
"length of the values in the columns. It determines the length of the longest string
|
||||
"in each column. Depending on the length values, either the length of the column name
|
||||
"or the length of the longest string in a column is stored in an internal table that
|
||||
"contains information for calculating the offset.
|
||||
LOOP AT tab_comps ASSIGNING FIELD-SYMBOL(<len>).
|
||||
ASSIGN it_comps[ name = <len>-name ] TO FIELD-SYMBOL(<co>).
|
||||
DATA(max_content) = REDUCE i( INIT len = <co>-len
|
||||
FOR <line> IN itab->*
|
||||
NEXT len = COND #( LET lv = |{ <line>-(<co>-name) }| IN
|
||||
WHEN strlen( lv ) > len THEN strlen( lv )
|
||||
ELSE len ) ).
|
||||
"Extend the length value to leave some more space
|
||||
IF max_content > <co>-len.
|
||||
<co>-len = max_content + 3.
|
||||
ELSE.
|
||||
<co>-len += 3.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
"Calculating offset values
|
||||
DATA max_str_len TYPE i.
|
||||
LOOP AT it_comps ASSIGNING FIELD-SYMBOL(<off>).
|
||||
DATA(tabix) = sy-tabix.
|
||||
READ TABLE it_comps INDEX tabix - 1 ASSIGNING FIELD-SYMBOL(<prev>).
|
||||
<off>-off = COND #( WHEN tabix = 1 THEN 0 ELSE <prev>-len + <prev>-off ).
|
||||
max_str_len += <off>-len.
|
||||
ENDLOOP.
|
||||
"Providing enough space so that table row content can be inserted based on
|
||||
"the offset specification
|
||||
SHIFT str BY max_str_len PLACES RIGHT.
|
||||
"Adding the column names first
|
||||
LOOP AT it_comps ASSIGNING FIELD-SYMBOL(<header>).
|
||||
str = insert( val = str sub = <header>-name off = <header>-off ).
|
||||
ENDLOOP.
|
||||
out->write( str ).
|
||||
"Processing all lines in the internal table containing the retrieved table rows
|
||||
LOOP AT itab->* ASSIGNING FIELD-SYMBOL(<wa>).
|
||||
CLEAR str.
|
||||
SHIFT str BY max_str_len PLACES RIGHT.
|
||||
DO.
|
||||
TRY.
|
||||
str = insert( val = str sub = <wa>-(sy-index) off = it_comps[ sy-index ]-off ).
|
||||
CATCH cx_sy_assign_illegal_component cx_sy_range_out_of_bounds cx_sy_itab_line_not_found.
|
||||
EXIT.
|
||||
ENDTRY.
|
||||
ENDDO.
|
||||
out->write( str ).
|
||||
ENDLOOP.
|
||||
ENDIF.
|
||||
IF error IS INITIAL.
|
||||
out->write( |\n| ).
|
||||
CLEAR: str, it_comps.
|
||||
out->write( |Retrieved content of database table { dbtab }:| ).
|
||||
"Implementation for properly aligning the content
|
||||
"The example is implemented to check the length of the column names as well as the
|
||||
"length of the values in the columns. It determines the length of the longest string
|
||||
"in each column. Depending on the length values, either the length of the column name
|
||||
"or the length of the longest string in a column is stored in an internal table that
|
||||
"contains information for calculating the offset.
|
||||
LOOP AT tab_comps ASSIGNING FIELD-SYMBOL(<len>).
|
||||
ASSIGN it_comps[ name = <len>-name ] TO FIELD-SYMBOL(<co>).
|
||||
DATA(max_content) = REDUCE i( INIT len = <co>-len
|
||||
FOR <line> IN itab->*
|
||||
NEXT len = COND #( LET lv = |{ <line>-(<co>-name) }| IN
|
||||
WHEN strlen( lv ) > len THEN strlen( lv )
|
||||
ELSE len ) ).
|
||||
"Extend the length value to leave some more space
|
||||
IF max_content > <co>-len.
|
||||
<co>-len = max_content + 3.
|
||||
ELSE.
|
||||
<co>-len += 3.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
"Calculating offset values
|
||||
DATA max_str_len TYPE i.
|
||||
LOOP AT it_comps ASSIGNING FIELD-SYMBOL(<off>).
|
||||
DATA(tabix) = sy-tabix.
|
||||
READ TABLE it_comps INDEX tabix - 1 ASSIGNING FIELD-SYMBOL(<prev>).
|
||||
<off>-off = COND #( WHEN tabix = 1 THEN 0 ELSE <prev>-len + <prev>-off ).
|
||||
max_str_len += <off>-len.
|
||||
ENDLOOP.
|
||||
"Providing enough space so that table row content can be inserted based on
|
||||
"the offset specification
|
||||
SHIFT str BY max_str_len PLACES RIGHT.
|
||||
"Adding the column names first
|
||||
LOOP AT it_comps ASSIGNING FIELD-SYMBOL(<header>).
|
||||
str = insert( val = str sub = <header>-name off = <header>-off ).
|
||||
ENDLOOP.
|
||||
out->write( str ).
|
||||
"Processing all lines in the internal table containing the retrieved table rows
|
||||
LOOP AT itab->* ASSIGNING FIELD-SYMBOL(<wa>).
|
||||
CLEAR str.
|
||||
SHIFT str BY max_str_len PLACES RIGHT.
|
||||
DO.
|
||||
TRY.
|
||||
str = insert( val = str sub = <wa>-(sy-index) off = it_comps[ sy-index ]-off ).
|
||||
CATCH cx_sy_assign_illegal_component cx_sy_range_out_of_bounds cx_sy_itab_line_not_found.
|
||||
EXIT.
|
||||
ENDTRY.
|
||||
ENDDO.
|
||||
out->write( str ).
|
||||
ENDLOOP.
|
||||
ENDIF.
|
||||
out->write( |\n| ).
|
||||
CLEAR: str, it_comps.
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
@@ -2403,9 +2484,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
DATA(cl_name) = `ZCL_DEMO_ABAP`.
|
||||
DATA(meth_name1) = `STAT_METH1`.
|
||||
|
||||
"------------------------------------------------------------------------
|
||||
"---------------- Calling static methods dynamically --------------------
|
||||
"------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Calling static methods dynamically
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"-------- Method without mandatory parameters defined --------
|
||||
"The syntax is possible for methods of the same class.
|
||||
@@ -2464,9 +2545,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
CATCH cx_sy_dyn_call_illegal_type.
|
||||
ENDTRY.
|
||||
|
||||
"------------------------------------------------------------------------
|
||||
"---------------- Calling instance methods dynamically ------------------
|
||||
"------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Calling instance methods dynamically
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Creating an instance of a class by specifying the type dynamically
|
||||
DATA oref TYPE REF TO object.
|
||||
@@ -2488,9 +2569,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
CALL METHOD oref->(`STAT_METH2`) EXPORTING text = `test` IMPORTING result = res.
|
||||
ASSERT res = `TEST`.
|
||||
|
||||
"------------------------------------------------------------------------
|
||||
"------------------- PARAMETER-TABLE addition ---------------------------
|
||||
"------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& PARAMETER-TABLE addition
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"------- Static equivalents to the dynamic statement below -------
|
||||
DATA(oref_stat) = NEW zcl_demo_abap( ).
|
||||
@@ -2973,11 +3054,10 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
"Filling demo database tables of the ABAP cheat sheet repository
|
||||
zcl_demo_abap_aux=>fill_dbtabs( ).
|
||||
|
||||
"--------------------------------------------------------------------
|
||||
"--- Specifying the data object holding external input as operand ---
|
||||
"--- and literal ----------------------------------------------------
|
||||
"--------------------------------------------------------------------
|
||||
|
||||
*&-------------------------------------------------------------------------*
|
||||
*& Specifying the data object holding external input as operand and literal
|
||||
*&-------------------------------------------------------------------------*
|
||||
|
||||
"The example explores a dynamic WHERE clause. External content is used
|
||||
"in the WHERE clause, unchecked.
|
||||
|
||||
@@ -3025,9 +3105,10 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
out->write( |\n\n| ).
|
||||
out->write( |{ repeat( val = `*` occ = 70 ) }| ).
|
||||
|
||||
"--------------------------------------------------------------------
|
||||
"------------ Accessing not allowed database tables -----------------
|
||||
"--------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Accessing not allowed database tables
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Assume the name of a database table is specified externally, and a
|
||||
"dynamic ABAP SQL statement uses this name. Potentially, users that
|
||||
"are actually not allowed to access the database table may get access.
|
||||
@@ -3103,9 +3184,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
out->write( |\n\n| ).
|
||||
out->write( |{ repeat( val = `*` occ = 70 ) }| ).
|
||||
|
||||
"--------------------------------------------------------------------
|
||||
"------------ Verifying input against a given allowlist ------------
|
||||
"--------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Verifying input against a given allowlist
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Assume a SELECT statement dynamically specifies the column names
|
||||
"in the SELECT list. Table columns might be accessed although
|
||||
@@ -3150,9 +3231,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
out->write( |\n\n| ).
|
||||
out->write( |{ repeat( val = `*` occ = 70 ) }| ).
|
||||
|
||||
"--------------------------------------------------------------------
|
||||
"------------ Potential manipulation of ABAP SQL clauses ------------
|
||||
"--------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Potential manipulation of ABAP SQL clauses
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"In the following example, a dynamic WHERE clause is set up. For this,
|
||||
"it is assumed that the WHERE clause uses external input via input fields.
|
||||
@@ -3279,9 +3360,9 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
|
||||
out->write( |{ repeat( val = `*` occ = 70 ) }| ).
|
||||
|
||||
"--------------------------------------------------------------------
|
||||
"---------------------------- Escaping ------------------------------
|
||||
"--------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Escaping
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"In various contexts, a replacement of special characters may be important.
|
||||
"Such an escaping is applied on characters contained in a string according
|
||||
@@ -4442,11 +4523,10 @@ They use the following methods to get type description objects:
|
||||
- `...=>get*` (getting type description objects for elementary and other types; other get* methods are shown further down)
|
||||
|
||||
```abap
|
||||
"------------------------------------------------------------------
|
||||
"--- Getting a type description object from an existing data ------
|
||||
"--- type name ----------------------------------------------------
|
||||
"--- describe_by_name method --------------------------------------
|
||||
"------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Getting a type description object from an existing data type name
|
||||
*& describe_by_name method
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Elementary and structured data object, internal table
|
||||
TYPES ty_elem TYPE c LENGTH 5.
|
||||
@@ -4459,11 +4539,10 @@ DATA(tdo_from_name2) = cl_abap_typedescr=>describe_by_name( type_name ).
|
||||
"As shown above, using a cast to get more details.
|
||||
DATA(tdo_from_name3) = CAST cl_abap_tabledescr( cl_abap_typedescr=>describe_by_name( 'TY_TAB' ) ).
|
||||
|
||||
"------------------------------------------------------------------
|
||||
"--- Getting a type description object from an existing data ------
|
||||
"--- object -------------------------------------------------------
|
||||
"--- describe_by_data method --------------------------------------
|
||||
"------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Getting a type description object from an existing data object
|
||||
*& describe_by_data method
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Elementary and structured data object, internal table
|
||||
DATA elem_dobj TYPE c LENGTH 5.
|
||||
@@ -4475,11 +4554,10 @@ DATA(tdo_from_dobj2) = cl_abap_typedescr=>describe_by_data( struct_dobj ).
|
||||
"As shown above, using a cast to get more details.
|
||||
DATA(tdo_from_dobj3) = CAST cl_abap_tabledescr( cl_abap_typedescr=>describe_by_data( tab_dobj ) ).
|
||||
|
||||
"----------------------------------------------------------------
|
||||
"--- Getting a type description object for built-in elementary --
|
||||
"--- types ------------------------------------------------------
|
||||
"--- cl_abap_elemdescr=>get* methods ----------------------------
|
||||
"----------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Getting a type description object for built-in elementary types
|
||||
*& cl_abap_elemdescr=>get* methods
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Conceptually, all elementary, built-in ABAP types already
|
||||
"exist and can be accessed by the corresponding get_* methods.
|
||||
@@ -4957,7 +5035,7 @@ DATA(tdo_tab_4) = cl_abap_tabledescr=>get_with_keys(
|
||||
( name = 'F' type = cl_abap_elemdescr=>get_i( ) )
|
||||
( name = 'G' type = CAST cl_abap_datadescr( cl_abap_typedescr=>describe_by_name( 'LAND1' ) ) )
|
||||
( name = 'H' type = CAST cl_abap_datadescr( cl_abap_typedescr=>describe_by_name( 'ZDEMO_ABAP_FLSCH' ) ) )
|
||||
( name = 'I' type = CAST cl_abap_datadescr( CAST cl_abap_refdescr( cl_abap_typedescr=>describe_by_data( REF #( `hello` ) ) ) ) )
|
||||
( name = 'I' type = CAST cl_abap_datadescr( cl_abap_refdescr=>get_by_name( 'STRING' ) ) )
|
||||
) )
|
||||
p_keys = VALUE #(
|
||||
( name = VALUE #( ) "In case of the primary table key, a name must be provided here
|
||||
|
||||
@@ -347,7 +347,10 @@ ASSERT cl_abap_char_utilities=>cr_lf = |\r\n|.
|
||||
- The following syntax examples demonstrate a selection. For information about all options, refer to [this topic](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapcompute_string_format_options.htm) in the ABAP Keyword Documentation.
|
||||
|
||||
```abap
|
||||
"---------------------- DATE ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& DATE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Defining the format of a date
|
||||
"The output is just an example and depends on your settings.
|
||||
DATA(d) = |The date is { cl_abap_context_info=>get_system_date( ) DATE = USER }.|. "The date is 01/01/2024.
|
||||
@@ -355,7 +358,10 @@ d = |{ cl_abap_context_info=>get_system_date( ) DATE = RAW }|. "20240101
|
||||
d = |{ cl_abap_context_info=>get_system_date( ) DATE = ISO }|. "2024-01-01
|
||||
d = |{ cl_abap_context_info=>get_system_date( ) DATE = ENVIRONMENT }|. "01/01/2024
|
||||
|
||||
"---------------------- TIME ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& TIME
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Defining the format of a time
|
||||
"The output is just an example and depends on your settings.
|
||||
DATA(tm) = |The time is { cl_abap_context_info=>get_system_time( ) TIME = ISO }.|. "The time is 14:37:24.
|
||||
@@ -363,7 +369,10 @@ tm = |{ cl_abap_context_info=>get_system_time( ) TIME = RAW }|. "143724
|
||||
tm = |{ cl_abap_context_info=>get_system_time( ) TIME = USER }|. "14:37:24
|
||||
tm = |{ cl_abap_context_info=>get_system_time( ) TIME = ENVIRONMENT }|. "14:37:24
|
||||
|
||||
"---------------------- TIMESTAMP ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& TIMESTAMP
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Defining the format of a time stamp
|
||||
"The output is just an example and depends on your settings.
|
||||
DATA(ts) = |{ utclong_current( ) TIMESTAMP = SPACE }|. "2024-01-01 14:39:50.4069170
|
||||
@@ -372,31 +381,49 @@ ts = |{ utclong_current( ) TIMESTAMP = USER }|. "01/01/2024 14:39:50.4072010
|
||||
ts = |{ utclong_current( ) TIMESTAMP = ENVIRONMENT }|. "01/01/2024 14:39:50.4073230
|
||||
ts = |{ utclong_current( ) }|. "2024-01-01 14:39:50.4074060
|
||||
|
||||
"---------------------- TIMEZONE ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& TIMEZONE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Defining the format of a time stamp using the rules for time zones
|
||||
DATA(tz) = |{ utclong_current( ) TIMEZONE = 'UTC' }|. "2024-12-30 14:43:20.6534640
|
||||
tz = |{ utclong_current( ) TIMEZONE = 'CET' COUNTRY = 'DE ' }|. "30.12.2024 15:43:20,6536320
|
||||
tz = |{ utclong_current( ) TIMEZONE = 'EST' COUNTRY = 'US ' }|. "12/30/2024 09:43:20.6889180 AM
|
||||
|
||||
"---------------------- CASE ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& CASE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Lowercase and uppercase
|
||||
s1 = `AbCdEfG`.
|
||||
s2 = |{ s1 CASE = LOWER }|. "abcdefg
|
||||
s2 = |{ s1 CASE = UPPER }|. "ABCDEFG
|
||||
|
||||
"---------------------- WIDTH/ALIGN ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& WIDTH/ALIGN
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
s1 = `##`.
|
||||
s2 = |{ s1 WIDTH = 10 ALIGN = LEFT }<---|. "'## <---'
|
||||
s2 = |{ s1 WIDTH = 10 ALIGN = CENTER }<---|. "' ## <---'
|
||||
|
||||
"---------------------- PAD ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& PAD
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Used to pad any surplus places in the result with the specified character.
|
||||
s2 = |{ s1 WIDTH = 10 ALIGN = RIGHT PAD = `.` }<---|. "'........##<---'
|
||||
|
||||
"---------------------- DECIMALS ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& DECIMALS
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
s1 = |{ CONV decfloat34( - 1 / 3 ) DECIMALS = 3 }|. "'-0.333'
|
||||
|
||||
"---------------------- SIGN ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& SIGN
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Defining the format of the +/- sign when the string represented
|
||||
"by the embedded expression represents a numeric value
|
||||
"- left without space, no +
|
||||
@@ -412,12 +439,18 @@ s1 = |{ 1 SIGN = RIGHTPLUS }|. "1+
|
||||
"- left without space, blank right for +
|
||||
s1 = |{ +1 SIGN = RIGHTSPACE }|. "1
|
||||
|
||||
"---------------------- ZERO ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& ZERO
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Defining the format of the numeric value zero.
|
||||
"Only to be specified if the embedded expression has a numeric data type.
|
||||
s1 = |'{ 0 ZERO = NO }' and '{ 0 ZERO = YES }'|. "'' and '0'
|
||||
|
||||
"---------------------- XSD ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& XSD
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Formatting is applied to an embedded expression (elementary data types) in asXML format that is
|
||||
"assigned to its data type. Check the information in the ABAP Keyword Documentation about the asXML
|
||||
"mapping of elementary ABAP types.
|
||||
@@ -431,7 +464,10 @@ s1 = |{ dat XSD = YES }|. "2024-01-01
|
||||
s1 = |{ tim XSD = YES }|. "12:34:56
|
||||
s1 = |{ utc XSD = YES }|. "2024-01-01T13:51:38.57088Z
|
||||
|
||||
"---------------------- STYLE ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& STYLE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Defining the style of decimal floating point numbers;
|
||||
"see the details in the ABAP Keyword Documentation.
|
||||
DATA(dcfl34) = CONV decfloat34( '-123.45600' ).
|
||||
@@ -451,7 +487,10 @@ s1 = |{ dcfl34 STYLE = SCALE_PRESERVING_SCIENTIFIC }|. "-1.2345600E+0002
|
||||
"Technical format
|
||||
s1 = |{ dcfl34 STYLE = ENGINEERING }|. "-123.456E+00
|
||||
|
||||
"---------------------- ALPHA ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& ALPHA
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Adds or removes leading zeros from strings of digits; the data type
|
||||
"must be string, c, or n
|
||||
"Adding leading zeros
|
||||
@@ -1897,7 +1936,10 @@ Examples:
|
||||
DATA(some_string) = `aa bb cc dd ee`.
|
||||
DATA(original_string) = some_string.
|
||||
|
||||
"---------------- Statements ----------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Statements
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
FIND ALL OCCURRENCES OF PCRE `\s` IN some_string RESULTS DATA(findings).
|
||||
*LINE OFFSET LENGTH SUBMATCHES
|
||||
*0 2 1 OFFSET LENGTH
|
||||
@@ -1914,12 +1956,17 @@ REPLACE ALL OCCURRENCES OF PCRE `\s` IN some_string WITH `#`.
|
||||
|
||||
some_string = original_string.
|
||||
|
||||
"---------------- Classes ----------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Classes
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The result is the same as 'findings'
|
||||
DATA(regex_cl1) = cl_abap_regex=>create_pcre( pattern = `\s` )->create_matcher( text = some_string )->find_all( ).
|
||||
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Built-in Functions
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"---------------- Built-in Functions ----------------
|
||||
"2
|
||||
DATA(find_first_occ) = find( val = some_string pcre = `\s` ).
|
||||
|
||||
@@ -2459,11 +2506,13 @@ 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 ------------------------
|
||||
"-----------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& FIND and REPLACE statements
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"------------------------ IN CHARACTER MODE addition ------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& IN CHARACTER MODE addition
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Searching for the first blank in the string
|
||||
"3
|
||||
@@ -2494,7 +2543,9 @@ REPLACE ALL OCCURRENCES OF ` ` IN abc_str WITH `#` IN CHARACTER MODE.
|
||||
|
||||
abc_str = copy_str.
|
||||
|
||||
"------------------------ IN BYTE MODE addition ------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& IN BYTE MODE addition
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Converting to xstring
|
||||
"6162632064656620676869206A6B6C206D6E6F20707172207374752076777820797A
|
||||
@@ -2524,9 +2575,9 @@ abc_xstr = copy_xstr.
|
||||
"6162632364656623676869236A6B6C236D6E6F23707172237374752376777823797A
|
||||
REPLACE ALL OCCURRENCES OF blank_xstr IN abc_xstr WITH repl_xstr IN BYTE MODE.
|
||||
|
||||
"-----------------------------------------------------------------------------
|
||||
"--------------------------- CONCATENATE statements --------------------------
|
||||
"-----------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& CONCATENATE statements
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(part_str1) = `abc`.
|
||||
DATA(part_str2) = `def`.
|
||||
@@ -2560,9 +2611,9 @@ CONCATENATE LINES OF xstr_table INTO DATA(concat_xstr_tab) IN BYTE MODE.
|
||||
"abcdef
|
||||
DATA(concat_xstr_tab_converted) = cl_abap_conv_codepage=>create_in( )->convert( concat_xstr_tab ).
|
||||
|
||||
"-----------------------------------------------------------------------------
|
||||
"------------------------------- SHIFT statements ----------------------------
|
||||
"-----------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& SHIFT statements
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(str) = `abcdef`.
|
||||
DATA(copy) = str.
|
||||
@@ -2582,9 +2633,9 @@ DATA(xstr) = cl_abap_conv_codepage=>create_out( )->convert( str ).
|
||||
"6263646566
|
||||
SHIFT xstr IN BYTE MODE.
|
||||
|
||||
"-----------------------------------------------------------------------------
|
||||
"------------------------------- SPLIT statements ----------------------------
|
||||
"-----------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& SPLIT statements
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
str = `abc def`.
|
||||
|
||||
|
||||
@@ -301,8 +301,8 @@ an ABAP program using ABAP EML (which this cheat sheet and the examples focus on
|
||||
- [Structure of a RAP behavior definition](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencds_bdef.htm)
|
||||
- [Infos about BDL syntax](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbdl_syntax.htm)
|
||||
- [Infos about behavior definitions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbdl.htm)
|
||||
- [RAP BDL - Feature Tables](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/abenrap_feature_table.html)
|
||||
|
||||
|
||||
The following example shows a commented BDEF, and is just an excursion. Note that there is a wide variety of possible specifications and options. The example shows only a selection. The example shows multiple specifications with comments and also syntax hidden with comments, just for the sake of showing more syntax options. For full details, correct specification and combination options, refer to the ABAP Keyword Documentation. For example, it is not possible to specify operations multiple times and more.
|
||||
|
||||
```js
|
||||
@@ -1013,7 +1013,7 @@ is only relevant in the context of
|
||||
[draft](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbdl_with_draft.htm).
|
||||
|
||||
|
||||
The following table covers a selection of available BDEF derived type components. Find more details on the available components in section [Components of BDEF Derived Types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapderived_types_comp.htm).
|
||||
The following table covers a selection of available BDEF derived type components. Find more details on the available components in section [Components of BDEF Derived Types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapderived_types_comp.htm) of the ABAP Keyword Documentation.
|
||||
|
||||
<table>
|
||||
|
||||
@@ -1105,7 +1105,7 @@ MODIFY ENTITIES OF zdemo_abap_rap_ro_m
|
||||
|
||||
<td>
|
||||
|
||||
The code snippet visualizes various specification options regarding `%key` and `%tky` as component groups, emphasizing how contained component may be accessed and that these component groups can contain further component groups.
|
||||
The code snippet visualizes various specification options regarding `%key` and `%tky` as component groups, emphasizing how contained components may be accessed and that these component groups can contain further component groups.
|
||||
|
||||
``` abap
|
||||
MODIFY ENTITY zdemo_abap_rap_ro_m
|
||||
|
||||
@@ -448,7 +448,10 @@ The following ABAP keywords are available for interrupting and exiting loops:
|
||||
| [`EXIT`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapexit_loop.htm) | `EXIT.` | The loop is terminated completely. The program flow resumes after the closing statement of the loop. |
|
||||
|
||||
```abap
|
||||
"------------ CONTINUE ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& CONTINUE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA str_c TYPE string.
|
||||
DO 15 TIMES.
|
||||
"Continue with the next loop pass if the number is even
|
||||
@@ -462,7 +465,10 @@ DO 15 TIMES.
|
||||
ENDDO.
|
||||
"str_c: 1, 3, 5, 7, 9, 11, 13, 15
|
||||
|
||||
"------------ CHECK ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& CHECK
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA str_d TYPE string.
|
||||
DO 15 TIMES.
|
||||
"Terminating the loop pass and continuing with the next loop pass if the condition is
|
||||
@@ -481,7 +487,10 @@ DO 15 TIMES.
|
||||
ENDDO.
|
||||
"str_e: 1, 3, 5, 7, 9, 11, 13, 15
|
||||
|
||||
"------------ EXIT ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& EXIT
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA str_f TYPE string.
|
||||
DO 15 TIMES.
|
||||
"Terminating the entire loop
|
||||
@@ -636,7 +645,9 @@ TRY.
|
||||
...
|
||||
ENDTRY.
|
||||
|
||||
"---------- Dynamic function method calls ----------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic function method calls
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Function module name contained in a variable
|
||||
DATA(func_name) = 'SOME_FUNCTION_MODULE_C'.
|
||||
@@ -791,7 +802,9 @@ CLASS zcl_demo_abap_func_test IMPLEMENTATION.
|
||||
out->write( calculation_result_table ).
|
||||
out->write( |\n\n\n| ).
|
||||
|
||||
"----- Dynamic function module call ----
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Dynamic function module call
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(func_name) = 'Z_DEMO_ABAP_TEST_FUNC_M'.
|
||||
DATA(ptab) = VALUE abap_func_parmbind_tab( ( name = 'NUM1'
|
||||
|
||||
@@ -1822,7 +1822,10 @@ SELECT *
|
||||
[`FINAL`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenfinal_inline.htm).
|
||||
|
||||
```abap
|
||||
"--------------------- Constants --------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Constants
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"As mentioned above, constants cannot be changed at runtime.
|
||||
CONSTANTS con_str TYPE string VALUE `hallo`.
|
||||
|
||||
@@ -1836,7 +1839,10 @@ CONSTANTS: BEGIN OF const_struct,
|
||||
char TYPE c LENGTH 4 VALUE 'ABAP',
|
||||
END OF const_struct.
|
||||
|
||||
"--------------------- Immutable variables --------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Immutable variables
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
FINAL(do_final_inl) = 1.
|
||||
DATA(do_data_inl) = 1 + do_final_inl.
|
||||
"not possible
|
||||
@@ -2292,7 +2298,9 @@ See the conversion rules for the different data types here: [Assignment and Conv
|
||||
|
||||
|
||||
```abap
|
||||
"-------------------- Conversions --------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Conversions
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Implicit conversions of the types c and string
|
||||
DATA do_1_str TYPE string VALUE `abcdef`.
|
||||
@@ -2317,7 +2325,9 @@ DATA(do_7_i) = CONV i( do_6_dcfl34 ).
|
||||
"`10-`
|
||||
DATA(i2str) = CONV string( -10 ).
|
||||
|
||||
"-------------------- Compatibility --------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Compatibility
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"1. Source and target are compatible, all technical type properties
|
||||
" match
|
||||
|
||||
@@ -329,7 +329,10 @@ Example using `CL_ABAP_TX`:
|
||||
```abap
|
||||
...
|
||||
|
||||
"------------- Activating the modify transactional phase -------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Activating the modify transactional phase
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
cl_abap_tx=>modify( ).
|
||||
|
||||
"The following database modification statement is not allowed in the
|
||||
@@ -343,7 +346,10 @@ MODIFY zdemo_abap_carr FROM TABLE @( VALUE #(
|
||||
|
||||
...
|
||||
|
||||
"------------- Activating the save transactional phase -------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Activating the save transactional phase
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
cl_abap_tx=>save( ).
|
||||
|
||||
"In this phase, database modifications are allowed.
|
||||
|
||||
@@ -4322,7 +4322,6 @@ Overwriting line content and format<br><br>
|
||||
- Overwrites a line stored in the list buffer with the content of the `sy-lisel` system field
|
||||
- Allows additional modifications such as changing the value and format.
|
||||
- Find more information [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapmodify_line.htm).
|
||||
-
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
@@ -262,7 +262,9 @@ DATA(conv_string) = cl_abap_conv_codepage=>create_in( )->convert( xml_pa ).
|
||||
Creating XML data using sXML:
|
||||
|
||||
```abap
|
||||
"--------------------- Token-based rendering ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Token-based rendering
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"For sXML, there are specialized writer classes, such as CL_SXML_STRING_WRITE.
|
||||
"Writers created with this class render XML data to a byte string.
|
||||
@@ -322,7 +324,9 @@ DATA(xml) = CAST cl_sxml_string_writer( writer )->get_output( ).
|
||||
" </flight>
|
||||
"</flights>
|
||||
|
||||
"--------------------- Object-oriented rendering ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Object-oriented rendering
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(writer_oo) = CAST if_sxml_writer( cl_sxml_string_writer=>create( type = if_sxml=>co_xt_xml10
|
||||
encoding = 'UTF-8' ) ).
|
||||
@@ -379,7 +383,9 @@ DATA(xml_oo) = CAST cl_sxml_string_writer( writer_oo )->get_output( ).
|
||||
Parsing XML data using sXML:
|
||||
|
||||
```abap
|
||||
"--------------------- Token-based parsing ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Token-based parsing
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Creating demo XML data to be used in the example
|
||||
TRY.
|
||||
@@ -508,7 +514,9 @@ ENDTRY.
|
||||
*CO_NT_ELEMENT_CLOSE subnode3
|
||||
*CO_NT_ELEMENT_CLOSE node
|
||||
|
||||
"--------------------- Object-oriented parsing ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Object-oriented parsing
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The example uses the XML from above
|
||||
CLEAR nodes_tab.
|
||||
@@ -693,7 +701,10 @@ ENDTRY.
|
||||
There are multiple options. Check the executable example to explore them.
|
||||
|
||||
```abap
|
||||
"--------------------- Transforming XML data ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Transforming XML data
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Options for src:
|
||||
"- Data object of type string or xstring containing XML data in XML 1.0 format
|
||||
"- Standard table with flat character-like or byte-like line type
|
||||
@@ -702,7 +713,10 @@ There are multiple options. Check the executable example to explore them.
|
||||
CALL TRANSFORMATION ... SOURCE XML src
|
||||
RESULT ...
|
||||
|
||||
"--------------------- Transforming ABAP data ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Transforming ABAP data
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"No XML specified after SOURCE
|
||||
"Options after SOURCE:
|
||||
"- One or multiple ABAP data objects (abap1 in the snippet) can be specified as
|
||||
@@ -725,7 +739,10 @@ CALL TRANSFORMATION ... SOURCE (srctab)
|
||||
There are multiple options. Check the executable example to explore them in action.
|
||||
|
||||
```abap
|
||||
"--------------------- Transforming to XML data ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Transforming to XML data
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Options for res:
|
||||
"- Data object of type string or xstring
|
||||
"- Data object declared inline (e.g. DATA(a) or FINAL(b)), which has then the type xstring
|
||||
@@ -734,7 +751,10 @@ There are multiple options. Check the executable example to explore them in acti
|
||||
CALL TRANSFORMATION ... SOURCE ...
|
||||
RESULT XML res.
|
||||
|
||||
"--------------------- Transforming to ABAP data ----------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Transforming to ABAP data
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"No XML specified after RESULT
|
||||
"Similar to above, multiple ABAP data objects can be specified as a static parameter list.
|
||||
CALL TRANSFORMATION ... SOURCE ...
|
||||
@@ -1346,10 +1366,16 @@ For more information, see the class documentation. Note that there are many addi
|
||||
```abap
|
||||
DATA(some_table) = VALUE string_table( ( `aaa` ) ( `bbb` ) ( `ccc` ) ).
|
||||
|
||||
"--------- ABAP -> JSON ---------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& ABAP -> JSON
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(abap_to_json) = /ui2/cl_json=>serialize( data = some_table ).
|
||||
|
||||
"--------- JSON -> ABAP ---------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& JSON -> ABAP
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA json_to_abap_table TYPE string_table.
|
||||
/ui2/cl_json=>deserialize( EXPORTING json = abap_to_json
|
||||
CHANGING data = json_to_abap_table ).
|
||||
|
||||
@@ -131,7 +131,10 @@ DATA(tz_w_xco_utc) = xco_cp_time=>time_zone->utc->value.
|
||||
To retrieve the current date, you can, for example, use the `get_system_date` method of the `cl_abap_context_info` class. You can also use the [XCO library](https://help.sap.com/docs/btp/sap-business-technology-platform/xco-library?version=Cloud).
|
||||
|
||||
```abap
|
||||
"--------------------- Retrieving the current date --------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Retrieving the current date
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Retrieving the current date with respect to UTC, e.g. 20240101
|
||||
"The result's base type is the DDIC type dats that is mapped to the
|
||||
"ABAP type d.
|
||||
@@ -171,7 +174,10 @@ DATA(date_utc_tz) = xco_cp=>sy->date( xco_cp_time=>time_zone->utc
|
||||
)->as( xco_cp_time=>format->iso_8601_basic
|
||||
)->value.
|
||||
|
||||
"--------------------- Retrieving current date values (XCO) --------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Retrieving the current date values using XCO
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"e.g. 01
|
||||
DATA(day) = xco_cp=>sy->date( )->day.
|
||||
"e.g. 01
|
||||
@@ -179,7 +185,10 @@ DATA(month) = xco_cp=>sy->date( )->month.
|
||||
"e.g. 2024
|
||||
DATA(year) = xco_cp=>sy->date( )->year.
|
||||
|
||||
"--------------------- Creating dates --------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Creating dates
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA date_cr1 TYPE d.
|
||||
date_cr1 = '20240101'.
|
||||
DATA date_cr2 TYPE d VALUE '20240202'.
|
||||
@@ -338,7 +347,9 @@ DATA(weekday2) = ( 5 + date_calc_3 MOD 7 ) MOD 7 + 1. "6 (Saturday)
|
||||
DATA(date_w_first_day_of_month) = CONV d( replace( val = `202403020` off = 6 len = 2 with = `01` ) ). "20240301
|
||||
DATA(date_w_last_day_of_prev_month) = CONV d( date_w_first_day_of_month - 1 ). "20240229
|
||||
|
||||
"------------ Performing date additions and subtractions using the XCO library ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Performing date additions and subtractions using the XCO library
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Adding days to the current date using the 'add' method
|
||||
"e.g. 2024-03-16 (if the current date is 2024-03-11)
|
||||
@@ -498,7 +509,9 @@ The code snippet below provides examples of time processing, such as retrieving
|
||||
### Retrieving the Current Time
|
||||
|
||||
```abap
|
||||
"--------------------- Retrieving the current time --------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Retrieving the current time
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Retrieving the current time in UTC, e.g. 152450
|
||||
DATA(utc_time) = cl_abap_context_info=>get_system_time( ).
|
||||
@@ -541,8 +554,6 @@ DATA(time_utc_tz) = xco_cp=>sy->time( xco_cp_time=>time_zone->utc
|
||||
### Accessing Time Values
|
||||
|
||||
```abap
|
||||
"--------------------- Accessing time values --------------------
|
||||
|
||||
"Note: As mentioned in a previous section on dates, the access to time fields
|
||||
"works similar as date fields. As an example, seconds, minutes, and hours are
|
||||
"extracted from a time field.
|
||||
@@ -573,8 +584,6 @@ DATA(hr_w_xco) = xco_cp=>sy->time( xco_cp_time=>time_zone->user )->hour.
|
||||
### Creating Time Values
|
||||
|
||||
```abap
|
||||
"--------------------- Creating times --------------------
|
||||
|
||||
DATA time_cr1 TYPE t.
|
||||
time_cr1 = '095812'.
|
||||
DATA time_cr2 TYPE t VALUE '112400'.
|
||||
@@ -598,7 +607,9 @@ DATA(seconds_from_time) = xco_time->second. "05
|
||||
### Performing Time Calculations
|
||||
|
||||
```abap
|
||||
"------------ Performing time calculations ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Performing time calculations
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Retrieving seconds, minutes, and hours from a time value in a data object
|
||||
"of type t
|
||||
@@ -623,7 +634,9 @@ DATA(time_xco_subtr) = xco_cp=>sy->time( xco_cp_time=>time_zone->user
|
||||
)->as( xco_cp_time=>format->iso_8601_extended
|
||||
)->value.
|
||||
|
||||
"------------ Calculating the time delta between two time values ------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Calculating the time delta between two time values
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA: time1 TYPE t VALUE '210000',
|
||||
time2 TYPE t VALUE '040000'.
|
||||
@@ -647,7 +660,10 @@ DATA(time2_conv2i) = CONV i( time2 ).
|
||||
ASSERT time2_conv2i = ( 04 * 3600 ) + ( 00 * 60 ) + 00.
|
||||
ASSERT time2_conv2i - time1_conv2i = time_diff.
|
||||
|
||||
"---- Calculating the total values of the time difference in seconds, minutes and hours ----
|
||||
*&----------------------------------------------------------------------------------*
|
||||
*& Calculating the total values of the time difference in seconds, minutes and hours
|
||||
*&----------------------------------------------------------------------------------*
|
||||
|
||||
"The MOD operator is used and works in a way that the positive remainder
|
||||
"of the division of the left operand by the right is returned. Therefore,
|
||||
"it is irrelevant whether the time difference value is either positive or
|
||||
@@ -730,8 +746,6 @@ DATA(hours_no_div_dec) = CONV decfloat34( ( ( time2 - time1 ) MOD 86400 ) / 3600
|
||||
### CL_ABAP_TIMEFM: Converting Time Values
|
||||
|
||||
```abap
|
||||
"------------ Conversions with the CL_ABAP_TIMEFM class ------------
|
||||
|
||||
"Using the CL_ABAP_TIMEFM class, you can perform conversions with external
|
||||
"and internal representations of a time, e.g. conversion of a time in a data
|
||||
"object of type string to type t and vice versa. Multiple methods are available,
|
||||
@@ -825,7 +839,9 @@ DATA(ts_utc_tz) = xco_cp=>sy->moment( xco_cp_time=>time_zone->utc
|
||||
#### Creating/Modifying a Time Stamp
|
||||
|
||||
```abap
|
||||
"--------------------- Creating time stamps --------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Creating time stamps
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA ts7 TYPE utclong.
|
||||
ts7 = utclong_current( ).
|
||||
@@ -844,7 +860,9 @@ DATA(ts10) = xco_cp_time=>moment( iv_year = '2024'
|
||||
)->as( xco_cp_time=>format->iso_8601_extended
|
||||
)->value.
|
||||
|
||||
"--------------------- Modifying time stamps (XCO) --------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& Modifying time stamps (XCO)
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"As covered for date and time types, you can modify time stamps using string
|
||||
"processing functionalities. They are not covered here. XCO provides, for
|
||||
|
||||
@@ -276,9 +276,9 @@ Syntax examples for raising exceptions programmatically:
|
||||
> More variants of the statements shown are possible. They are covered in a [separate section below](#syntax-variants-of-raise-exceptionthrow) because they relate to topics covered in the following sections.
|
||||
|
||||
```abap
|
||||
"-------------------------------------------------------------------
|
||||
"----------------- RAISE EXCEPTION statements ----------------------
|
||||
"-------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& RAISE EXCEPTION statements
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"RAISE EXCEPTION statement with the TYPE addition, specifying
|
||||
"the name of a visible exception class; an exception
|
||||
@@ -307,9 +307,9 @@ DATA dyn_exc TYPE REF TO cx_root.
|
||||
CREATE OBJECT dyn_exc TYPE ('CX_SY_ZERODIVIDE').
|
||||
RAISE EXCEPTION dyn_exc.
|
||||
|
||||
"-------------------------------------------------------------------
|
||||
"----------- COND/SWITCH operators with THROW addition -------------
|
||||
"-------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& COND/SWITCH operators with THROW addition
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"THROW addition in conditional expressions with the COND and SWITCH operators
|
||||
"enabling raising class-based exceptions in operand positions
|
||||
@@ -651,9 +651,10 @@ DO 2 TIMES.
|
||||
ENDTRY.
|
||||
ENDDO.
|
||||
|
||||
"----------------------------------------------------------------------------
|
||||
"----------------------- INTO addition --------------------------------------
|
||||
"----------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& INTO addition
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"The example is the same as above. Here, the CLEANUP statement is specified
|
||||
"with the addition INTO. If required, you can evaluate the exception information
|
||||
"as shown above.
|
||||
@@ -785,9 +786,10 @@ CLASS zcl_demo_abap IMPLEMENTATION.
|
||||
|
||||
METHOD if_oo_adt_classrun~main.
|
||||
|
||||
"----------------------------------------------------------------------------
|
||||
"----------------------- CATCH BEFORE UNWIND -------------------------------
|
||||
"----------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& CATCH BEFORE UNWIND
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Example using the method
|
||||
"The following example creates a table containing integers from -5 to 5. This
|
||||
"table is looped across to have different values for divisions. Here, this
|
||||
@@ -983,9 +985,9 @@ msgv4 = sy-msgv4. "H
|
||||
> - In the executable example, `zcx_demo_abap_error_a` implements the `IF_T100_MESSAGE` interface and `zcx_demo_abap_error_b` implements `IF_T100_DYN_MSG`.
|
||||
|
||||
```abap
|
||||
"----------------------------------------------------------------------------
|
||||
"------------------- RAISE EXCEPTION statements ----------------------------
|
||||
"----------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& RAISE EXCEPTION statements
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
"Multiple additions and variants are possible. The following examples
|
||||
"demonstrate a selection.
|
||||
@@ -1101,9 +1103,10 @@ RAISE EXCEPTION TYPE zcx_demo_abap_error_b MESSAGE ID sy-msgid
|
||||
NUMBER sy-msgno
|
||||
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
|
||||
|
||||
"----------------------------------------------------------------------------
|
||||
"------------------- COND operator, THROW addition -------------------------
|
||||
"----------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& COND operator, THROW addition
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(flag) = 'X'.
|
||||
|
||||
"Specifying the exception class after THROW including a mandatory pair of parentheses
|
||||
@@ -1151,9 +1154,10 @@ MESSAGE e005(zdemo_abap_messages) WITH 'Some message' INTO DATA(msg6).
|
||||
DATA(cond_w_throw_8) = COND #( WHEN flag IS INITIAL THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_b( USING MESSAGE ) ).
|
||||
|
||||
"----------------------------------------------------------------------------
|
||||
"------------------- SWITCH operator, THROW addition ----------------------
|
||||
"----------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& SWITCH operator, THROW addition
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(switch_w_throw_1) = SWITCH #( flag WHEN '' THEN `works`
|
||||
ELSE THROW zcx_demo_abap_error_a( ) ).
|
||||
|
||||
|
||||
@@ -819,9 +819,9 @@ string_cond_pattern = replace( val = `cd` pcre = `(ab)?cd` with = `${1:-yz}cd` )
|
||||
The following example demonstrates a selection of syntax options with `FIND` and `REPLACE`. There are multiple options as there is a rich variety of additions. For more details, refer to the [String Processing](07_String_Processing.md) cheat sheet.
|
||||
|
||||
```abap
|
||||
"-----------------------------------------------------------------------------
|
||||
"------------------------------- FIND ----------------------------------------
|
||||
"-----------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& FIND
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(str) = `Cathy's black cat on the mat played with Matt.`.
|
||||
|
||||
@@ -943,9 +943,9 @@ ASSERT url_parts = url_parts_for_loop.
|
||||
*abap-concepts
|
||||
*controlled-sap-luw
|
||||
|
||||
"-----------------------------------------------------------------------------
|
||||
"------------------------------- REPLACE -------------------------------------
|
||||
"-----------------------------------------------------------------------------
|
||||
*&---------------------------------------------------------------------*
|
||||
*& REPLACE
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
DATA(str_replace) = `ab apppc app`.
|
||||
DATA(str_replace_copy) = str_replace.
|
||||
|
||||
@@ -30,7 +30,7 @@ This cheat sheet explores various aspects of numeric operations and calculations
|
||||
- Calculations use numeric data objects or those convertible to numeric types.
|
||||
- ABAP supports specific elementary numeric data types.
|
||||
- These types have distinct characteristics and value ranges, allowing the use for various purposes.
|
||||
- This cheat sheet covers only [built-in ABAP types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuiltin_abap_type_glosry.htm). [Built-in DDIC types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuiltin_ddic_type_glosry.htm) are also available for defining types in the [ABAP Dictionary DDIC)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_dictionary_glosry.htm) and ABAP CDS. These types cannot be used directly in ABAP programs except for typed literals. They are mapped to built-in ABAP types; for example, the DDIC type `INT4` is mapped to type `i`, and `DECFLOAT16` is mapped to the built-in ABAP type `decfloat16`.
|
||||
- This cheat sheet covers only [built-in ABAP types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuiltin_abap_type_glosry.htm). [Built-in DDIC types](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenbuiltin_ddic_type_glosry.htm) are also available for defining types in the [ABAP Dictionary (DDIC)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenabap_dictionary_glosry.htm) and ABAP CDS. These types cannot be used directly in ABAP programs except for typed literals. They are mapped to built-in ABAP types; for example, the DDIC type `INT4` is mapped to type `i`, and `DECFLOAT16` is mapped to the built-in ABAP type `decfloat16`.
|
||||
- Most types' values (except type `i`) cannot be directly specified in the program and must be represented by character literals interpretable as the respective type.
|
||||
|
||||
<table>
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
|
||||
This cheat sheet focuses on `WHERE` conditions and explores various syntax options in ABAP statements that include `WHERE` for data filtering. This is relevant, for example, when retrieving data from a data source using ABAP SQL or when processing internal tables with ABAP statements. For all details and syntax options, refer to the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/ABENABAP.html). Several aspects and code snippets in this cheat sheet are also available in other cheat sheets.
|
||||
|
||||
> **💡 Note**<br>
|
||||
> - Most examples in the cheat sheet use internal tables as data sources for ABAP SQL `SELECT` statements to have self-contained examples. Use `SELECT` with internal tables as data sources only when SQL functionalities like joins exceed ABAP statements. For more details, refer to the [Internal Tables](01_Internal_Tables.md) cheat sheet.
|
||||
> - Some examples also use artifacts from the ABAP cheat sheet repository. To check out these examples, ensure you have imported the ABAP cheat sheet repository into your system.
|
||||
|
||||
<p align="right"><a href="#top">⬆️ back to top</a></p>
|
||||
|
||||
## WHERE Conditions in ABAP SQL Statements
|
||||
@@ -626,7 +630,7 @@ To try the example out, create a demo class named `zcl_demo_abap` and paste the
|
||||
|
||||
> **💡 Note**<br>
|
||||
> - Many ABAP SQL `SELECT` statements in the example use an internal table as the data source to work with simple data.
|
||||
> - Some examples also use subqueries. In these cases, another internal table cannot serve as the data source in the subquery. Therefore, examples use demo database tables from the ABAP cheat repository. They are also used to demonstrate `IS [NOT] NULL`. As a prerequisite, you have imported the ABAP cheat sheet repository to run the example class.
|
||||
> - Some examples also use subqueries. In these cases, another internal table cannot currently serve as the data source in the subquery. Therefore, examples use demo database tables from the ABAP cheat repository. They are also used to demonstrate `IS [NOT] NULL`. As a prerequisite, you have imported the ABAP cheat sheet repository to run the example class.
|
||||
|
||||
|
||||
```abap
|
||||
|
||||
@@ -38,7 +38,7 @@ ABAP cheat sheets[^1] ...
|
||||
- are enriched by links to glossary entries and chapters of the **ABAP Keyword Documentation** (the *F1 help*) and more for you to deep dive into the respective ABAP topics and get more comprehensive information.
|
||||
|
||||
<details>
|
||||
<summary>💡 Note</summary>
|
||||
<summary>🟢 Click to expand for more information</summary>
|
||||
<br>
|
||||
|
||||
- Since the ABAP cheat sheets provide information in a nutshell, they do not claim to be fully comprehensive as far as the described syntax and concepts are concerned. If you need more details, you can always consult the ABAP Keyword Documentation, for example, by choosing *F1* on a keyword in your code, or by searching directly using the online or the system-internal version.
|
||||
@@ -54,6 +54,7 @@ ABAP cheat sheets[^1] ...
|
||||
- The code snippets in the ABAP cheat sheet documents and the executable examples include many comments. While it is generally not recommended to overuse comments in your code, they are used here to explain and provide context directly where it is needed. In many cases, they illustrate the results of ABAP statements.
|
||||
- As previously mentioned, the cheat sheet documents and examples primarily focus on syntax options. Most of the executable examples, code snippets, names of data objects, classes, methods, interfaces, etc., are nonsemantic.
|
||||
- Many ABAP statements allow additions in various orders, and these orders are not always fixed.
|
||||
|
||||
</details>
|
||||
|
||||
<br>
|
||||
|
||||
Reference in New Issue
Block a user