| **Navigation:**  [[introduction.htm|Language Reference]] > 13 - Built-in Functions >====== DUPLICATE (check for duplicate key entries) ====== | [[dropid return drag and drop string .htm|{{btn_prev_n.gif|Previous page}}]][[introduction.htm|{{btn_home_n.gif|Return to chapter overview}}]][[ellipse draw an ellipse .htm|{{btn_next_n.gif|Next page}}]] | | || | | **DUPLICATE(** | |// key //| **)** | | | | |// file //| | {{blk2blue.jpg|blk2blue.jpg}} | **DUPLICATE** | Checks duplicate entries in unique keys. | | //key// | The label of a KEY declaration. | | //file// | The label of a FILE declaration. | The **DUPLICATE** procedure returns a non-zero value (true) if writing the current record to the data file would post the "Creates Duplicate Key" error. With a //key// parameter, only the specified KEY is checked. With a //file// parameter, all KEYs declared without a DUP attribute are checked. DUPLICATE is most useful to detect potential duplicate key errors before writing to disk. The DUPLICATE procedure assumes that the contents of the RECORD structure data buffer are duplicated at the current record pointer location. Therefore, when using DUPLICATE prior to ADDing a record, the record pointer should be cleared with: GET(//file//,0). | **Return Data Type:** | LONG | **Example:** **IF Action = 'ADD' THEN GET(Vendor,0).            !If adding, clear the file pointer** **IF ****DUPLICATE****(Vendor)                             !If this vendor already exists** ** SCR:MESSAGE = 'Vendor Number already assigned'  !display message** ** SELECT(?)                                       !and stay on the field** **END** **See Also:** [[get read a record or entry .htm|GET]] [[add add an entry .htm|ADD]] [[dup allow duplicate key entries .htm|DUP]]