on 02-22-2006 5:08 AM
Does anyone know if the following is a known SAP .NET Connector issue, or if a work-around exists?
Here's the issue:
When using the "FindBy" method, the SAP documentation states that it will position to the 1st occurrence meeting the criteria specified. This does not appear to be the case.
-
Example:
I have a table with 6 rows. Table is 0-based.
The key field I'm finding by is populated as follows for the table:
10
10 <---
20
20 <---
30 <---
30
If I find by "10", row 1 is returned (<---). It should return 0.
If I find by "20", row 3 is returned (<---). It should return 2.
If I find by "30", row 4 is correctly returned (<---)
-
Findings:
It appears that the results of the FindBy return one row greater than the first occurrence except if the value requested is last in the list of values. In that case, it correctly returns the first occurrence of the value.
You are right, the documentation is not correct: FindBy sorts the table and uses ArrayList.BinarySearch to find a matching item. The binary search algorithm searches for an arbitrary matching entry - not for the first one. If you get the first second or any other fitting line is simple random.
I recommend to work arround by searching backward until you find a row that doesn't match:
int index = table.FindBy(fieldname, fieldvalue);
if (index >= 0)
{
IComparable reference = table[index];
for (int i= index; i<=0; i--)
{
IComparable row = table<i>;
if (0 != row.Compare(reference)
return i+1;
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.