Good idea,
I think at some point in the original code you'd find a place where "unlisted" sales men can be given a name, or they always just remain records to balance or store some promotions not given to any salesman but staying with the company.
VFP offers a project search within the tools menu, called "Code References". If you search for "unlisted" there, you should find that code. Not sure if you even have a pjx yet, perhaps just a folder with PRs, but Code references also covers that case in its options where to search.
And by the way, the two simplest approaches of updating an existing record ot inserting a new one, if no record with an id (tempcode) is found are:
1. SQL
Code:
UPDATE table Set somefield = somevalue ...(perhaps more changes)... WHERE somefield=someid (or tempcode in this case)
IF _tally=0
INSERT INTO table (fieldlist) VALUES (valuelist)
Endif
2. xBase
Code:
Select table && in this case SELECT salesman
If NOT SEEK(tempcode,'salesman','code') && or whatever tag name for the code field exists
APPEND BLANK
REPLACE ...
* in this special case:
* REPLACE code with tempcode, name with "unlisted"
ENDIF
REPLACE somefield with somevalue...
* in this special case
REPLACE collect with collect + pay
In both cases there's no use of <>, you "think positive", you seek an existing record with either where field equals value (not unequal <>) or you SEEK a value in an index, which also means it equals that value. If it's not found, then you add a record. In both cases you're now on a record that has the code and a salesman name or "unlisted" and can add whatever pay is given in that record.
What I wonder is how pay is given, if it's differing per salesman, what is the default for it? If it should be a promotion payment that's depending on the deal/product and not the salesmen, it seems wrong to take it from the salesman record, it should be a variable/parameter. But if this commission is salesman dependent, then this is okay. In any case that's not a technical problem, that's just a business rule decision. What to look out for is how pay is defined for a new BLANK record. The original clipper code also doesn't set it, so there either is a default value for pay in new records or it's 0, and unlisted salesmen get no pay. In which case you could also skip the step of adding pay to collect for "unlisted" salesmen.
Last, not least: You can see the original code is repetitive, not most elegant in itself:
Code:
...
if found()
[highlight #FCE94F]replace salesman.collect with salesman.collect + salesman.pay[/highlight]
else
append blank
replace salesman.code with tempcode
replace salesman.name with "unlisted"
[highlight #FCE94F]replace salesman.collect with salesman.collect + salesman.pay[/highlight]
endif
instead what could be done is:
Code:
...
if not found()
append blank
replace code with tempcode, name with "unlisted"
endif
replace collect with collect + pay
The major change is not having the collect+pay replacement in both cases but as final step of either finding the record or creating it.
The not found case only needs to add a record with the right code and a name.
It's not fair to judge the clipper code by one case, but the original developer likely didn't solve things in the best way already. And once more, that code also works in VFP, there's actually no need to change it that much, if you want to get through with conversion it pays in saving time to leave code as is if it's also working in VFP that way.
Chriss