Ansicht
Dokumentation

ABENLINE_INDEX_FUNCTION - LINE INDEX FUNCTION

ABENLINE_INDEX_FUNCTION - LINE INDEX FUNCTION

General Data in Customer Master   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.
SAP E-Book

- line_index

... line_index( table_exp  ) ...

The built-in table function line_index returns the number of the line found using the table expression table_exp with respect to the table index used. The return value has the type i.

The line itab_line to be searched for using the table expression must be determined by a key specification. An index cannot be specified. For table_exp, in addition to individual table expressions, all chainings whose result is a line of an internal table, that is, they are closed using angle brackets, can also be specified. The result always refers to the line specified in the final angle bracket and the key access restrictions apply only to this angle bracket.

Within line_index, an explicitly specified table key in the table line table_line of the table expression is handled in the same way as a free search key specified for this table key.

The table index used depends on the specified key as follows:

  • If a search key is specified without a table key being specified explicitly, the number of a found line is returned with respect to the primary table index and, in the case of a hashed table, the value -1.
  • If a table key is specified explicitly after KEY, the number of a found line is returned with respect to the assigned table index. If the key is a hash key, the value -1 is returned.

If the line searched for is not found, no exception is raised. The value 0 is returned instead. In the case of chainings, of table expressions, the first unsuccessful from the left produces this value.

Notes

  • An index specified in itab_line of the table expression is not possible here, since it does not make sense.
  • The table expression is only used to check the existence of the line number specified line. No temporary result is created.
  • The table function line_index can be understood as a short form of the statement READ TABLE with the addition TRANSPORTING NO FIELDS followed by the evaluation of sy-tabix. If a line is not found, 0 is always returned. sy-tabix, on the other hand, has the value where the line would be found after a binary search using READ TABLE.
  • If a search key specified in table_line in the table expression covers the initial part of a secondary table key without being specified explicitly after KEY, a syntax check warning is produced that can be hidden by a pragma, since the function is generally quicker if the secondary key is specified explicitly.
  • As in other use cases for table expressions, it is important that no duplicate selections are made, especially in the case of line_index. Generally speaking, it is best not to first check the line number using line_index and then read the line immediately using the index.
  • The predicate function line_exists can be used to check the existence of a line. The table function line_index can also be used to check whether a line exists. If the line is found, the result is not equal to 0 for every table category. A check on a value greater than 0, on the other hand, is sufficient only for index tables or when using sorted keys.

Example

The index function can be used on chained table expressions as follows, where the nested internal table accessed is taken from the example for Chainings with Table Expressions. The first read returns the value 1 for the first line of the innermost table. The second read returns the value 0, since there is no line available for the index read on the outermost table.

DATA(idx1) = line_index(
               itab[ 2 ][ 2 ][ KEY primary_key table_line = 7 ] ).

DATA(idx2) = line_index(
               itab[ 9 ][ 2 ][ KEY primary_key table_line = 7 ] ).

Internal Tables, Index Function






ROGBILLS - Synchronize billing plans   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.

Length: 6868 Date: 20240426 Time: 145523     sap01-206 ( 104 ms )