Defining Duplicate Keys |
Virtual Machine |
While for PROIV, usage the primary key of a record must always be unique within a file, duplicate alternate keys (more than one record with the same alternate key) are allowed. However, there is no way of specifying to PROIV whether or not duplicates are allowed, and so they can only be used when it is not necessary to uniquely access an individual record by key. Otherwise, the outcome will be unpredictable and, for example, in the case of a record deletion, the wrong record could be deleted. The cases in which a duplicate key can be reliably used to access a file are:
When it is specified as the primary file in an indexed paging LS and only lookup mode is used and no sort is specified.
When it is specified as the primary file in a LSupdate and no sort is specified.
When it is specified as the primary file in a LR or LU and no sort is specified.
To illustrate this, assume that in the CUSTOMER file example, a customer's name is not always unique, so that there will be duplicates. This is ideal when simply displaying a list of all the customers with a particular name, but cannot be used to retrieve an individual record where there are duplicates. A work around would be to define another alternate key comprising customer name concatenated with customer number (the primary key, which is unique).unique). Records are accessed in alphabetical order of customer name, but each record has a unique alternate key. The appropriate alternate key can then be specified for use depending on the situation in which it is to be used.
Topic ID: 720059