SETCURRENTKEY is it necessary

Hi All,

I have ready different opinions on using SETCURRENTKEY and it could be that this is not required in latest versions of BC (cloud) as the application does the optimization automatically to run the SQL statements. For example see below:

ValueEntry.SetCurrentKey(“Item Ledger Entry No.”);
ValueEntry.SetRange(“Item Ledger Entry No.”, Rec.“Entry No.”);
ValueEntry.SetRange(“Item Ledger Entry Type”, “Entry Type”::Sale);

if ValueEntry.Findlast() then

Do you need Setcurrent above?


SETCURRENTKEY is only needed to define the sort order of the result set. There does not even need to be a matching physical key on the table. It is the equivalent of the “Order By” clause" in the SQL Statement. Of course, all the caveats of sorting large datasets on non-indexed fields need to be considered. But that’s different topic.