ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Read Accesses →  SELECT → 

SELECT - additional_options

Quick Reference

Syntax

... [UP TO n ROWS]
    [BYPASSING BUFFER]
    [CONNECTION con|(con_syntax)] ...

Additions

1.... UP TO n ROWS

2.... BYPASSING BUFFER

3.... CONNECTION con|(con_syntax)

Effect

These optional additions of the statement SELECT specify the maximum number of rows read, whether SAP buffering is bypassed, and define the database connection.

If the INTO clause is specified as last clause of the SELECT statement, the additions must follow after the INTO clause. Otherwise, they can also be specified after the SELECT clause or after the FROM clause.

Addition 1

... UP TO n ROWS

Effect

This addition restricts the number of rows in the results set of a SELECT statement. n expects a host variable, a host expression or literal of type i that can contain all non-negative numbers from the value range except its maximum value +2147483647. A host variable should be prefixed by the escape character @. The content of n must match the data type i in accordance with the rules for a lossless assignment.

A positive number in n indicates the maximum number of rows in the results set. If n contains the value 0, a maximum of 2147483647 rows are passed to the results set. If n contains a negative number or +2147483647, a syntax error is produced or a non-handleable exception is raised.

The addition UP TO cannot be used with the addition SINGLE.

Notes

It is advisable to use the addition UP TO 1 ROWS to read at most one row from a set of selected rows. The addition SINGLE, on the other hand. should generally be used to read a row specified in full.

Example

Reading the three business customers with the highest discount rates:

DATA: wa_scustom TYPE scustom.

SELECT *
       FROM scustom
       WHERE custtype = 'B'
       ORDER BY discount DESCENDING
       INTO @wa_scustom
       UP TO 3 ROWS.
ENDSELECT.

Addition 2

... BYPASSING BUFFER

Effect

This addition causes the SELECT statement to bypass SAP buffering and to read directly from the database and not from the buffer on the application server

Addition 3

... CONNECTION con|(con_syntax)

Effect

The Open SQL command is not executed on the standard database connection but on the specified secondary database connection. The database connection can be specified as follows:

Specified directly and statically as con.
Specified as the content of a parenthesized data object con_syntax of type c or string. The following can be specified for con_syntax:

The database connection must be specified with a name, which is contained in the table DBCON in the column CON_NAME or which begins with prefix R/3* and therefore represents a service connection for the standard database. A database connection is not evaluated until runtime, regardless of whether it is specified statically or dynamically, and any unknown database connections produce the runtime error DBSQL_UNKNOWN_CONNECTION.

The database tables or views specified in the current Open SQL statement must be active in ABAP Dictionary in the current AS ABAP regardless of the specified database connection. Only transparent tables can be specified as database tables. Pooled tables and cluster tables cannot be specified together with the addition CONNECTION. In the secondary database, an identically named and usable object with a suitable structure must exist for each database table or view specified in the current Open SQL statement. If not, an exception is raised.

Notes

Example

Reads data using a service connection to the standard database.

SELECT *
       FROM scarr
       INTO TABLE @DATA(itab)
       CONNECTION r/3*my_conn.

cl_demo_output=>display( itab ).