Referring to a Partial Key

To specify a partial key, you can use a KLIST with fewer KFLD specifications. In free-form calculations, you can also use %KDS with a second parameter indicating the number of keys, or a list of expressions with as many keys as you want. For example, if the file has three keys, but you only want to specify two keys, you can specify the partial key in any of the following ways.

DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++ 
D keys            DS                  LIKEREC(rec : *KEY)
CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq
C     klist2        KLIST
C                   KFLD                    k1
C                   KFLD                    k2
 /free
        CHAIN klist2 rec;                // KLIST with two KFLD entries
        CHAIN %KDS(keys : 2) rec;        // %KDS with two keys
        CHAIN (name : %char(id_no)) rec; // a list of two expressions

The rules for the specification of a search argument that refers to a partial key are as follows:

If a search argument refers to a partial key, the file is positioned at the first record that satisfies the search argument or the record retrieved is the first record that satisfies the search argument. For example, the SETGT and SETLL operations position the file at the first record on the access path that satisfies the operation and the search argument. The CHAIN operation retrieves the first record on the access path that satisfies the search argument. The DELETE operation deletes the first record on the access path that satisfies the search argument. The READE operation retrieves the next record if the portion of the key of that record (or the record of the specified type) on the access path matches the search argument. The READPE operation retrieves the prior record if the portion of the key of that record (or the record of the specified type) on the access path matches the search argument. For more information on the above operation codes, see the IBM Rational Development Studio for i: ILE RPG Reference.



[ Top of Page | Previous Page | Next Page | Contents | Index ]