KLIST (Define a Composite Key)

Free-Form Syntax (not allowed - use %KDS)
Code Factor 1 Factor 2 Result Field Indicators
KLIST KLIST name          

The KLIST operation is a declarative operation that gives a name to a list of KFLDs. This list can be used as a search argument to retrieve records from files that have a composite key.

You can specify a KLIST anywhere within calculations. The control level entry (positions 7 and 8) can be blank or can contain an L1 through L9 indicator, an LR indicator, or an L0 entry to group the statement within the appropriate section of the program. Conditioning indicator entries (positions 9 through 11) are not permitted. Factor 1 must contain a unique name.

Remember the following when specifying a KLIST operation:
  • If a search argument is composed of more than one field (a composite key), you must specify a KLIST with multiple KFLDs.
  • A KLIST name can be specified as a search argument only for externally described files.
  • A KLIST and its associated KFLD fields can appear anywhere in calculations.
  • A KLIST must be followed immediately by at least one KFLD.
  • A KLIST is ended when a non-KFLD operation is encountered.
  • A KLIST name can appear in factor 1 of a CHAIN, DELETE, READE, READPE, SETGT, or SETLL operation.
  • The same KLIST name can be used as the search argument for multiple files, or it can be used multiple times as the search argument for the same file.
  • A KLIST in a cycle-main procedure can have only global KFLDs associated with it. A KLIST in a subprocedure can have local and global KFLDs. For more information, see Scope of Definitions.

For more information, see Declarative Operations.

Figure 1. KLIST and KFLD Operations
*...1....+....2....+....3....+....4....+....5....+....6....+....7....+....
A*  DDS source
A          R RECORD
A            FLDA           4
A            SHIFT          1  0
A            FLDB          10
A            CLOCK#         5  0
A            FLDC          10
A            DEPT           4
A            FLDD           8
A          K DEPT
A          K SHIFT
A          K CLOCK#
A*
A*  End of DDS source
A*
A***********************************************************************
*...1....+....2....+....3....+....4....+....5....+....6....+....7....+....
CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq....
 *
 *  The KLIST operation indicates the name, FILEKY, by which the
 *  search argument can be specified.
 *
C     FILEKY        KLIST
C                   KFLD                    DEPT
C                   KFLD                    SHIFT
C                   KFLD                    CLOCK#

The following diagram shows what the search argument looks like. The fields DEPT, SHIFT, and CLOCK# are key fields in this record.

search argument