Comparing records

Records can be compared with the == comparison operator and the .* notation.

It is possible to compare records by using the .* notation and the == or != operators:
IF rec1.* == rec2.* THEN

All members will be compared individually.

Important: If the record contains members of type ARRAY[n], DYNAMIC ARRAY, DICTIONARY or TEXT/BYTE, the comparison will always evaluate to FALSE, except when TEXT/BYTE members are NULL in both records. Consider testing each record member individually. Eventually, the size of TEXT/BYTE members can be compared with the LENGTH() function.

If the record contains several levels of sub-records, all sub-records will be processed recursively.

If two record members are NULL, the result of this member comparison is TRUE.

If two corresponding members do not contain the same value, or one of them is NULL, the records are considered as different.

Tip: Record comparison can be used to implement optimistic locking for database updates. For more details, read the SQL programming guide.
The next code example shows how to compare two records defined from the same type:
            id INTEGER,
            name VARCHAR(50),
            address RECORD
                num VARCHAR(5),
                street VARCHAR(100)
            END RECORD

    DEFINE r1, r2 t_cust

    LET = 999
    LET = "Mike Torme"
    LET r1.address.num = "2A"
    LET r1.address.street = "Sunset bld"

    LET r2 = r1
    DISPLAY "1: ", IIF( r1.* == r2.*, "Equals", "Differs" )

    LET = "Mike Torm"
    DISPLAY "2: ", IIF( r1.* == r2.*, "Equals", "Differs" )

    LET = NULL
    DISPLAY "3: ", IIF( r1.* == r2.*, "Equals", "Differs" )

1: Equals
2: Differs
3: Differs