You could add one to LISTER and use strictly less than, <, in the locate. Adding one to LISTER puts you one case past the one you want but with < you will get one case before that. There are some special cases to handle though.
It is possible that there is no case with GEO_CODE and LISTER that match the ones that you searching for so after the loadcase you would need to double check that the GEO_CODE and LISTER of the loaded case match the one that you searching for. For example say you had the following cases:
Code: Select all
GEO_CODE LISTER HH_NO
1 1 1
1 1 2
1 3 1
and you were searching for GEO_CODE=1, LISTER=2 you would end up calling locate with 1, 3 and it would find 1,1,2. In that case you would check that the loaded lister (1) against the value you were searching for (2) and since they are different you would treat it is if the locate had failed.
Another issue is if LISTER is already at it's max value then adding one will cause problems. For example if LISTER is a two digit value and you area searching for LISTER=99 then you can't pass 100 for lister. In that case you would add one to GEO_CODE and use that in the call to locate.
Here is what the logic would like. This assumes that GEO_CODE and LISTER are two digit numeric values. If they have different lengths you would have to adjust the lengths in the call to maketext and as well as change the max value for LISTER from 99 to whatever the new length would result in. GEO_CODE_FOUND and LISTER_FOUND are the variables names for geocde and lister in the TPL_HH_DICT. I'm assuming that GEO_CODE and LISTER are the names in the main dictionary.
// Get case that is one greater than one we are searching for
numeric nextGeoCode;
numeric nextLister;
if LISTER < 99 then
nextGeoCode = GEO_CODE;
nextLister = LISTER + 1;
else
// Can't increment LISTER since it is already at max so use next GEO_CODE
nextGeocode = GEO_CODE + 1;
nextLister = 0;
endif;
if locate(TPL_HH_DICT,<, maketext("%2d%2d", nextGeoCode, nextLister)) then
loadcase(TPL_HH_DICT);
// Make sure that case that was found matches the one we are searching for
if GEO_CODE_FOUND = GEO_CODE and LISTER_FOUND = LISTER then
$ = HH_NO + 1;
else
$ = 1;
endif;
else
$ = 1;
endif;