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

ABAP - The new Select

1928

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.

Advertising


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.

 

Changes

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.

 

Examples

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
SELECT
  '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
SELECT
  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.

 

Conclusion

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.

 

Source:
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 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