ABAP语法讲解四(FROM语句) 下载本文

内容发布更新时间 : 2024/6/26 17:34:08星期一 下面是文章的全部内容请认真阅读。

FROM Clause

Variants:

1. ... FROM dbtab [AS alias] 2. ... FROM (dbtabname)

3. ... FROM tabref1 [INNER] JOIN tabref2 ON cond 4. ... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond

Additions:

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

Used in a SELECT statement to name the source (database tables and views) from which the system is to select data.

Addition 1

... CLIENT SPECIFIED Effect

Automatic client handling is suspended. This enables you to search all clients in a client-specific table. The client field is treated as a perfectly normal table field, for which you can specify conditions in the WHERE clause.

The CLIENT SPECIFIED addition must come immediately after the name of the database table, or, in a JOIN, immediately after the last ON condition. Example

To output a list of all customers in client 003:

DATA WA_SCUSTOM TYPE SCUSTOM.

SELECT * FROM SCUSTOM CLIENT SPECIFIED INTO WA_SCUSTOM WHERE MANDT = '003'.

WRITE: / WA_SCUSTOM-ID, WA_SCUSTOM-NAME. ENDSELECT.

Addition 2

... BYPASSING BUFFER Effect

The data is read direct from the database, bypassing any SAP buffer there may be. Example

To output the address of the aircraft manufacturer Boeing:

DATA: WA_SPPROD TYPE SPPROD.

SELECT * FROM SPPROD INTO WA_SPPROD BYPASSING BUFFER WHERE PRODUCER = 'BOE'.

WRITE: / WA_SPPROD-STREET, WA_SPPROD-NUMB, WA_SPPROD-POSTCODE, WA_SPPROD-CITY, WA_SPPROD-COUNTRY. ENDSELECT.

Addition 3

... UP TO n ROWS Effect

The set of results is restricted to a maximum of nrows. Example

To output a list of the 3 business customers with the greatest discount:

DATA WA_SCUSTOM TYPE SCUSTOM.

SELECT * FROM SCUSTOM INTO WA_SCUSTOM UP TO 3 ROWS WHERE CUSTTYPE = 'B'

ORDER BY DISCOUNT DESCENDING.

WRITE: / WA_SCUSTOM-ID, WA_SCUSTOM-NAME, WA_SCUSTOM-DISCOUNT. ENDSELECT. Notes

1. If you use an UP TO n ROWS addition in an ORDER-BY clause , the lines read are

sorted into the correct order. The first n lines are then displayed. The system may need to read more than n lines from the database to be able to do this.

2. If n = 0, all selected lines are displayed.

3. n < 0 results in a runtime error.

Variant 1

... FROM dbtab [AS alias] Effect

Reads data from the database table or view dbtab. You specify the name dbtab directly in the program. The name must be known to the ABAP Dictionary.

You can use an alternative table name alias to give column names a unique name in the SELECT, FROM, WHERE, GROUP-BY, or ORDER-BY clauses when you use more than one database table. Example

Outputs a list of all customers:

DATA WA_SCUSTOM TYPE SCUSTOM.