Supported by
Supported by Inetum

The RANGEs double negatives

images/thumbnail.jpg - Thumbnail

RANGEs have interesting properties.

Take these two lines as an example. They look the same but they behave differently:

Sign | Option | Low

—|—|—

I | NE | X

E | EQ | X

Crazy, right?

Yesterday I bumped into yet another weird double negative which I had never thought about. When using a RANGE as a criteria in a SELECT WHERE and the range is empty, the criteria will always return TRUE. It is counter-intuitive because the mathematically correct would be FALSE (after all, the value is not in the range), but the way it behaves is very convenient as we all know. An empty RANGE behaves like a wildcard. Ok. Fair enough.

But, what if we add a NOT:

DATA r TYPE RANGE of kunnr.

SELECT * FROM kna1 INTO TABLE @data(t)
WHERE kunnr NOT IN r.

The RANGE is empty so we’re sure none of the KUNNRs will be there so, mathematically speaking, it should always return TRUE. But, since the empty RANGE works as a wildcard and returns TRUE when it should return FALSE,… its negative will return FALSE when it should return TRUE. And this is good. I guess…

Greetings from Abapinho.