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)

388

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.



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)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP - Type Casting

Category - ABAP

How do you actually get the original type of a class or instance if it is passed in a generic table? In this article we examine the possibilities.

04/16/2024

ABAP - RETURN value

Category - ABAP

After all these years, the “real” return in ABAP has finally arrived. In this article we will show you how it works and what it can do.

02/13/2024

ABAP Deep Dive - FOR (Loops)

Category - ABAP

Let's take a closer look at the FOR loop. How does it work? What do I have to consider and what can I do with it?

04/14/2023

ABAP Deep Dive - Table access (internal)

Category - ABAP

In this article, let's take a look at table access to internal tables and how they replace READ TABLE.

02/03/2023

ABAP Developer still relevant

Category - ABAP

In this article we look at whether ChatGPT can already replace an ABAP developer or whether it can be used as a help in everyday life.

01/06/2023