Вопрос

I've been told by our RPG programmer that none of our AS400-based DB2 database tables can permit nulls because nulls "are really difficult to program for" in RPG. I'd like to know if this is actually true and if so, what is it that makes this basic database feature so difficult to use in RPG?

I realize this may be slightly out of scope for Stack Overflow, but this is the best source I know for this kind of information.

Это было полезно?

Решение

The answer turns out to be "NULLS are allowed but require extra work." User Carl Groner commented above with a link to an excellent article which explains this from the RPG programmer's point of view. Here is the pertinent part which applied to my problem:

RPG/400 doesn't support processing NULLs in a database file. If a file contains NULLs, specifying the ALWNULL(*YES) compiler option on the Create RPG Program (CRTRPGPGM) command allows the program to access the file as input only, with the caveat that all NULL-capable fields contain the "default" value when a NULL is encountered. This means the RPG/400 program will have no way of distinguishing a NULL from a blank, for example.

Другие советы

IBM RPG does not currently support handling nulls directly, but they can be handled in a SQL call by using the ISNULL built in function:

exec sql declare X cursor for 
select ISNULL(numfield, 0), 
       ISNULL(alphafield, '')
from table
where field = value
for read only;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top