PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Correcting duplicate Unique keys  (Read 1447 times)

PxPlus

  • Administrator
  • Diamond Member
  • *****
  • Posts: 1091
    • View Profile
Correcting duplicate Unique keys
« on: May 31, 2018, 10:47:14 AM »
If during the course of building a key tree for a data file the system detects that a duplicate key exists, the system will display the following message.

    Duplicate key found at NNNNN

The value displayed in NNNNN is the logical record address or index which can be used to locate and read the effected record.

To correct this problem read the record using an IND=NNNNN clause, change/correct the key field(s) and issue a WRITE to update the record. The system will remove the incorrect key pointer and insert the appropriate new key pointer.

For Example lets create a file which ultimately will have duplicate keys:

    ->keyed "keyfle",[1:1:6]
    ->open (1) "keyfle"
    ->write (1) "000001","123456"
    ->write (1) "000002","123456"
    ->close (1)

Add the index which will cause the problem:

    ->add index [2:1:6:"U"] to "keyfle"
    Duplicate key found at index 2050
    Done - loaded key number 1 with 2 keys

During the addition of the new key the system will attempt to load the key trees. Any errors will be reported both on the screen and, on PxPlus, the system logfile (see below).

To repair the records read by the record index and change the key:

    ->open (1) "keyfle"
    ->read (1,ind=2050) a$,b$
    ->print a$,b$
    000002123456
    ->b$="999999"
    ->write (1) a$,b$

A reload of the keys is not required but can be uses to verify the correction.

    ->keyed load (1)
    Done - loaded key number 0 with 2 keys
    Done - loaded key number 1 with 2 keys

-----------------------------
Note: In PxPlus (build 9180.3 and beyond), whenever a key table is loaded a log is sent of the rebuild process (including errors) to the logfile specified in the INI file for the system. The contents of this logfile can be used to keep track of any records with keys that need to be corrected. On the windows version the output is also sent to the Trace window which itself could be saved to a disk file if necessary.