Analogous to IN operator of SQL in SAP

You can get similar functionality to SQL's IN operator done in many ways in SAP. You can use an internal table usage or a range table approach.

Let me showcase an example with an internal table for your reference.

Using Internal Table with FOR ALL ENTRIES

The FOR ALL ENTRIES clause in SAP allows you to filter data based on values from an internal table, similar to the IN operator in SQL ?

SELECT Id, Name, DOB
FROM sEmployee
INTO CORRESPONDING FIELDS OF TABLE result_tab
FOR ALL ENTRIES IN internal_tab
WHERE Id = internal_tab-Id
AND Name = internal_tab-Name

In this example, internal_tab is an internal table defined with columns that match the WHERE clause conditions. The system will fetch records where the Id and Name match any combination of values present in the internal table.

Using Range Table Approach

Alternatively, you can use a range table which is more similar to SQL's IN operator ?

DATA: lr_id TYPE RANGE OF sEmployee-Id.

" Populate range table
lr_id = VALUE #( ( sign = 'I' option = 'EQ' low = '001' )
                 ( sign = 'I' option = 'EQ' low = '002' )
                 ( sign = 'I' option = 'EQ' low = '003' ) ).

SELECT Id, Name, DOB
FROM sEmployee
INTO CORRESPONDING FIELDS OF TABLE result_tab
WHERE Id IN lr_id

This approach using range tables provides more flexibility and closely mimics the SQL IN operator behavior.

Conclusion

Both FOR ALL ENTRIES and range tables provide SQL IN operator equivalent functionality in SAP, with range tables offering more direct syntax similarity to standard SQL.

Updated on: 2026-03-13T18:52:01+05:30

197 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements