SAP SELECT ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID SELECT
• SELECT ABAP_STATEMENT_OSQL

SELECT
Short Reference

ABAP_SYNTAX
SELECT mainquery_clauses
$[UNION$|INTERSECT$|EXCEPT ...$]
INTO$|APPENDING target
$[UP TO ...$] $[OFFSET ...$]
$[abap_options$].
...
$[ENDSELECT$].

What does it do?
Use of the AB-SQL statement SELECT as a standalone statement. This statement reads data from one or more DDIC database tables
BEGIN_SECTION VERSION 5 OUT , DDIC views,
END_SECTION VERSION 5 OUT or non-abstract CDS entities, uses this data to create a multirow or a single row result set, and assigns this result set to suitable ABAP data objects.
The additions mainquery_clauses define which data is read from the database in which form. The set operators UNION, INTERSECT , and EXCEPT can be used to combine the result sets of multiple queries. In this case, special rules query_clauses apply when specifying clauses. Finally, the following properties are defined:
ABAP target objects In the INTO clause after INTO or APPENDING, the target data objects are specified, to which the result set is assigned by row or by package.
Restricting the result set The additions UP TO and OFFSET determine the number of rows to be read.
ABAP-specific additions Optional additions abap_options define whether table buffering is bypassed and define the database connection.
In the following cases, the statement SELECT opens a loop that must be closed using ENDSELECT.
If an assignment is made to a non-table-like target range, that is, a SELECT statement without the addition INTO$|APPENDING ... TABLE, a loop closed by ENDSELECT always occurs, except in the following instances:
The addition SINGLE for reading a single row is specified after SELECT
The columns of the result set are specified statically in the SELECT list, they contain only aggregate functions, and the additions GROUP BY, UNION, INTERSECT, and EXCEPT are not specified.
If an assignment is made to a table-like target range, that is, a SELECT statement with the addition INTO$|APPENDING ... TABLE, a loop closed by ENDSELECT occurs whenever the addition PACKAGE SIZE is used.
In each loop iteration, the SELECT statement assigns a row or a package of rows to the data objects specified in target. If the last row has been assigned or the result set is empty, SELECT jumps to ENDSELECT. A database cursor is opened implicitly to process a SELECT loop, and is closed again when the loop has ended. In a program, a maximum of 17 database cursors can be open simultaneously across the AB-SQL interface. If more than 17 database cursors are opened, the runtime error DBSQL_TOO_MANY_OPEN_CURSOR occurs. If the entire result set is passed to the data object in one step, no loop is opened and the statement ENDSELECT cannot be specified.
A SELECT loop can be exited with one of the following statements: