Null indicator
A small extra field that tells a COBOL program whether a DB2 column it read was empty (null), since COBOL fields cannot hold null themselves.
Also written indicator variable, NULL, SQLCODE -305, -305
In DB2, a column can be null, which means it has no value at all. That is different from zero or spaces. COBOL fields cannot show this, because a COBOL field always contains something. A null indicator is how the two are joined up.
It is a separate binary field, PIC S9(4) COMP, paired with the host variable for a column that can be null. In the SQL you write the two together: FETCH ACCT-CURSOR INTO :WS-CLOSE-DATE :WS-CLOSE-DATE-IND. After the fetch, a negative value in the indicator, usually -1, means the column was null and the host variable should be ignored. Zero means a real value arrived.
If a program fetches a null column without an indicator, DB2 returns SQLCODE -305 and the statement fails. This is a common error when a column that never used to be null starts containing nulls.
Indicators work the other way too. Setting the indicator to -1 before an INSERT or UPDATE stores null in that column. DCLGEN can create indicator fields for you, which helps you remember them.
Where can I learn this hands-on?
Right here, at ZedBank. You take a junior job at a simulated bank and learn each part of the work by doing it, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- Embedded SQLSQL statements written directly inside a COBOL program, marked off so they can be prepared before compiling.
- SQLCODEThe result code DB2 returns after every SQL statement, saying whether it worked and what happened if it did not.
- DCLGENA tool that generates COBOL declarations matching a DB2 table, so the program's fields line up with the columns.
- CursorA mechanism for stepping through a set of rows one at a time, when a query returns more than one result.
- Binary fieldA COBOL number stored as a binary integer, written with USAGE COMP, COMP-4, BINARY or COMP-5.
- DB2 for z/OSIBM's relational database on the mainframe, where a great deal of the world's banking and insurance data is stored.