Uni

uni allows you to verify if there are duplicated values in a list of variables or expressions that can have any type (numeric, string CLOB, dates, UUIDs, or datetime).

Syntax

 uni(ELEMENT_LIST)

The expressions must have comparable types:
* Date types can be compared with Date and Datetime types.
* Decimal types can be compared with TinyInt, Shortint, Integer, Float, and Double types.
* Char can be compared with Schar and Clbfile types.

Examples

 # Are there duplicated values in the list? After execution, I contains 3I=uni(24, 15, 24, 1, 2, 3, pi, 4, 5)# Control of a collection where no duplicate values must exist on the CODE columnI = uni(this.LINES(1..maxtab(this.LINES)).CODE)If IJ = find(this.LINES(I).CODE,this.LINES(1..maxtab(this.LINES)).CODE)[L]ASTATUS=Fmet this.ASETERROR("","Duplicate code"-this.LINES(I).CODE-"at lines"-num$(I)-"and"-num$(J),[V]CST_AERROR)Endif

Description

uni allows you to verify if at least a duplicate value is present on a list of values. uni returns the rank of the first duplicate value on the list, and returns 0 if no duplicate value is found. For example:

If one of the arguments is an array variable, all the elements are considered, except if an index or an index range is given to limit the indexes.

If an index interval is given so that no value is included (for example, uni(ARRAY(1..0)), the result returned is 0.

When an element in an array of instances is considered (for example, MYINSTANCE(1..N).PROPERTY), the elements in the array that are not allocated (the values of I for which MYINSTANCE(I)equals Null) are counted even if there is no PROPERTY value assigned. This means that the following code is valid:

 # Works even if all LINES instances are not defined in the MYINSTANCE.LINE arrayI=uni(MYINSTANCE.LINES(1..maxtab(MYINSTANCE.LINES)).PROPERTY)If IDUPLICATE_VALUE=MYINSTANCE.LINES(I).PROPERTYJ=find(DUPLICATE_VALUE,MYINSTANCE.LINES(1..maxtab(MYINSTANCE.LINES)).PROPERTY)SAME_DUPLICATE_VALUE=MYINSTANCE.LINES(J).PROPERTYEndif

The type of result foruni is Integer. Note that uni can never return 1.

Associated errors

Error codeDescription
8Range error for indexes.
10The indexes given are not numeric.
50Type mismatch on the list of expressions.
55Too many dimensions given for an argument.

See also

find, max, min, sum, prd, avg, var.