SQL Programming Manual for TAL

Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL527887-001
7-38
Handling Null Values
INT .EXT param^(sql^types); --pointer to buffer that
--will receive parameter value
--Procedure code:
--Set pointer to storage for current parameter value:
@param^ := isqlda^ptr.sqlvar[i].var^ptr;
-- call READX or WRITEREAD, depending on data type ...
IF (isqlda^ptr.sqlvar[i].null^info = -1) AND
(param^. datatype-field = "?") THEN
BEGIN
@ind^ := isqlda^ptr.sqlvar[i].IND^PTR;
ind^ := -1;
END;
Handling Null Values in Output Variables
DESCRIBE sets NULL^INFO to -1 if the output variable can be null (that is, if the
prepared statement included a null indicator). If the value returned is null, SQL checks
NULL^INFO and moves a -1 into the location pointed to by IND^PTR. (Errors are
returned if the value is null but NULL^INFO is 0 or if IND^PTR is an invalid address.)
Your program must check NULL^INFO to determine whether the value returned can be
null. If NULL^INFO contains a -1, then your program checks the location pointed to by
IND^PTR. If that location contains a -1, then a null value was returned. If the location
contains 0, then a nonnull value was returned and your program should get the value
from the location pointed to by VAR^PTR.
This example handles null values in output variables. BUF is a globally defined output
buffer. NEXT^BUF is a pointer to the end of data in the buffer. SBUF is a string buffer.
This example prints the string “NULL” to represent a null value.
@param^ := osqlda^ptr.sqlvar[i].var^ptr;
@ind^ := osqlda^ptr.sqlvar[i].IND^PTR;
IF osqlda^ptr.sqlvar[i].null^info = -1 AND
ind^ = -1 THEN
BEGIN
buf ':=' "NULL" -> @next^buf;
CALL WRITE(term,buf,$INT(@next^buf - @sbuf));
END
ELSE
--display values according to data type
Null Values and the Names Buffer
If your program processes indicator parameters, the names of the indicator parameters
are included in the names buffer after DESCRIBE INPUT executes. The IND^PTR field
points to the length field for the parameter name in the names buffer. This behavior is
parallel to that of VAR^PTR after DESCRIBE INPUT or DESCRIBE.
This diagram illustrates the structure of the names buffer immediately after DESCRIBE
INPUT when indicator parameters are present for two parameters, where len is a 2-