SeekBy vs SetFilter
 
This help topic assumes you are already familiar with the use of SeekBy methods, and builds on the examples in that other help topic.
 
The purpose of the SetFilter() method, is to have a way where end-users (not the developer of the SDK application) would have a means to provide custom filtering much in the same way as an end-user can filter a Venice worksheet, using a syntax they are already familiar with.
 
If you use SetFilter() in an SDK application and are doing so with a hardcoded expression, then you really should use a custom SeekBy/GetNext loop with a limit and/or a filter instead. The performance gains will be noticeable. If you can use a limit, the performance difference and network load improvement are very significant.
 
When you write the following bit of code:
 
ObjSales.SeekByClassCode(smFirst, ""); // set ordering only, position is irrelevant
bool more = ObjSales.SetFilter("@ASL.ClassCode=='WEBSHOP' && @ASL.Remark=='Gift'");
while (more)
{
    DoSomething(ObjSales);

    more = ObjSales.GetNext();
}
 
Then what it essentially does is:
 
ObjSales.SeekByClassCode(smFirst, ""); // set ordering only, position is irrelevant

string rawExpression = "@ASL.ClassCode=='WEBSHOP' && @ASL.Remark=='Gift'";
bool more = ObjSales.SeekBy<LastUsedKey>(smFirst);
while (more)
{
    string expression = rawExpression;
    ReplaceFields(expression, objSales); // Replace @-fields in the expression with the actual values from the file.
    if (Evaluate(expression)==true)      // Parse and evaluate the expression
    {
        DoSomething(objSales);
    }

    more = ObjSales.GetNext();
}
 
There are 3 places where noticeable performance is lost (there is a bit of overhead here and there not shown in the above code, but it will barely make an impact):
ReplaceFields(): The way the Venice expressions work, field identifiers in the expression are being replaced with the corresponding value from the record. This necessarily happens for ALL fields, and there is no way to optimize this such that replacing only happens for fields that matter for a specific use case.
Figuring out which fields there are and doing the actual replacements involves additional string manipulations.
While this is efficient, if you are doing this for a few thousand records, this will quickly add up to several seconds of additional processing work.
Evaluate(): The expression string is parsed and evaluated. Every part of the expression is fully evaluated.
A hardcoded filter in the programming language you are using the SDK in, may benefit from:
- short circuit evaluation so not all fields are fetched from the record.
- Your programming language can be compiled into machine code, or translated into an intermediate language allowing for faster evaluation.
Again, this is not dramatic, but if you are doing this for a few thousands records, this too will add up to several seconds of processing work.
Fetching the entire file: SetFilter() always evaluates every record of the file. This is sometimes unavoidable. But if a limit is applied, this makes a very significant difference because not all records in the file are fetched.