This is a test message to test the length of the message box.
The new Select
Created by Software-Heroes

ABAP - The new Select


The customization of the ABAP language also has implications and improvements for the well-known and important Select. In this article we want to briefly describe what has changed and what you get for benefits.

As already described in an earlier article, the Select also changed a bit. There are now two variants in the execution and notation. The previous variant persists and does not change, thus keeping all old programs up to date.



So what has changed with the modern ABAP? Basically, this can be described with a few bullet points:

  • Functions can now be transferred to the select or the results of these functions when called. Many functions were also completely new, only for the Select, implemented.
  • Dynamic return tables / variables can be generated at runtime.
  • The order of construction has changed a bit.


For you that means, there are some new features that you should definitely try with the Select.



Here are two examples to bring the new features a little bit closer to you. In the first example we focus on the creation of internal tables with dummy fields and how you can create them dynamically at runtime.

" Select-option creation
  'I' AS sign,
  'EQ' AS option,
  bukrs AS low,
  ' ' AS high
 FROM t001
 WHERE land1 <> 'DE'
 INTO TABLE @DATA(lt_range).

As you have already guessed from the fields, we get as result a select option that is filled with the company codes, which are not in Germany.

  • With the AS addition we give the fields new names, which was already possible with the "old" Select. The individual fields are now separated by commas.
  • We give the fields a default value and assign it to the field. An empty value must contain a space in the literal, and an empty literal will be displayed as an error by the compiler.
  • With the Escape character and DATA command we create a table at runtime. This table has exactly the fields that we specify in the Select.
  • The INTO command has now moved to the end of the statement, which is as far as provided by SAP as a new point in the statement.


As a second example, we would like to draw your attention to the many new inline functions that were implemented especially for the Select.

" Create new variable
DATA(ld_waers) = 'eur'.

" Select with functions
  bukrs AS bukrs,
  CAST( kokfi AS CHAR( 20 ) ) AS text,
  CASE WHEN stceg = ' ' THEN '-'
       ELSE stceg
  END AS tax
 FROM t001
 WHERE bukrs LIKE 'A%'
   AND waers = @( to_upper( ld_waers ) )
 INTO TABLE @DATA(lt_bukrs).

In this example, the functions that pass the values to the select or make specific queries to the data of the select are of particular interest.

  • The cast function converts the number field into a text field with 20 characters, so that the data type can be returned to the target format directly upon return.
  • With a case statement, the tax key is checked, when it's not empty, it is taken over, but should it be empty, then we set a simple minus.
  • In the where-clause, we still convert the currency field to uppercase with the UPPER command before passing it to Select. As always, an escape character is used to call the function.


To the point

The best feature is the dynamic generation of the target structure in Select. Thus only the determined fields are in the table, the table remains small in the memory and no special type needs to be defined beforehand and not even the target variable.

" Simple Select
SELECT bukrs, butxt, stceg, waers
 FROM t001
 WHERE land1 <> 'DE'
 INTO TABLE @DATA(lt_bukrs).

It is always important to use the comma between the enumeration of the fields and the escape of the DATA statement to create the table.



Much has changed at the Select statement, also because the CDS Views are now in competition with these and are also very powerful. We hope we could make you curious? Then take a look at the new Open SQL functions in the SAP documentation.


SAP documentation - Open SQL

Included topics:
New ABAPSelect
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.


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.


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?


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.


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.



Category - ABAP

In this article, we'll take a look at the new FINAL language construct, how it works, and what you can do with it.