This is a test message to test the length of the message box.
Login
New ABAP internal tables example
Created by Software-Heroes

ABAP - Internal tables (example)

Performance when accessing internal tables may vary depending on access. How to check your data and the times, we'll show you in this article.

Advertising

In the previous articles we talked about performance and access. Today we want to clarify the question with you, which of the accesses is faster or easier and how you can measure it for yourself.

 

Preparation

To prepare the test, we define the tables for access. Each individual table is used for access and represents an access type for us.


" Tables definition
DATA:
  ld_tab   TYPE string,
  lt_sttab TYPE STANDARD TABLE OF t001,
  lt_sotab TYPE SORTED TABLE OF t001 WITH UNIQUE KEY bukrs,
  lt_hatab TYPE HASHED TABLE OF t001 WITH UNIQUE KEY bukrs,
  lt_bitab TYPE STANDARD TABLE OF t001,
  lt_ketab TYPE STANDARD TABLE OF t001 WITH NON-UNIQUE SORTED KEY sec COMPONENTS bukrs.

 

Then we read the data for our access from the T001 (company codes). In this case, it is sufficient to read all entries and then move them, because we want to read against all entries.


" Select data
SELECT *
 FROM t001
 INTO TABLE @lt_sttab.

" Move data
lt_sotab = lt_sttab.
lt_hatab = lt_sttab.
lt_bitab = lt_sttab.
SORT lt_bitab BY bukrs.
lt_ketab = lt_sttab.

The table lt_bitab is a standard table, so we should sort the table to the defined key, otherwise we can not be sure that the table really has the right sort after data selection.

 

Execution

For our test we have prepared six cases that we would like to test:

  • Standard table
  • Sorted table
  • Hash table
  • Read with binary search
  • Standard table with secondary key without usage
  • Standard table with secondary key with usage

" Processing methods
DO 6 TIMES.
  DATA(ld_index) = sy-index.

  " Start measurement
  GET RUN TIME FIELD DATA(ld_start).
  LOOP AT lt_sttab INTO DATA(ls_data).

    " Choose method
    CASE ld_index.
      WHEN 1.
        ld_tab = 'Standard'.
        DATA(ls_bukrs) = lt_sttab[ bukrs = ls_data-bukrs ].

      WHEN 2.
        ld_tab = 'Sorted'.
        ls_bukrs = lt_sotab[ bukrs = ls_data-bukrs ].

      WHEN 3.
        ld_tab = 'Hashed'.
        ls_bukrs = lt_hatab[ bukrs = ls_data-bukrs ].

      WHEN 4.
        ld_tab = 'BinarySearch'.
        READ TABLE lt_bitab INTO ls_bukrs
         WITH KEY bukrs = ls_data-bukrs
         BINARY SEARCH.

      WHEN 5.
        ld_tab = 'SecondaryKey ohne Angabe'.
        ls_bukrs = lt_ketab[ bukrs = ls_data-bukrs ].

      WHEN 6.
        ld_tab = 'SecondaryKey mit Angabe'.
        ls_bukrs = lt_ketab[ KEY sec COMPONENTS bukrs = ls_data-bukrs ].

    ENDCASE.

  ENDLOOP.

  " Finish measurement
  GET RUN TIME FIELD DATA(ld_end).
  WRITE: / |Messung { ld_tab }: { ld_end - ld_start }|.
ENDDO.

 

Using Get Runtime, we read the used time at the beginning and at the end and compare the result.

 

Result

As we described in the last article, the accesses with defined keys or the Binary Search are the fastest. In addition the result after the execution of the report (with approx. 4500 data records) in three different runs, in order to better represent the varying result.

 

Conclusion

When accessing internal tables, you should always make sure that you have also defined the correct key or that the table does not contain many records. However, as our tests have shown, it does not really matter what kind of key you use, the main thing is that it is defined at all.


Included topics:
New ABAPInternal tablesExample
Comments (0)
Advertising

ABAP - Performance for the SELECT

Category - ABAP

In this article we will look at a few special cases with the SELECT and examine the performance of these constructs. We'll show you the current alternatives and give you little tips while reading.

04/02/2021

ABAP - Check objects (Instances)

Category - ABAP

In this article we will show you how you can analyze instances and react to them correctly, for example if you hand them over during processing and want to react individually.

03/19/2021

ABAP - Loops

Category - ABAP

With New ABAP, new loops and possibilities for restricting table contents were created. We'll take a closer look at these new commands in this article.

02/19/2021

ABAP - Comparison

Category - ABAP

Today we'll look at comparisons and comparison operators in terms of the new commands and their current usage. What has changed so far and what should still be done?

02/12/2021

ABAP - String Functions (Part 3)

Category - ABAP

This article is about other new string functions and a replacement for CONDENSE. We would like to show you why you should use the new functions.

01/22/2021

We use cookies for our services and functions. More informations