NULL is Easytrieve's SQL-aware representation of an absent or unknown value. It is not a blank string, numeric zero, LOW-VALUES, an omitted file record, or end-of-file. A nullable database column has an indicator associated with its data area. IF PHONE NULL checks that indicator. MOVE NULL TO PHONE sets the nullable field's indicator to the null state. SQL INCLUDE with NULLABLE can generate and manage default indicator fields, while native SQL programs can define a manual indicator as a two-byte quantitative binary field and place it beside the host variable in the INTO clause. Arithmetic cannot safely assume NULL means zero: Broadcom documents a runtime error when any arithmetic operand is NULL. This tutorial explains automatic and manual indicators, IF NULL, MOVE NULL, NOT NULL assignments, SQL retrieval, reports, truncation indicators, validation, and the exact differences between NULL and other empty-looking constants.
A database must distinguish “the employee has no phone value recorded” from “the recorded phone is an empty string,” “the phone is all blanks,” and “the phone is zero.” NULL provides that distinction. The underlying data bytes are not sufficient to identify it; an indicator carries the status. Application logic must test NULL before using the data area, because bytes left there can be stale or irrelevant when the indicator says NULL.
| State | Business meaning | Easytrieve test |
|---|---|---|
| NULL | No known value exists | IF FIELD NULL |
| Spaces | Known character value is all blanks | IF FIELD SPACES |
| Zero | Known numeric value is zero | IF FIELD ZERO |
| LOW-VALUES | Known raw bytes are X'00' | IF FIELD LOW-VALUES |
The SQL INCLUDE statement can define fields from database declarations. Adding NULLABLE tells Easytrieve to generate default indicator fields for columns that allow NULL. The indicator is a two-byte binary field that precedes the data portion in storage. Easytrieve uses it automatically whenever the associated nullable field is referenced. Because the generated indicator cannot be directly referenced, use IF FIELD NULL for routine checks.
123456789SQL INCLUDE SQLCA SQL INCLUDE PERSONNEL NULLABLE JOB INPUT SQL NAME(READ-EMP) IF EMPPHONE NULL DISPLAY 'PHONE NUMBER IS UNKNOWN' ELSE DISPLAY EMPPHONE END-IF
Exact SQL INCLUDE naming depends on the database declaration and generated field names in your installation. The important point is that the nullable data field—not the hidden default indicator name—is the subject of IF NULL.
NULL is one of the documented field-class condition objects. Syntax is IF field-name [NOT] NULL. IF DEPTNAME NULL runs when no known department name was returned. IF DEPTNAME NOT NULL runs when the indicator says the data area contains a known value, even if that known value consists entirely of spaces. Add a SPACES test when both states must be distinguished.
123456789IF DEPTNAME NULL DISPLAY-NAME = 'UNKNOWN DEPARTMENT' ELSE IF DEPTNAME SPACES DISPLAY-NAME = 'BLANK DEPARTMENT' ELSE DISPLAY-NAME = DEPTNAME END-IF END-IF
MOVE NULL TO nullable-field marks the receiver NULL. It does not simply fill its visible data bytes with zero or spaces. A non-nullable receiver cannot represent that state, so Broadcom documents a runtime error when NULL is moved to a non-nullable field. Validate field definitions and SQL metadata before executing nullable assignments.
12345IF PHONE-SUPPLIED = 'N' MOVE NULL TO EMPPHONE ELSE EMPPHONE = INPUT-PHONE END-IF
In the ELSE branch, assigning a normal value sets the receiving nullable field to NOT NULL. Its indicator becomes zero under the documented assignment rules.
MOVE SPACES and MOVE ZERO are not substitutes for MOVE NULL. Broadcom says moving spaces or zeros to a nullable receiving field sets it to NOT NULL. This lets the program record a known blank or known zero. Choose based on business meaning. Replacing every NULL salary with zero may falsely state that an employee earned nothing, while NULL may mean payroll has not supplied the amount.
Native SQL statements and automatic retrieval without a generated nullable file can use manual indicators. Define the indicator as two-byte quantitative binary: 2 B 0. Put it after the corresponding host variable in the INTO clause. A negative indicator means the returned column is NULL. Zero normally means the value is present. Some DBMS products use positive indicator values to communicate truncation or length information, so consult the database-specific guide before interpreting every nonnegative value as identical.
12345678910111213DEFINE EMPNAME W 20 A DEFINE EMPPHONE W 3 P 0 DEFINE NULLPHONE W 2 B 0 JOB INPUT SQL NAME(READ-PERSONNEL) SELECT EMPNAME, EMPPHONE INTO :EMPNAME, :EMPPHONE :NULLPHONE FROM PERSONNEL IF NULLPHONE LT 0 EMPPHONE = 0 DISPLAY 'PHONE WAS NULL' END-IF
This example intentionally converts NULL to zero for a report after recording the state. In a production system, a display label or separate missing-value flag is often more honest than silently replacing unknown data with zero.
| Approach | Benefit | Tradeoff |
|---|---|---|
| SQL INCLUDE NULLABLE | Generated indicators and direct IF FIELD NULL | Default indicator is not directly referenced |
| Manual 2 B 0 indicator | Explicit access to indicator value | Program must pair every host variable correctly |
| Convert NULL after retrieval | Simplifies downstream report fields | Can lose unknown-versus-zero distinction |
Nullable assignments propagate state according to source and receiver definitions. Assigning a known value to a nullable receiver marks it NOT NULL. Assigning a NULL nullable source to a compatible nullable receiver preserves null status. Assigning NULL to a receiver that cannot hold NULL produces a runtime error. Check NULL before moving into legacy file fields that have no indicator.
SQL uses three-valued logic, but Easytrieve arithmetic does not automatically turn NULL into zero. Broadcom's Assignments and Moves rules state that an arithmetic expression with any NULL operand causes a runtime error. Guard every nullable quantity before addition, subtraction, multiplication, division, or SUM preparation.
1234567IF BONUS NULL DISPLAY-BONUS = 0 BONUS-MISSING = 'Y' ELSE DISPLAY-BONUS = BONUS TOTAL-PAY = BASE-PAY + BONUS END-IF
The flag preserves the fact that zero was substituted for display. The total calculation runs only when BONUS is known.
Reports should expose missing data rather than letting undefined bytes print. Derive a non-null display field and a readable label before PRINT. For numeric columns, a separate alphabetic status such as UNKNOWN may be clearer than printing 0.00. If business rules require zero substitution, explain it in the report title, footnote, or metadata.
123456789DEFINE PHONE-DISPLAY W 15 A IF EMPPHONE NULL PHONE-DISPLAY = 'NOT PROVIDED' ELSE PHONE-DISPLAY = EMPPHONE END-IF PRINT PERSONNEL-RPT
Before an SQL INSERT or UPDATE, MOVE NULL to nullable host fields that should have no value. Assign ordinary content when the column should be NOT NULL. Do not send spaces as a workaround unless a known blank value is the intended database state. Database NOT NULL constraints still apply independently of Easytrieve field definitions.
A VARYING field has length information and data. A zero-length string is still a known, NOT NULL value unless the null indicator says otherwise. That gives three potentially distinct cases: NULL, zero-length string, and a fixed or varying string containing spaces. Database and Easytrieve release behavior should be tested when an application depends on empty-string distinctions.
Flat files have no automatic SQL null indicator unless the layout defines one. When exporting database rows, decide how to encode NULL: a separate flag, a documented literal, an empty delimited column, or another agreed representation. Never assume spaces preserve NULL semantics. The receiving program must know how to reverse the encoding.
IF NULL, MOVE NULL, SQL INCLUDE NULLABLE, and manual two-byte indicators are documented in Broadcom Easytrieve Report Generator 11.6. Indicator details beyond negative-means-NULL can differ by DBMS, especially truncation handling. Confirm DB2, SQL/DS, IDMS SQL, or other database behavior used by your installation. Generated SQL INCLUDE layouts should be reviewed again after database schema changes.
Imagine a box for a phone number and a small sign beside it. Spaces mean someone knows the phone entry is blank. Zero means someone knows the number recorded is zero. NULL means the sign says “we do not know the value,” so whatever old marks remain inside the box should not be trusted. Easytrieve reads the sign before it uses the box.
1. What does SQL NULL mean?
2. What does IF PHONE NULL test?
3. A manual SQL null indicator is normally defined as:
4. What does a negative manual null indicator mean after SELECT?
5. What happens when an arithmetic expression uses a NULL operand?