What does it do? The table expression reads the line with the line number specified in idx> with respect to a table index. The line is read in exactly the same way as when specifying an index • idx [USING KEY keyname]>> in the statement READ TABLE>>. Similarly, idx> is a numeric expression position> and the optional KEY keyname> •> is equivalent to the USING KEY keyname>> specified here. If the optional addition is not used, itab> must be an index table>. If the addition is used, the secondary table index of a sorted secondary key can be specified statically or dynamically. If no line exists for the specified index, the catchable exception CX_SY_ITAB_LINE_NOT_FOUND> is usually raised. The attributes KEY_NAME> and KEY_COMP_VALUES> are not filled here. Exceptions to this rule are when a start value> is specified, uses in the statement ASSIGN>>, in the predicate function line_exists>>, and in the table function line_index>>.
ABAP_EXAMPLE_VX5 Reading of the line with the line number 1 once using the secondary table key skey> and twice using the primary table key. It is the third line once and the first line twice. ABEXA 01336 ABAP_EXAMPLE_END
What does it do? The table expression reads the line in accordance with the specified free search key. The search is performed in exactly the same way as when specifying the free search key comp1 = operand1 comp2 = operand2 ...>> in the statement READ TABLE>>. Similarly, the components comp1 comp2 ...> can be specified in accordance with the rules from the section Specifying Components> and compatible or convertible operands operand1 operand2 ...> must be specified that are general expression positions>. If no line is found for the specified free key, the catchable exception CX_SY_ITAB_LINE_NOT_FOUND> is usually raised. The attributes KEY_NAME> and KEY_COMP_VALUES> are not filled here. Exceptions to this rule are when a start value> is specified, uses in the statement ASSIGN>>, in the predicate function line_exists>>, and in the table function line_index>>.
Latest notes:
If the free key overlaps with some or all of the primary table key>, the optimizations described under READ TABLE> > are performed when sorted tables and hashed tables are read.
Unlike the statement READ TABLE>> with a free key specified>, no binary searches can be forced for a table expression and it is not possible to specify explicit table key for optimizing searches using secondary keys. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 Reading of a line in an internal table using a free specified key. ABEXA 01337 ABAP_EXAMPLE_END
ABAP Alternative 3 ... KEY keyname $[COMPONENTS$] ...>
What does it do? The table expression reads the line in accordance with the explicitly specified table key>.
Generally, the search is performed in exactly the same way as when specifying the table key WITH TABLE KEY $[keyname COMPONENTS$] ...>> in the statement READ TABLE>>. The table key must be covered completely by specifying components and no components can be specified that are not part of the table key.
If the table expression is specified as an argument of the predicate function> line_exists>> or of the table function line_index>>, the search is performed as when specifying a free search key WITH KEY keyname COMPONENTS ...>> in the statement READ TABLE>> and the key is linked to a table key. A sorted table key does not have to be covered completely by specified components. For both categories of secondary keys, components can be specified that are not part of the table key. Unlike the statement READ TABLE>, a table expression must specify the name of the table key and the addition COMPONENTS> can be omitted. Like here, the table key keyname> and the key components can be specified statically or dynamically. The operands operand1 operand2 ...> are general expression positions>. If no line is found for the specified table key, the catchable exception CX_SY_ITAB_LINE_NOT_FOUND> is usually raised. The attributes KEY_NAME> and, if the table is not empty, KEY_COMP_VALUES> are not filled here. Exceptions to this rule are when a start value> is specified, uses in the statement ASSIGN >>, in the predicate function line_exists>> , and in the table function line_index>>.
Latest notes:
Searches using the primary table key > do not have to specify it explicitly. Instead, the variant with a free search key can be used. If this covers the primary table key, it is used for optimized reads on sorted tables and hashed tables.
In order to use the primary table key > in this variant explicitly, the key must be specified using its predefined name primary_key> or an alias name.
The differing behavior of the specified key outside and inside the functions line_exists>> and line_index>> is explained as follows:
Outside the functions, the main purpose of an explicitly specified table key is to read exactly one completely specified line.
Within the functions, the existence of a specified line that is not necessarily specified completely or, for example, a line number as the starting point of a subsequent sequential read using LOOP ... FROM>> is to be determined as efficiently as possible. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 Reading of a line in an internal table by specifying the primary table key. ABEXA 01338 ABAP_EXAMPLE_END