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).
uni(ELEMENT_LIST)
ELEMENT_LIST is a list of ELEMENTS separated by commas.ELEMENTS can be:
FIRST_INDEX..LAST_INDEX. If several dimensions exist, the index range or the index values must be given for all dimensions.INSTANCE(FIRST_INDEX..LAST_INDEX).PROPERTY.FIRST_INDEX and LAST_INDEX are integer value returning an index value in an array.INSTANCE is the name of an array of instances (class or representation).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.
# Are there duplicated values in the list? After execution, I contains 3
I=uni(24, 15, 24, 1, 2, 3, pi, 4, 5)
# Control of a collection where no duplicate values must exist on the CODE column
I = uni(this.LINES(1..maxtab(this.LINES)).CODE)
If I
J = 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
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:
uni returns 2.uni returns 3.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 array
I=uni(MYINSTANCE.LINES(1..maxtab(MYINSTANCE.LINES)).PROPERTY)
If I
DUPLICATE_VALUE=MYINSTANCE.LINES(I).PROPERTY
J=find(DUPLICATE_VALUE,MYINSTANCE.LINES(1..maxtab(MYINSTANCE.LINES)).PROPERTY)
SAME_DUPLICATE_VALUE=MYINSTANCE.LINES(J).PROPERTY
Endifuni is Integer. Note that uni can never return 1.
| Error code | Description |
|---|---|
| 8 | Range error for indexes. |
| 10 | The indexes given are not numeric. |
| 50 | Type mismatch on the list of expressions. |
| 55 | Too many dimensions given for an argument. |
find, max, min, sum, prd, avg, var.