diff --git a/01_Internal_Tables.md b/01_Internal_Tables.md index 1a799c7..9f9d8e1 100644 --- a/01_Internal_Tables.md +++ b/01_Internal_Tables.md @@ -17,7 +17,7 @@ - [NEW Operator](#new-operator) - [Example: Exploring Populating Internal Tables](#example-exploring-populating-internal-tables) - [Reading Single Lines from Internal Tables](#reading-single-lines-from-internal-tables) - - [Determining the Target Area when Reading Single Lines](#determining-the-target-area-when-reading-single-lines) + - [Determining the Target Area when Reading Single Lines in READ TABLE Statements](#determining-the-target-area-when-reading-single-lines-in-read-table-statements) - [Reading a Single Line by Index](#reading-a-single-line-by-index) - [Reading a Single Line Using Table Keys](#reading-a-single-line-using-table-keys) - [Reading a Single Line Using a Free Key](#reading-a-single-line-using-a-free-key) @@ -1108,7 +1108,7 @@ There are three different ways to specify the line to read: The following code snippets include [`READ TABLE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapread_table.htm) statements and [table expressions](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abentable_expressions.htm) to read from internal tables. -### Determining the Target Area when Reading Single Lines +### Determining the Target Area when Reading Single Lines in READ TABLE Statements - Copying a line to a data object using the addition `INTO`. After the copying, the line found exists separately in the internal table and @@ -1151,7 +1151,7 @@ The following code snippets include [`READ TABLE`](https://help.sap.com/doc/abap READ TABLE itab REFERENCE INTO DATA(dref_inl) ... ``` -**Which to use then?** Since all syntax options provide the same +**Which to use then?** Since all syntax options basically provide similar functionality, your use case, the performance or readability of the code may play a role. For more information, see the programming guidelines for the [target @@ -3278,9 +3278,8 @@ ENDCLASS. ### Improving Read Performance with Secondary Table Keys -The following example creates two demo internal tables. One without a secondary -table key and the other with a secondary table key. Consider a scenario where you -have a standard internal table without a secondary table key, and you want to add a secondary table key later to improve read performance. The tables are populated with a lot of data. Then, in a `DO` loop, many reads are performed on the internal tables. One example uses a free key for the read, the other uses a secondary table key that includes the components used for the free key search. Before and after the reads, the current timestamp is stored in variables, from which the elapsed time is calculated. There should be a significant delta of the elapsed time. +Consider a scenario where you have a standard internal table, and you frequently access its content using a free key. The table is declared without a secondary table key. You can add a secondary table key to improve read performance. +The following example creates two demo internal tables. One without a secondary table key and the other with a secondary table key. The tables are populated with a lot of data. Then, in a `DO` loop, many reads are performed on the internal tables. One example uses a free key for the read, the other uses a secondary table key that includes the components used for the free key search. Before and after the reads, the current timestamp is stored in variables, from which the elapsed time is calculated. There should be a significant delta of the elapsed time. ```abap CLASS zcl_some_class DEFINITION PUBLIC FINAL CREATE PUBLIC. diff --git a/02_Structures.md b/02_Structures.md index ad3baf3..7936460 100644 --- a/02_Structures.md +++ b/02_Structures.md @@ -13,9 +13,8 @@ - [Using the CORRESPONDING Operator and MOVE-CORRESPONDING Statements](#using-the-corresponding-operator-and-move-corresponding-statements) - [Clearing Structures](#clearing-structures) - [Processing Structures](#processing-structures) - - [Excursions](#excursions) - - [Including Structures](#including-structures) - - [Getting Structured Type Information and Creating Structures at Runtime](#getting-structured-type-information-and-creating-structures-at-runtime) + - [Including Structures](#including-structures) + - [Getting Structured Type Information and Creating Structures at Runtime](#getting-structured-type-information-and-creating-structures-at-runtime) - [Executable Example](#executable-example) ## Introduction @@ -727,9 +726,7 @@ MODIFY TABLE itab FROM struc.

⬆️ back to top

-## Excursions - -### Including Structures +## Including Structures - [`INCLUDE TYPE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapinclude_type.htm) and [`INCLUDE STRUCTURE`](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abapinclude_type.htm) statements @@ -771,7 +768,7 @@ TYPES END OF address_type.

⬆️ back to top

-### Getting Structured Type Information and Creating Structures at Runtime +## Getting Structured Type Information and Creating Structures at Runtime Using [Runtime Type Services (RTTS)](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenrun_time_type_services_glosry.htm "Glossary Entry") you can ... diff --git a/17_SAP_LUW.md b/17_SAP_LUW.md index ccafcb7..57d006e 100644 --- a/17_SAP_LUW.md +++ b/17_SAP_LUW.md @@ -15,7 +15,8 @@ ## Introduction -⚠️ The concept is relevant to both ABAP Cloud and classic ABAP, but some of the statements covered in the cheat sheet and the executable example are only relevant to [classic ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenclassic_abap_glosry.htm). +> **💡 Note**
+> The concept is relevant to both ABAP Cloud and classic ABAP, but some of the statements covered in the cheat sheet and the executable example are only relevant to [classic ABAP](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenclassic_abap_glosry.htm). This cheat sheet provides a high-level overview of the [SAP LUW](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_luw_glosry.htm) concept that deals with data consistency with a focus on SAP LUW-related statements, supported by an executable example to check the syntax in action. diff --git a/22_Misc_ABAP_Classes.md b/22_Misc_ABAP_Classes.md index 2c7acdd..7e6648a 100644 --- a/22_Misc_ABAP_Classes.md +++ b/22_Misc_ABAP_Classes.md @@ -2387,248 +2387,8 @@ ENDTRY.
  • For creating a client object using an HTTP destination. The HTTP destination is provided based on an HTTP destination object. The latter can be created, among others, based on a communication arrangement or a plain URL.
  • For more information, refer to the class documentation and the topic Integration and Connectivity.
  • -
  • To check out the classes in an example, expand the collapsible section below.
  • -
    - Expand to view an example - - - - -
    - -``` abap -CLASS zcl_some_class DEFINITION PUBLIC FINAL CREATE PUBLIC. - PUBLIC SECTION. - INTERFACES if_oo_adt_classrun. - PRIVATE SECTION. - CONSTANTS url_cs TYPE string VALUE `https://api.github.com/repos/SAP-samples/abap-cheat-sheets/git/trees/main`. - CONSTANTS url_gh TYPE string VALUE `https://raw.githubusercontent.com/SAP-samples/abap-cheat-sheets/main/`. - CONSTANTS url_api TYPE string VALUE `https://api.github.com/markdown`. - DATA url TYPE string. - TYPES: BEGIN OF s, - file_name TYPE string, - title TYPE string, - code_snippets TYPE string_table, - error TYPE abap_boolean, - END OF s. - DATA tab TYPE TABLE OF s WITH EMPTY KEY. - DATA snippets TYPE string_table. - DATA html TYPE string. -ENDCLASS. -CLASS zcl_some_class IMPLEMENTATION. - METHOD if_oo_adt_classrun~main. - TRY. - "Creating a client object using a destination - "In the example, the HTTP destination is created using a plain URL. - "Here, a GitHub API is used to retrieve file names of the ABAP cheat sheet repository. - DATA(http_client) = cl_web_http_client_manager=>create_by_http_destination( i_destination = cl_http_destination_provider=>create_by_url( i_url = url_cs ) ). - "Sending an HTTP GET request and returning the response - "In the example, the HTTP body is retrieved as string data. - DATA(response) = http_client->execute( if_web_http_client=>get )->get_text( ). - CATCH cx_root INTO DATA(err). - out->write( err->get_text( ) ). - ENDTRY. - IF err IS INITIAL. - "Markdown file names are contained in the returned string in a specific - "pattern. In the following code, the markdown file names are extracted - "using a regular expression (pattern: "path":"04_ABAP_Object_Orientation.md") - "After '"path":"' (not including this part, indivated by \K), two - "digits must follow. Then, the further file name is captured with a - "non-greedy capturing up to '.md'. - FIND ALL OCCURRENCES OF PCRE `("path":")\K\d\d.*?\.md` IN response - RESULTS DATA(results) - IGNORING CASE. - - "The 'results' internal table contains all findings and includes their - "offset and length information. - "Using a loop, the actual file names are extracted from the 'response' - "string and added to an internal table that is to receive more information - "in the code below. - LOOP AT results REFERENCE INTO DATA(md). - tab = VALUE #( BASE tab ( file_name = substring( val = response off = md->offset len = md->length ) ) ). - ENDLOOP. - SORT tab BY file_name ASCENDING. - - "In the following loop, the raw markdown content is retrieved using an HTTP GET request, also - "by creating a client object and using a destination (another plain URL). The URL is constructed - "using the constant value plus the markdown file that was retrieved before. - LOOP AT tab REFERENCE INTO DATA(cs). - url = url_gh && cs->file_name. - TRY. - http_client = cl_web_http_client_manager=>create_by_http_destination( i_destination = cl_http_destination_provider=>create_by_url( i_url = url ) ). - DATA(raw_md) = http_client->execute( if_web_http_client=>get )->get_text( ). - "Putting the long string that was retrieved in an internal table of type string - "for further processing (extracting the code snippets). - SPLIT raw_md AT |\n| INTO TABLE snippets. - DATA(flag) = ''. - "In the loop, all content from the markdown that is not part of a code - "snippet (indicated by the triple ```) is deleted. - "The replacements with dummy content in the loop are only done so that - "the POST request further down can work with the provided content - "(i.e. avoiding issues with characters such as "; they are inserted later again). - LOOP AT snippets REFERENCE INTO DATA(line). - DATA(tabix) = sy-tabix. - FIND PCRE '^\s*```' IN line->*. - IF sy-subrc = 0 AND flag = ''. - line->* = `%%%--START--%%%%`. - flag = 'X'. - ELSEIF sy-subrc = 0 AND flag = 'X'. - line->* = `%%%--END--%%%%`. - flag = ''. - ELSEIF flag <> 'X'. - DELETE snippets INDEX tabix. - ELSE. - FIND PCRE `^\s*"` IN line->*. - IF sy-subrc = 0. - DATA(comment1) = 'X'. - ENDIF. - FIND PCRE `^\*` IN line->*. - IF sy-subrc = 0. - DATA(comment2) = 'X'. - ENDIF. - FIND `***********************************************************************` - IN line->*. - IF sy-subrc = 0. - DATA(divider) = 'X'. - ENDIF. - IF comment1 = 'X' OR comment2 = 'X' OR divider = 'X'. - DELETE snippets INDEX tabix. - CLEAR: comment1, comment2, divider. - ELSE. - REPLACE ALL OCCURRENCES OF `"` IN line->* WITH `§§§§§`. - REPLACE ALL OCCURRENCES OF `\` IN line->* WITH `%%%%%`. - ENDIF. - ENDIF. - ENDLOOP. - "Adding the code snippets to the information table - cs->code_snippets = snippets. - CLEAR snippets. - CATCH cx_root INTO err. - cs->error = abap_true. - ENDTRY. - DELETE ADJACENT DUPLICATES FROM cs->code_snippets COMPARING table_line. - ENDLOOP. - "Creating the final html to be displayed - LOOP AT tab REFERENCE INTO cs WHERE code_snippets IS NOT INITIAL AND error = abap_false. - LOOP AT cs->code_snippets REFERENCE INTO DATA(code). - tabix = sy-tabix. - IF code->* = `%%%--START--%%%%`. - code->* = |```|. - ENDIF. - IF code->* = `%%%--END--%%%%`. - code->* = |```|. - INSERT `*****************` && |\\n| - INTO cs->code_snippets INDEX tabix + 1. - ENDIF. - code->* = code->* && |\\n|. - ENDLOOP. - "For the POST request, concatenating the string table to a single string. - DATA(code_string) = concat_lines_of( table = cs->code_snippets ). - TRY. - "Another creation of a client object using a destination - "This example deals with a POST request. - http_client = cl_web_http_client_manager=>create_by_http_destination( i_destination = cl_http_destination_provider=>create_by_url( i_url = url_api ) ). - DATA(request) = http_client->get_http_request( ). - request->set_text( `{"text":"` && code_string && `"}` ). - request->set_header_fields( VALUE #( ( name = 'Accept' value = 'application/vnd.github+json' ) ) ). - DATA(post) = http_client->execute( if_web_http_client=>post ). - DATA(status) = post->get_status( ). - IF status-code <> 200. - cs->error = abap_true. - DATA(status_error) = |Post request error: { status-code } / { status-reason }|. - ELSE. - "Retrieving the created html code - DATA(html_code) = post->get_text( ). - REPLACE ALL OCCURRENCES OF `§§§§§` IN html_code WITH `"`. - REPLACE ALL OCCURRENCES OF `%%%%%` IN html_code WITH `\`. - REPLACE ALL OCCURRENCES OF PCRE `()(\w.*)` IN html_code WITH `$1 $2`. - ENDIF. - CATCH cx_root INTO DATA(error). - cs->error = abap_true. - ENDTRY. - "Preparing the title for expandable sections - DATA(title) = cs->file_name. - REPLACE ALL OCCURRENCES OF `_` IN title WITH ` `. - REPLACE PCRE `^..` IN title WITH ``. - REPLACE `.md` IN title WITH ``. - "Assembling expandable sections - html = html && - `
    ` && - ` ` && title && `` && - COND #( WHEN cs->error = abap_false THEN html_code ELSE COND #( WHEN error IS INITIAL THEN status_error ELSE error->get_text( ) ) ) && - `
    `. - ENDLOOP. - "Providing the html skeleton and inserting the assembled expandable sections from above - DATA(final_html) = - `` && - `` && - `` && - `ABAP Cheat Sheet Code Snippets` && - `` && - `` && - `` && - `

    ABAP Cheat Sheet Code Snippets

    ` && - `https://github.com/SAP-samples/abap-cheat-sheets

    ` && - html && - `` && - `` && - ``. - "Displaying the html result in the ADT console - "Note: Before running the class, clear the ADT console. - "When the html code is displayed in the ADT console, you can, for example, - "create a file named ABAP_cheat_sheet_code.html on your local machine. - "Open the file in an editor, copy & paste the entire ADT console content and - "save the local file. In doing so, you have various code snippets at your - "disposal offline. - out->write( final_html ). - ENDIF. - ENDMETHOD. -ENDCLASS. -``` -
    - -