... { SINGLE [FOR UPDATE] }
| { [DISTINCT] { } } ... .
1. ... SINGLE [FOR UPDATE]
2. ... [DISTINCT] { }
The data in lines specifies that the resulting set has either multiple lines or a single line.
... SINGLE [FOR UPDATE]
If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used. The addition ORDER BY can also not be used.
An exclusive lock can be set for this
line using the FOR UPDATE addition when a single line
is being read with SINGLE. The
SELECT command is used in this case only if all primary key fields in logical expressions
linked by AND are checked to make sure they are the same
in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a
deadlock, an exception occurs. If the
FOR UPDATE addition is used, the SELECT command circumvents SAP buffering.
When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key.
... [DISTINCT] { }
If SINGLE is not specified and if columns does not contain only aggregate expressions, the resulting set has multiple lines. All database lines that are selected by the remaining additions of the SELECT command are included in the resulting list. If the ORDER BY addition is not used, the order of the lines in the resulting list is not defined and, if the same SELECT command is executed multiple times, the order may be different each time. A data object specified after INTO can be an internal table and the APPENDING addition can be used. If no internal table is specified after INTO or APPENDING, the SELECT command triggers a loop that has to be closed using ENDSELECT.
If multiple lines are read without SINGLE, the DISTINCT addition can be used to exclude duplicate lines from the resulting list. If DISTINCT is used, the SELECT command circumvents SAP buffering. DISTINCT cannot be used in the following situations:
When specifying DISTINCT, note that this requires the
execution of sort operations in the database system, and the SELECT statement therefore bypasses the
SAP buffer.