On Wed, Sep 23, 2015 at 1:13 PM, Birgitta Hauser <Hauser@xxxxxxxxxxxxxxx> wrote:
But you don't *have* to in SQL (and many other languages).
You have to check NULL values with SQL separately: WHERE conditions IS NULL
Embedded SQL Indicator variables that have to be added.
You are not required to check for NULL separately in SQL if you know
how NULL interacts with other values, and can make use of those
interactions. As Raul Jager noted, in SQL you can (for example) test
whether a nullable date variable is greater than today. You just have
to be aware that if the variable is NULL, the result of the comparison
will be False. No separate "IS NULL" test is needed if that serves
your purposes.
In other situations, you may need to handle NULL differently, and in
those situations, you would need the "IS NULL" test.
In RPG, null doesn't even really exist as a value. It's an add-on flag.
A NULL value is a value out of the valid range! That must be checked
separately in RPG as well as in SQL.
Birgitta, it doesn't look like you read my post at all. In RPG, there
is definitely no such thing as a null value. I'm talking about pure
language mechanics, not about what programmers use the NULL concept to
represent. By "value" I am referring to the data bits. This value is
always present in RPG and is completely and utterly independent of the
null indicator.
Let's say I have a nullable variable call MYVAR. And let's say that
its null indicator is currently on. So in SQL, MYVAR is simply equal
to NULL. But in RPG, I can do this:
myvar = 5; // null indicator is not affected
x = %nullind(myvar); // x = '1'
y = (myvar > 2); // y = '1'
In SQL, MYVAR > 2 would be False, since any comparison with NULL is
False. But in RPG, MYVAR > 2 is actually True, because 5 is greater
than 2. Even though the null indicator is on!
In the database the NULL value is a flag that is set if it is a NULL value
and it is not set if it is no NULL value
My point is that if the null flag is on, you cannot get the data bits
out via SQL. You can't use SQL to find out that MYVAR is really "5,
but with null indicator on". In SQL, MYVAR is simply NULL. But in RPG,
you access the data bits and the null flag separately. And you are
free to ignore the null flag in RPG and just use the data bits. There
is no way to circumvent the null flag in SQL.
VARLEN fields are conceptually similar in structure to nullable fields.
No they aren't!
I explained the ways in which they are similar. Of course they are not
similar in other ways. RPG is similar to C. But it's also not similar
to C.
John Y.
As an Amazon Associate we earn from qualifying purchases.