ABAP语法讲解五(WHERE语句)

上传人:飞*** 文档编号:39935729 上传时间:2018-05-21 格式:DOC 页数:4 大小:34.50KB
返回 下载 相关 举报
ABAP语法讲解五(WHERE语句)_第1页
第1页 / 共4页
ABAP语法讲解五(WHERE语句)_第2页
第2页 / 共4页
ABAP语法讲解五(WHERE语句)_第3页
第3页 / 共4页
ABAP语法讲解五(WHERE语句)_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《ABAP语法讲解五(WHERE语句)》由会员分享,可在线阅读,更多相关《ABAP语法讲解五(WHERE语句)(4页珍藏版)》请在金锄头文库上搜索。

1、WHERE Clause Variants: 1. . WHERE cond 2. . FOR ALL ENTRIES IN itab WHERE cond Effect If you specify a WHERE clause in the SELECT, OPEN CURSOR, UPDATE or DELETE statement, the system only selects records from the table or tables in the FROM clause that meet the logical condition cond in it. When you

2、 use OPEN SQL statements, the system uses automatic client handling by default. This means that, for a client-specific table, only data from the current client is processed. Specifying a condition for the client field in the WHERE clause does not make sense, and causes an error in the syntax check.

3、If you switch off the automatic client handlign using the . CLIENT SPECIFIED addition in the FROM clause, the client field is treated like a normal field, and you can then specify conditions for it normally in the WHERE clause. Notes 1.If you have transparent tables that you often access without usi

4、ng the full primary key, or where you often sort the data in a sequence that is different to that of the primary key, you should consider creating a corresponding index. 2.If you do not specify a WHERE condition in a selection, the system processes all table records in the current client. Variant 1

5、. WHERE cond Effect Only selects the records that meet the WHERE condition cond. Example Displaying all Lufthansa flights: DATA: WA_SPFLI TYPE SPFLI. SELECT * FROM SPFLI INTO WA_SPFLI WHERE CARRID = LH. WRITE: / WA_SPFLI-CITYFROM, WA_SPFLI-CITYTO. ENDSELECT. Variant 2 . FOR ALL ENTRIES IN itab WHERE

6、 cond Effect Only selects the records that meet the logical condition cond when each replacement symbol itab-f is replaced with the value of component f of the internal table itab for at least one line of the table. SELECT . FOR ALL ENTRIES IN itab WHERE cond returns the union of the solution sets o

7、f all SELECT statements that would result if you wrote a separate statement for each line of the internal table replacing the symbol itab-f with the corresponding value of component f in the WHERE condition.Duplicates are discarded from the result set. If the internal table itab does not contain any

8、 entries, the system treats the statement as though there were no WHERE cond condition, and selects all records. Example Displaying the occupancy of flights on 28.02.1995: TYPES: BEGIN OF FTAB_TYPE, CARRID LIKE SFLIGHT-CARRID, CONNID LIKE SFLIGHT-CONNID, END OF FTAB_TYPE. DATA: FTAB TYPE STANDARD TA

9、BLE OF FTAB_TYPE WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 10, RATIO TYPE P DECIMALS 3, WA_SFLIGHT TYPE SFLIGHT. * Suppost FTAB is filled as follows: * * CARRID CONNID * - * LH 2415 * SQ 0026 * LH 0400 SELECT * FROM SFLIGHT INTO WA_SFLIGHT FOR ALL ENTRIES IN FTAB WHERE CARRID = FTAB-CARRID AND CONNID

10、 = FTAB-CONNID AND FLDATE = 19950228. RATIO = WA_SFLIGHT-SEATSOCC / WA_SFLIGHT-SEATSMAX. WRITE: / WA_SFLIGHT-CARRID, WA_SFLIGHT-CONNID, RATIO. ENDSELECT. * The statement has the same effect as: SELECT DISTINCT * FROM SFLIGHT INTO WA_SFLIGHT WHERE ( CARRID = LH AND CONNID = 2415 AND FLDATE = 19950228

11、 ) OR ( CARRID = SQ AND CONNID = 0026 AND FLDATE = 19950228 ) OR ( CARRID = LH AND CONNID = 0400 AND FLDATE = 19950228 ). RATIO = WA_SFLIGHT-SEATSOCC / WA_SFLIGHT-SEATSMAX. WRITE: / WA_SFLIGHT-CARRID, WA_SFLIGHT-CONNID, RATIO. ENDSELECT. Notes 1.You can only use . FOR ALL ENTRIES IN itab WHERE cond

12、in a SELECT statement. 2.In the logical condition cond, the symbol itab-f is always a replacement symbol, and should not be confused with the component f of the header line of the internal table itab. The internaln table itab does not have to have a header line. 3.The line structure of the internal

13、table iab must be a structure. Each component of the structure that appears in the WHERE condition as a replacement symbol must have exactly the same type and length as the corresponding component of the table work area (see TABLES). 4.You cannot use replacement symbols in comparisons in LIKE, BETWE

14、EN, or IN expressions. 5.If you use FOR ALL ENTRIES IN itab, you cannot use ORDER BY f1 . fn in the ORDER-BY clause. 6.You cannot use the internal table itab in the INTO clause as well. Notes Performance: 1.Specify all conditions in the WHERE clause. This means that you do not transport redundant da

15、ta over the network only to filter it out in your program (using CHECK, for example). 2.If you regularly use a SELECT statement, you should create an index. In the WHERE clause, you should use the fields of the index, linked using AND, and checking for equality. Fields of an index that occur after a field for which you do not use an equality comparison in the WHERE clause (EQ or =) cannot be used to restrict the search. The logical expression NOT in a WHERE clause is not supported by indexes. For example, WHERE FLDATE = 19950228 is better than WHERE NOT FLDATE 19950228.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号