On 19 Apr 2012 09:44, Albert York wrote:
I have an RPG program that is having a problem with var length
fields. I get the error 'unexpected null value' How can I fix this?
Rather than an issue with VarLen, the described would seem instead to
be an issue with AlwNull. If representation of the database NULL value
as the data type default [or field default; I can not recall] is an
acceptable outcome, then just compile the RPG using "Allow null values"
(ALWNULL) specification of *YES; i.e. ALWNULL(*YES), similar to
effectively same ALWNULL parameter on the CL DCLF "Declare File"
command. Otherwise use the *USRCTL specification for ALWNULL and be
sure to review the %nullind for each null-capable field to decide what
should be effect for [the representation of] the missing data.
Another option is to ask the database to replace the null value with
an actual value as an alternative, using a query file or logical VIEW.
For example, given the following "setup" actions, the later "prep#"
actions are examples of two different ways to have the database give a
replacement for the database NULL value so the RPG need not:
create table qtemp/nulltest (F varchar(45)) /* default NULL */
insert into qtemp/nulltest values('one'),(default),('three')
opnqryf qtemp/nulltest MAPFLD((F '%nonnull(1/F "*N")'))
cpyfrmqryf nulltest *print
dspsplf qsysprt splnbr(*last) /* expected output follows */
MBRNBR RCDNBR *...+... 1 ...+... 2 ...
1 1 one
1 2 *N
1 3 three
3 records copied to member or label *N in file QSYSPRT
create view qtemp/nulltnot as
( select ifnull(F, '*NoValue') as F from qtemp/nulltest )
select * from qtemp/nulltnot /* expected output follows */
******** End of data ***