EXISTS

EXISTS(recordset [, KEYED ] [, UNORDERED | ORDERED( bool ) ] [, STABLE | UNSTABLE ] [, PARALLEL [ ( numthreads ) ] ] [, ALGORITHM( name ) ] )

EXISTS( valuelist )

recordsetThe set of records to process. This may be the name of an index, a dataset, or a record set derived from some filter condition, or any expression that results in a derived record set.
KEYEDOptional. Specifies the activity is part of an index read operation, which allows the optimizer to generate optimal code for the operation.
valuelistA comma-delimited list of expressions. This may also be a SET of values.
UNORDEREDOptional. Specifies the output record order is not significant.
ORDEREDSpecifies the significance of the output record order.
boolWhen False, specifies the output record order is not significant. When True, specifies the default output record order.
STABLEOptional. Specifies the input record order is significant.
UNSTABLEOptional. Specifies the input record order is not significant.
PARALLELOptional. Try to evaluate this activity in parallel.
numthreadsOptional. Try to evaluate this activity using numthreads threads.
ALGORITHMOptional. Override the algorithm used for this activity.
nameThe algorithm to use for this activity. Must be from the list of supported algorithms for the SORT function's STABLE and UNSTABLE options.
Return:EXISTS returns a single BOOLEAN value.

The EXISTS function returns true if the number of records in the specified recordset is > 0, or the valuelist is populated. This is most commonly used to detect whether a filter has filtered out all the records.

When checking for an empty recordset, use the EXISTS(recordset) function instead of the expression: COUNT(recordset) > 0. Using EXISTS results in more efficient processing and better performance under those circumstances.

Example:

TrdRec := RECORD
  UNSIGNED2 Trd_ID;
  INTEGER4 Trd_bal;
  INTEGER4 Trd_hc;
END;

PersonRec := RECORD
  STRING20 FirstName;
  STRING20 LastName;
  DATASET(TrdRec) Trd;
END;

Person := DATASET([{'Noah','Brody',[]},
                   {'Fred','Jones',[{1,2,3},{2,4,5}]},
                   {'Sue','Smith',[{10,-2,60},{12,14,50}]},
                   {'Joe','Johnson',[{11,200,3000},{22,140,350},{25,100,850}]},
                   {'Susan','Stone',[{102,2,30},{125,14,50},{225,14000,50000}]}],PersonRec);
Trades := Person.Trd;

MyBoolean := EXISTS(Trades(Trd_ID = 15));
OUTPUT(MyBoolean);            //returns FALSE

TradesExistPersons := Person(EXISTS(Trades));
OUTPUT(TradesExistPersons);   //returns 4 records

NoTradesPerson := Person(NOT EXISTS(Trades));
OUTPUT(NoTradesPerson);       //returns 1 record

SetExists1 := EXISTS(4,8,16,2,1); 
OUTPUT(SetExists1);            //returns TRUE

SetVals := [4,8,16,2,1];
SetExists2 := EXISTS(SetVals); 
OUTPUT(SetExists2);            //returns TRUE

EmptySet := [];
SetExists3 := EXISTS(EmptySet);
OUTPUT(SetExists3);            //returns FALSE

See Also: DEDUP, Record Filters