Ansicht
Dokumentation

ABAPSELECT_CLAUSE - SELECT CLAUSE

ABAPSELECT_CLAUSE - SELECT CLAUSE

CL_GUI_FRONTEND_SERVICES - Frontend Services   BAL Application Log Documentation  
This documentation is copyright by SAP AG.
SAP E-Book

SELECT, select_clause

Short Reference



... $[DISTINCT$] select_list ...

Addition:

... DISTINCT

Effect

SELECT clause of a query. The SELECT clause defines the structure of the result set of the SELECT statement. It consists of a SELECT list, which defines the columns of the result set, and an optional addition DISTINCT, which removes duplicative rows from the result set.

The SELECT list select_list can indicate all columns of a data source using * or it defines the individual columns of the result set using an SQL expression. It defines the names of the columns in the result set, using optional or mandatory alias names.

Note

The SELECT clause must either be listed as the first clause after the keyword SELECT, or after the optional addition SINGLE, or after the FROM clause. After the FROM clause, the SELECT clause must be introduced using the addition FIELDS. A FROM clause in front of the SELECT clause supports tools such as the code completion in the ABAP Editor.

Example

SELECT clause after FIELDS, whose SELECT list specifies individual columns as well as aggregate expressions as arguments using SQL expressions.

Addition

... DISTINCT

Effect

The addition DISTINCT removes rows that occur more than once in a multirow result set. Here, the entire row content is respected.

The addition DISTINCT must not be used in the following cases:

  • If the addition SINGLE is used.
  • If a column specified in the SELECT list select_list has the type STRING, RAWSTRING, LCHR, LRAW, or GEOM_EWKB.

If DISTINCT is used, the statement SELECT bypasses table buffering.

Notes

  • For the addition DISTINCT, it is not important which columns of the result set are key fields of the associated DDIC database tables, views, or CDS entities.
  • The comparison is based on the entire row content, which means that the number of rows in the result set depends on the SELECT list. If, for example, all key fields of a DDIC database table are specified directly as columns in a SELECT list, there can be no rows that occur more than once. The other extreme is the case where a SELECT list contains a single host variable or a single literal. Here, all rows are deleted except one.
  • As a part of the SELECT clause, the addition DISTINCT has an effect before the additions UP TO and OFFSET are evaluated.
  • If DISTINCT is specified, it should be noted that this requires the execution of sort operations in the database system, and the statement SELECT therefore bypasses table buffering.

Example

Output of all destinations to which Lufthansa flies from Frankfurt.






Addresses (Business Address Services)   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.

Length: 4686 Date: 20240424 Time: 143556     sap01-206 ( 69 ms )