FROM clause


Variants


1. ... FROM dbtab
2. ... FROM (dbtabname)

Effect

When used in a SELECT statement, specifies the source (database table or view ) from which data can be selected.

Variant 1

... FROM dbtab

Additions



1. ... CLIENT SPECIFIED
2. ... BYPASSING BUFFER
3. ... UP TO n ROWS

Effect

Specifies the name of the database table dbtab in the program. The database table must be known to the ABAP/4 Dictionary and the program must contain an appropriate TABLES statement.

Example

Output a list of all customers:
TABLES SCUSTOM. SELECT * FROM SCUSTOM. WRITE: / SCUSTOM-ID, SCUSTOM-NAME. ENDSELECT.

Addition 1

... CLIENT SPECIFIED

Effect

Switches off automatic client handling. With client-specific tables, this enables you to read data across all clients. The client field is treated like a normal table field for which conditions can be formulated in the WHERE clause .

The addition CLIENT SPECIFIED must appear immediately after the name of the database table.

Example

Output a list of all customers in client 3:
TABLES SCUSTOM. SELECT * FROM SCUSTOM CLIENT SPECIFIED WHERE MANDT = '003'. WRITE: / SCUSTOM-ID, SCUSTOM-NAME. ENDSELECT.

Addition 2

... BYPASSING BUFFER

Effect

Reads the data records directly from the database, even if the table is in the SAP buffer .

Example

Output address of aircraft manufacturer Boeing:
TABLES SPROD. SELECT * FROM SPROD BYPASSING BUFFER WHERE PRODUCER = 'BOE'. WRITE: / SPROD-STREET, SPROD-NAME, SPROD-POSTCODE, SPROD-CITY, SPROD-COUNTRY. ENDSELECT.

Addition 3

... UP TO n ROWS

Effect

Restricts the result set to a maximum of n lines.

Example

Output a list of the 3 business customers with the highest discounts:
TABLES SCUSTOM. SELECT * FROM SCUSTOM UP TO 3 ROWS WHERE CUSTTYPE = 'B'. ORDER BY DISCOUNT DESCENDING. WRITE: / SCUSTOM-ID, SCUSTOM-NAME, SCUSTOM-DISCOUNT. ENDSELECT.

Notes

If you combine UP TO n ROWS with an ORDER-BY clause , the records are arranged in the specified order and the first n records are output. To achieve this, you must sometimes read more than n records in the database.
If n = 0, all the selected records are returned.
If n < 0, a runtime error occurs.

Variant 2

... FROM (dbtabname)

Additions



1. ... CLIENT SPECIFIED
2. ... BYPASSING BUFFER
3. ... UP TO n ROWS

Effect

Specifies the name of the database table as the contents of the field dbtabname at runtime. The database table must be known to the ABAP/4 Dictionary .

Example

Output a list of all customers:
DATA TABNAME(10). DATA: BEGIN OF WA, ID LIKE SCUSTOM-ID, NAME LIKE SCUSTOM-NAME, REST(100), END OF WA. TABNAME = 'SCUSTOM'. SELECT * INTO WA FROM (TABNAME). WRITE: / WA-ID, WA-NAME. ENDSELECT.

Notes

If you use an INTO clause , you can only specify the name of the database table at runtime.
The database table name must always be in upper case.

Addition 1

... CLIENT SPECIFIED

Effect

As for variant 1.

Addition 2

... BYPASSING BUFFER

Effect

As for variant 1.

Addition 3

... UP TO n ROWS

Effect

As for variant 1.

Note

Performance
With small datasets, you should always try to avoid specifying the name of the database table at runtime because this adversely affects performance. With larger datasets, there is no such problem.

Index
© SAP AG 1996