For starters: Looking at the name of the loop's iterator, it looks like you are iterating over SOnumberlist, but you need to iterate over ListOfSalesOrdersNumbers.
ListOfSalesOrdersNumbers needs to be ordered by the key field(s).
Before the loop create a LatestSalesOrdersNumbers-object
In the loop: