凡尘clsoho™的博客

E-mail & MSN: clsoho@hotmail.com
QQ1超级群: <101817641已满> QQ2群:<110722895已满>
QQ3超级群:<23765855>QQ4超级群:<85338969>

READ TABLE - table_key

Syntax 语法

... { FROM wa }
  | { WITH TABLE KEY {comp_name1|(name1)} = dobj1
                     {comp_name2|(name2)} = dobj2
                     ...                           } ... .

Alternatives:

1. ... FROM wa

2. ... WITH TABLE KEY ...

Effect: 作用

The values of the search key can be specified either implicitly in a work area wa after FROM, or by explicitly listing the components of the table key after TABLE KEY.

查找关键字的值可以暗中被指定在from后面的一个工作区wa中,或者在table key之后显式地列在这些表关键字段。

Alternative 1 选项1

... FROM wa
Effect:
作用

The work area wa must be a data object that is compatible with the line type of the internal table. The first found line of the internal table is read for which the values in the columns of the table key match the values in the corresponding components of wa.

工作区wa必须是一个与内表的行类型相匹配的数据对象。内表中第一个被找到的行是从表关键字的列的值和wa工作区的相应字段相匹配后从工作区中读取的。

Note:

Apart from in classes, the specification FROM wa can be omitted if the internal table has a header line itab with the same name. In this case, the statement then does not evaluate the content of the table key, but instead evaluates the standard key. Initial fields receive special treatment (see obsolete variants of READ TABLE).

除了在课堂上,指定的From wa可以被省略如果内表有一个同名的表头itab.在这种情况下,语句不再求表关键字段的值,而取代去求标准关键字的值。初始字段受到特殊处理。

Alternative 2 选项2

... WITH TABLE KEY ...



Effect: 作用

Each component of the table key must listed either directly as comp_name1 comp_name2 ... , or as a bracketed character-type data object name1 name2 ..., which contains the name of the component when the statement is executed (before release 6.10 in upper case). A data object must be assigned to each component, which is compatible with or can be converted to the data type of the component. The first found line of the table is read, for which the values in the columns of the table key match the values in the assigned data objects dobj1 dobj2 .... If necessary, the content of dobj1 dobj2 ... is converted to the data type of the component before the comparison.

每一个表关键字字段必须要么被直接以comp_name1 comp_name2 …列出,或者以一个相同的,当语句被执行时包含字段名字的字符类型数据对象name1 name2…列出(在6.10版本前用大写字段)。必须为每个字段指定一个与字段的数据类型相匹配的,或者能够被转换的数据对象。表的第一行找到的数据被读取,表关键字的列的值和指定的数据对象dobj1 dobj2 …相匹配。如果需要,dobj1 dobj2 … 的内容在匹配之前被转换成字段的数据类型。

The different table types are accessed as follows: 可以使用如下不同的表类型:

  • standard tables are searched using a linear search. 标准表使用线性搜索查找数据。
  • sorted tables are searched using a binary search. 排序表使用二分查找查找数据。
  • For hashed tables, the hash algorithm is used. 对于哈希表,则使用哈希算法。

Notes:

  • In tables with a non-structured line type, for which the whole table line is defined as a table key, the pseudo component table_line can be specified as a component.

在没有结构化行类型的表中,对于这种表整个表行被定义成一个表关键字,假字段table_line可以被指定为一个字段。

  • To avoid unexpected results after a conversion, dobj1 dobj2 ... should be compatible with the data type of the component.
    为了避免在一个转换之后不可预料的结果,dobj1 dobj2 …应该和字段的数据类型相一致。

Example: 例子

Reading from lines of the internal table spfli_tab using the table key. The first READ statement evaluates the work area spfli_key, in the second READ statement, the components of the table key are specified explicitly.

用表关键字读取内表spfli_tab的行。第一个Read 语句计算工作区spfli_key的值,在第二个read语句中,表关键字的内容被直接指定。

DATA: spfli_tab TYPE SORTED TABLE OF spfli
                WITH UNIQUE KEY carrid connid,
      spfli_key LIKE LINE OF spfli_tab.

FIELD-SYMBOLS <spfli> TYPE spfli.

...

SELECT *
       FROM spfli
       INTO TABLE spfli_tab
       WHERE carrid = 'LH'.

...

spfli_key-carrid = 'LH'.
spfli_key-connid = '0400'.

READ TABLE spfli_tab FROM spfli_key ASSIGNING <spfli>.

IF sy-subrc = 0.
  ...
ENDIF.

...

READ TABLE spfli_tab
           WITH TABLE KEY carrid = 'LH' connid = '2402'
           ASSIGNING <spfli>.

IF sy-subrc = 0.
  ...
ENDIF.

posted on 2010-02-09 10:13  凡尘clsoho  阅读(3165)  评论(0编辑  收藏  举报