Get Example source ABAP code based on a different SAP table
• line_exists ABAP_FUNCTION
ABAP_RELEXP > - line_exists>
ABAP_SYNTAX ... line_exists( table_exp> ) ...>
What does it do? The built-in> predicate function> line_exists> checks whether a line of an internal table specified> in the table expression> table_exp>> exists and returns the corresponding truth value>. In addition to single table expressions, chainings> can also be specified for table_exp>, whose result is a line of an internal table. Within line_exists>, 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.
Latest notes:
The table expression is only used to check the existence of the specified line. No temporary result> is created.
The predicate function line_exists> can be considered as a short form of the statement READ TABLE>> with the addition TRANSPORTING NO FIELDS>> followed by sy-subrc> being checked.
The predicate function line_exists> cannot be used to determine the line number in a table index of a search key used for the search, since table expressions do not fill the system field sy-tabix>. The table function line_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 after KEY>, a syntax check warning that can be hidden by a pragma occurs, since the function is generally more performant if the secondary key is specified explicitly.
As in other use cases of table expressions, line_exists> must be used carefully to avoid duplicate selections. Therefore, line_exists> should not be used to first check the existence of a line and then read it. Instead, the table expression can be assigned to a field symbol> and then sy-subrc> checked. If the line 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 lines that are not found, there is also the option of checking the existence of lines. NON_V5_HINTS ABAP_HINT_END