ABAP Keyword Documentation → ABAP − Reference → Program Flow Logic → Expressions and Functions for Conditions → log_exp - Logical Expressions → rel_exp - Predicates → rel_exp - Predicate Functions → Predicate Functions for Table-Like Arguments
rel_exp - line_exists, Predicate Function
Other versions:
7.31 | 7.40 | 7.54
Syntax
... line_exists( table_exp ) ...
Effect
The predicate function line_exists
checks whether a row of an internal table
specified in the
table
expression table_exp
exists and returns the appropriate
truth value. Alongside single table expressions, table_exp
can also handle
chainings, whose result is a row of an internal table.
Within line_exists
, an explicitly specified table key in the table row
table_line
of the table expression is handled in the same way as a free search key specified for this table key.
Notes
- The table expression is only used to check the existence of the specified row. No temporary result is created.
- The predicate function
line_exists
can be considered as a short form of the statementREAD TABLE
with the additionTRANSPORTING NO FIELDS
followed bysy-subrc
being checked.
- The predicate function
line_exists
cannot be used to determine the row number in a table index of a search key, since table expressions do not fill the system field sy-tabix. The table functionline_index
can be used instead.
- 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 afterKEY
, a syntax check warning is produced (which 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,
line_exists
must be used carefully and no duplicate selections made. For example,line_exists
should not be used to first check the existence of a row and then read it. Instead, the table expression can be assigned to a field symbol and thensy-subrc
checked. If the row in question usually exists, the table expression can be specified in the required operand position and the exception CX_SY_ITAB_LINE_NOT_FOUND caught.
- As well as assigning a table expression a default value for rows that are not found, there is also the option of checking the existence of rows.
Example
DATA flight_tab TYPE HASHED TABLE OF spfli
WITH UNIQUE KEY carrid connid.
SELECT *
FROM spfli
INTO TABLE @flight_tab.
IF line_exists( flight_tab[ carrid = 'LH'
connid = '0400' ] ).
...
ENDIF.