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:
Post a Comment