内表与数据库表连接查询FOR ALL ENTRIES IN


背景, FOR ALL ENTRIES IN,是用于内表与我们数据表进行连接的条件。

1.Syntax(语法)

… FOR ALL ENTRIES IN @itab WHERE … col operator @itab-comp …

If the addition FOR ALL ENTRIES is specified in front of the language element WHERE of the statement SELECT of a main query, the components comp of the internal table itab specified here can be used within sql_cond on the right side of comparisons of a relational operator in comparisons with a column col. The specified component comp must be compatible with the column col. The internal table itab can have a structured or an elementary row type. For an elementary row type, the pseudo component table_line must be specified for comp. The name of the host variable dbcur should be prefixed with the escape character @.

2.Example(例子)

Gets all flight data for a specified departure city. The relevant airlines and flight numbers are first passed to an internal table entry_tab, which is evaluated in the WHERE condition of the subsequent SELECT statement. This selection could also be carried out in a single SELECT statement by using a join in the FROM clause. Make sure that the table entry_tab is not initial before the SELECT statement is executed using FOR ALL ENTRIES.

DATA city TYPE spfli-cityfrom VALUE ‘FRANKFURT’.
cl_demo_input=>request( CHANGING field = city ).

SELECT carrid, connid
FROM spfli
WHERE cityfrom = @( to_upper( city ) )
INTO TABLE @DATA(entry_tab).

IF entry_tab IS NOT INITIAL.
SELECT carrid, connid, fldate
FROM sflight
FOR ALL ENTRIES IN @entry_tab
WHERE carrid = @entry_tab-carrid AND
connid = @entry_tab-connid
ORDER BY PRIMARY KEY
INTO TABLE @DATA(result_tab).
cl_demo_output=>display( result_tab ).
ENDIF.

Example

Uses FOR ALL ENTRIES with an empty internal table. All rows of the database table are respected. The number of read rows is usually, however, smaller in the first SELECT statement than in the second statement. This is because only one column is read and hence more duplicate rows can be removed. The second SELECT statement, on the other hand, moves all rows of the database table to the results set, since their structure covers the full table key.

DATA carriers TYPE TABLE OF scarr.

SELECT carrid, connid
FROM spfli
FOR ALL ENTRIES IN @carriers
WHERE carrid = @carriers-carrid
INTO TABLE @DATA(result1).
cl_demo_output=>write( result1 ).

SELECT carrid
FROM spfli
FOR ALL ENTRIES IN @carriers
WHERE carrid = @carriers-carrid
INTO TABLE @DATA(result2).
cl_demo_output=>display( result2 ).

3.总结

有时候如果文档太多了,我们就看quick reference.

When the lines are duplicate in the result. Please use key field in the table.

4.源文档

源文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值