× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Tue, Sep 22, 2015 at 8:53 AM, Charles Wilt <charles.wilt@xxxxxxxxx> wrote:
In either RPG or SQL, when dealing with nullable columns, you have to test
for null before trying to look at the value.

You definitely have to test for null separately in RPG (using %NULLIND
as your example shows), which is part of why it's so clunky in RPG.

But you don't *have* to in SQL (and many other languages). You just
have to be aware of how null values interact. In SQL, NULL is a
"first-class" value. What I mean by first-class is that it is just as
valid as any other value (as far as the language is concerned); it can
appear where any other value appears.

In RPG, null doesn't even really exist as a value. It's an add-on
flag. A variable can be nullable or not, and if nullable, then its
add-on flag can be on or off. But it still has a value completely
separate and independent of this flag. That is, if you do a "straight
test" of the value of a nullable variable, it might be 5. Or 6. Or
'Hello world!'. Or complete garbage. And in any of these cases, the
nullable flag might be on. So it *tests* as 5, say, but it really
should be considered NULL, and you don't know that it's NULL unless
you explicitly check for it using %NULLIND.

Very, very clunky. And extremely prone to logic errors. I suspect
RPG-centric shops are much less likely to use nullable columns than
SQL-centric shops, in part for this reason. (In fact, I *hope* this is
the case!)

Maybe RPG will eventually improve its null support (by "improve" I
mean make RPG higher level, more like SQL and less like assembly).
VARLEN fields are conceptually similar in structure to nullable
fields: They have a "value" which consists of the bits stored in the
allocated data space, and they have an add-on attribute (length, in
the case of VARLEN fields; "is null" in the case of nullable fields).
The RPG compiler is smart enough to use the length attribute in most
contexts that involve a VARLEN field. I believe it shouldn't be too
much of a stretch for the RPG compiler to make similar use of the "is
null" attribute when working with nullable fields. (Though I think the
current behavior should stay as-is when the ALWNULL(*NO) compiler
option is specified.)

John Y.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.