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

ABAP - Internal tables (read)

6415

New functions and commands have been implemented for accessing internal tables. How these work and what to consider, we show you here.

Advertising


Previously, internal tables were always read and evaluated via READ TABLE, which has changed somewhat with the new way of ABAP. Of course, what you knew so far is not outdated, but there are a few shorter ways to get the data in the tables.

In today's article, we want to focus on the different access methods, what you should look for, and how exactly the accesses work.

 

Read over the index

A common method is to read the first or last line of an internal table. To do this, use the index of the table to read the correct line. Whether if the entry was found, you have to check with the subrc.

The new version reads the index like reading an array in other languages. You access the index directly. But beware, if the line does not exist, because then an exception is raised and if this is not catched, then the report creates a short dump.


DATA:
  lt_t001 TYPE STANDARD TABLE OF t001,
  ls_t001 TYPE t001.

" old function
READ TABLE lt_t001 INTO ls_t001 INDEX 1.

" new function
ls_t001 = lt_t001[ 1 ].

" with inline declaration
DATA(ls_t001) = lt_t001[ 1 ].

 

Read over keys and fields

When reading the table, in most cases it is read with a predefined key or via fields defined as a free key. This syntax is still possible and slightly more compact in the new form and also easy to read for a few keys. As in the case of reading via the index, a direct inline declaration can also be used in this case.


" alter Read
READ TABLE lt_t001 INTO ls_t001
 WITH KEY bukrs = 'ABCD'.

" neuer Read
ls_t001 = lt_t001[ bukrs = 'ABCD' ].

 

Examination of the result

Before you read lines in the new variant, you should make sure that you catch errors or early enough checks whether the desired line is even present. The new standard offers two options that you can use.

In the first case you can use the new command LINE_EXISTS to check if the desired line exists.


" Examine the line
IF LINE_EXISTS( lt_t001[ 1 ] ).
  DATA(ls_t001) = lt_t001[ 1 ].
ENDIF.

 

In the second case, you catch the error while reading and save yourself the double typing of the key conditions. These methods provide the best solution in most cases.


" Examine the line
TRY.
    DATA(ls_t001) = lt_t001[ 1 ].
  CATCH CX_SY_ITAB_LINE_NOT_FOUND.
    " Error handling
ENDTRY.

 

Read only a field

In addition to the definition of an entire structure, it is also possible to access individual fields during reading, if, for example, in our case only the text for the company code is to be read.


" Read the text
DATA(ld_text) = lt_t001[ bukrs = 'ABCD' ]-butxt.

" Read the currency
DATA(ld_waers) = lt_t001[ bukrs = 'ABCD' ]-waers.

 

Conclusion

In today's article, we've shown you how the new accesses to internal tables work and how easy they are now. But there are also some new things that need to be considered when accessing and that the subrc is not quite as important as it used to be.

 

Source:
SAP Documentation table expressions


Included topics:
New ABAPInternal tablesLINE_EXISTS
Comments (0)



And further ...

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


ABAP - XCO Logging

Category - ABAP

The XCO classes are part of the ABAP Cloud APIs and offer numerous functions that aren't always easy to understand. In this article, we'll take a detailed look at the logging object.

12/16/2025

ABAP - The right Key

Category - ABAP

What about the use of internal tables? Is it still just TYPE TABLE in ABAP, and the table is fully defined?

11/14/2025

ABAP - XCO Regular Expressions

Category - ABAP

Let's take a look at the XCO classes for regular expressions and how you can easily use them to execute REGEX against text and input in ABAP Cloud. We'll also compare them with classic ABAP.

11/07/2025

ABAP - Escape

Category - ABAP

In this article, let's take a closer look at different escape variants that you need for ABAP development and system security.

10/07/2025

ABAP - Date and Time

Category - ABAP

In this article, let's take a closer look at the data types for dates and times in ABAP. Have any changes been made between the various releases, and what should you still use today?

10/03/2025