Navigation: Language Reference > 13 - Built-in Functions >====== DUPLICATE (check for duplicate key entries) ====== | |
DUPLICATE( | key | ) | ||
file |
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: