Ansicht
Dokumentation

ABAPSELECT_MAINQUERY - SELECT MAINQUERY

ABAPSELECT_MAINQUERY - SELECT MAINQUERY

ABAP Short Reference   General Data in Customer Master  
This documentation is copyright by SAP AG.
SAP E-Book

SELECT, mainquery_clauses



Effect

Possible clauses and additions of a main query represented by a standalone SELECT statement. The clauses and additions define the result set of the SELECT statement:

  • Rows of the result set
  • Multirow result set

If SINGLE is not specified and if aggregate expressions are not exclusively specified in the SELECT list of the SELECT clause select_clause, the result set is multirow or tabular by default. All database rows that are selected by the remaining additions of the statement SELECT are included in the result set. If the addition ORDER BY is not used, the order of the rows in the result set is not defined and can be different if the same statement SELECT is executed multiple times. A data object specified after INTO can be an internal table and the addition APPENDING can be used. If no internal table is specified after INTO or APPENDING, the statement SELECT for multirow result sets initiates a loop that must be closed using ENDSELECT.
  • Single row result set

The optional addition SINGLE defines a single-row result set that can be protected against parallel changes by another program. When using SINGLE, it is not possible to specify an internal table as the target object, and the addition SINGLE cannot be combined with all additions of the SELECT statement.
  • Columns of the result set
The SELECT clause select_clause defines the structure of the result set. It consists mainly of a SELECT list that defines the columns of the result set. Optionally, duplicate rows can be excluded.
  • Data Sources
The FROM clause specifies data sources source from which data is read. These can either be data sources in the database accessed by the current query or they can be internal tables. Data sources in the database must be defined in the ABAP Dictionary.
  • Conditions
The result set can be restricted using the WHERE clause. The optional addition FOR ALL ENTRIES can be used to compare the content of a column on the database with a component with all rows of a structured internal table itab.
  • Grouping
The GROUP BY clause merges multiple database rows into one row of the result set. The HAVING clause restricts the merged rows.
  • Database Hints
db_hints can be used to specify database hints.
  • Sorting
The ORDER BY clause sorts the result set. If ORDER BY is not specified, the order of the rows in the result set is undefined.

The SELECT clause select_clause can be specified before or after the FROM clause. After the FROM clause, the SELECT clause must be prefixed with the addition FIELDS.

Notes

  • Although the WHERE condition is optional, it should always be specified for performance reasons, and the result set should not be restricted in AS ABAP.

Example

SELECT statement with all possible clauses.






BAL_S_LOG - Application Log: Log header data   ABAP Short Reference  
This documentation is copyright by SAP AG.

Length: 6097 Date: 20240419 Time: 141637     sap01-206 ( 97 ms )