ClustrMaps

The roadrunner is back as never before! See also: My homepage or my very obsolete site
If by any means entries in my blog are considered to be harmful or damaging, please let me know (add comment) or just mail me. In this (unhopely) case I will remove or change the contents.

Tuesday, January 29, 2008

Much Ado about Nothing: Interesting Facts about Null

See: http://www.itjungle.com/fhg/fhg091405-story01.html
It's hard to believe that this much could be said about things that don't exist.

See also: http://www.itjungle.com/mpo/mpo082803-story02.html
The NULL Nemesis

The concept is simple enough. The ShipDate for the given OrderID is placed in program variable RPGShipDate. But what if ShipDate contains a NULL in the file? The way the program is coded now, when the statement retrieves a NULL the SQLCOD will contain error code -305, which has the primary error description of "indicator variable required."

This message indicates that SQL can't return the NULL value into a HLL program variable without the assistance of an "indicator" variable. An indicator variable is simply an extra variable, defined with an SQL data type of SMALLINT, containing either a zero or a negative 1, to indicate if the given variable is NOT NULL or NULL, respectively. Here's the revised code using an indicator variable that will behave correctly if a NULL is read:

D ShipDateNull    S              5I 0
D NULL S 5I 0 Inz(-1)
C Eval OrderID=11074
C/EXEC SQL
C+ SELECT ShipDate
C+ INTO :RPGShipDate:ShipDateNull
C+ FROM Orders
C+ WHERE OrderID=:OrderID
C/END-EXEC
C Select
C When SQLCOD=*Zero
C If ShipDateNull=NULL
… ShipDate is NULL – Process accordingly
C Else
… ShipDate is NOT NULL – Process accordingly
C EndIf

No comments: