Example 2: Unique-key processing

This example shows how to read records using only some of the key fields.

Assume that you want to process the same file with the sequence: Slsman, Cust, Date, but you want only one record per Slsman and Cust. Assume that the records in the file are:

Slsman Cust Date Record #
01 5000 880109 1
01 5000 880115 2
01 4025 880103 3
01 4025 880101 4
02 3000 880101 5
You specify the number of key fields that are unique, starting with the first key field.
OVRDBF     FILE(FILEA) SHARE(*YES)
OPNQRYF    FILE(FILEA) KEYFLD(SLSMAN CUST DATE) UNIQUEKEY(2)
CALL       PGM(PGMD)
CLOF       OPNID(FILEA)
DLTOVR     FILE(FILEA)

The following records are retrieved by the program:

Slsman Cust Date Record #
01 4025 880101 4
01 5000 880109 1
02 3000 880101 5
Note: Null values are treated as equal, so only the first null value would be returned.