Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Expressions and Functions for Conditions →  log_exp - Logical Expressions →  rel_exp - Comparison Expressions →  rel_exp - Relational Operators →  rel_exp - Relational Operators for All Data Types 

rel_exp - Tabular Relational Operator IN

Other versions: 7.31 | 7.40 | 7.54

Syntax


... operand [NOT] IN range_tab ...

Effect

In a comparison expression with the relational operator IN, the conditions of a ranges table or a table with this layout are checked. This means that an operand operand is checked to see whether it meets the conditions of the rows in the ranges table or (if the addition NOT is specified) whether it does not meet them. The tabular comparison expression is equivalent to a join using binary or ternary comparison expressions whose number is determined by the number of rows in the internal table.

Any internal table whose row type matches that of a ranges table or a functional method with the corresponding type of return value can be specified as a table range_tab. This includes, in particular, selection tables. The ranges table can be of any type. For the layout of a ranges tables, see TYPES RANGE OF. The evaluation of a ranges table requires the table to contain the valid values specified in that section in the columns sign and option. If the ranges table contains invalid values, an exception that cannot be handled is raised. If the ranges table is initial, the comparison expression is always true.

Each row in a non-initial ranges table is included in the join using one of the following comparison expressions. Depending on the operator in the column option, this involves a comparison between two operands using a binary relational operator or the delimitation of an interval using the ternary operator BETWEEN.

  • The operators "EQ", "NE", "GE", "GT", "LE", and "LT" produce a comparison of sizes:

    ... operand {EQ|NE|GE|GT|LE|LT} range_tab-low ...

    The relational operator is derived from the content of the column range_tab-option and the content of the column range_tab-low is used as the right operand.
  • The operators "CP" and "NP" produce a string comparison:

    ... operand {CP|NP} range_tab-low && range_tab-high

    The relational operator is derived from the content of the column range_tab-option and the content of the columns range_tab-low and range_tab-high is concatenated as the right operand.
  • The operators "BT" and "NB" produce a delimitation of an interval:

    ... operand [NOT] BETWEEN range_tab-low AND range_tab-high ...

    The comparison is made without the addition NOT if the content of the column range_tab-option is "BT" and with the addition NOT if the content is "NB". The content of the columns range_tab-low and range_tab-high is used for the interval boundaries.

operand is a general expression position and the usual comparison rules apply to operand and the columns low and high of the ranges table. The comparison expressions of the individual rows are joined as a logical expression in accordance with the following hierarchy:

  • The expressions of all rows that contain "I" in the column sign are joined using OR. If there are no rows that contain "E" in the column sign, this represents the entire logical expression.
  • The expressions of all rows that contain "E" in the column sign are joined using OR and then negated using NOT. If there are no rows that contain "I" in the column sign, this represents the entire logical expression.
  • If the content "I" and the content "E" are both in the column sign, AND is used to join the logical expression that is produced by step 1 with the logical expression from step 2

  • Notes

    • The rules above can be interpreted in such a way that the rows containing "I" or "E" in the column sign describe two value sets. The set for "I" is the inclusive set and the set for "E" is the exclusive set. By subtracting the exclusive set from the inclusive set, a results set is calculated that contains all values for which the entire logical expression is true.

    • The comparison rules are checked only at runtime and comparisons that are not allowed lead to exceptions.

    • The operator IN is, due to its implementation using binary relational operators, not suitable for selecting natural-language text content.

    Example

    Fills a ranges table in a SELECT loop and uses it in a logical expression in the condition operator COND.

    DATA range_tab TYPE RANGE OF scarr-carrid. 
    
    SELECT carrid 
           FROM scarr 
           INTO @DATA(wa). 
      range_tab = VALUE #( BASE range_tab 
                            ( option = 'EQ' 
                              sign   = 'I' 
                              low    = wa ) ). 
    ENDSELECT. 
    
    DATA carrid TYPE scarr-carrid. 
    cl_demo_input=>request( CHANGING field = carrid ). 
    
    cl_demo_output=>display( 
      COND #( WHEN to_upper( carrid ) IN range_tab THEN `Yes!` 
                                                  ELSE `No!` ) ). 
    

    Executable Example

    Ranges Tables in Relational Expressions

    Continue

    Comparison with Selection Table