2

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!

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Kjarlvi
  • 126
  • 1
  • 13

2 Answers2

5

This is the standard behaviour, as documented in the ABAP Help:

"If the internal table itab is empty, the entire WHERE condition is ignored."

https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abenwhere_logexp_itab.htm

Check if the table is not empty before the SELECT:

IF lt_customer IS NOT INITIAL.
  SELECT ...
  ...
  FOR ALL ENTRIES IN lt_customer
  ...
ENDIF.
József Szikszai
  • 4,791
  • 3
  • 14
  • 24
  • 1
    Thanks, due to the large volume of data, it throws dump bc of the memory allocation. thanks again! – Kjarlvi Aug 05 '20 at 11:42
  • 1
    @Kjarlvi It's a very frequent pitfall even seasoned ABAP programmers stumble into from time to time. – Philipp Aug 05 '20 at 14:06
0

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.

mkysoft
  • 5,392
  • 1
  • 21
  • 30