Checking for Null Values

Article ID: 14584
Q: How can I use ILE to determine whether a physical file field is null?

A: When a field is null capable, an RPG program associates a null indicator with the field. For example, when a null-capable field is read from an externally described file, the field's null indicator is set to on if the field is null in the record; otherwise, the null indicator is set to off.

Use the %NullInd function in a logical expression to check for a null value in null-capable fields. If %NullInd returns *On, the field is null. This function requires that you specify AlwNull(*UsrCtl) in the H-specs or as a compile command parameter:

H AlwNull( *UsrCtl )

The code in Figure 1a checks for a null value, or if you're at V5R1, you can use the code in Figure 1b. You can also use %NullInd on the left side of an assignment expression to set the null indicator for null-capable fields to *On or *Off, as Figure 1c shows. You can also use the code in Figure 1d if you're at V5R1.

— Bryan Meyers

ProVIP Sponsors

ProVIP Sponsors