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

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)
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