sapdev logo background
sapdev logo sapdev logo
Comments

SAP LINE EXISTS FUNCTION documentation, setup help and example usage



Return to SAP documentation index


ARTICLE

rel_exp - line_exists , Predicate Function

Syntax
... line_exists( table_exp ) ...

Effect
The predicate function
line_exists checks whether the row of an internal table specified in the table expression table_exp exists and returns the appropriate logical 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 statement READ TABLE with the addition TRANSPORTING NO FIELDS following by sy-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 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 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 row and then read it. Instead, the table expression can be assigned to a field symbol and then sy-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.

    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.
    Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




    LINE_ELEMENT_GLOSRY
    LINE_INDEX_ABEXA




    comments powered by Disqus