FOR ALL ENTRIES through empty itab selects all records from DB

Viewed 680

I have a query in which I am using FOR ALL ENTRIES. The internal table lt_customer has no records.

SELECT *
    FROM bsid
    INTO CORRESPONDING FIELDS OF TABLE lt_customer2
    FOR ALL ENTRIES IN lt_customer
    WHERE bukrs EQ p_bukrs
      AND belnr EQ lt_customer-belnr
      AND gjahr EQ lt_customer-gjahr.

Now, since lt_customer has no record, I am expecting a dump here. But it turns out that it was selecting all the records from bsid into lt_customer2. I don't understand why or how. Please enlighten me. Thanks!

2 Answers

FOR ALL ENTRIES working look like IN operator. If itab empty then this condition ignored. You need to make manual check or add dummy record to lt_customer.

Related