Wikibanking - info-LOCATE and FINDSTR Functions
Wikibanking - info-LOCATE and FINDSTR Functions
info/2013/09/findstr-instead-of-locate-function/
LOCATE Function
When searching for a value in an array, you can use the common “LOCATE” function.
You need to specify the dimension of the array, considering that you’re looking for a string in a:
valued array (separator= FM), you will use: LOCATE xxx IN array<1> SETTING POS THEN…
multivalued array (separator= VM), you will use: LOCATE xxx IN array<1,1> SETTING POS THEN…
subvalued array (separator= SM), you will use: LOCATE xxx IN array<1,1,1> SETTING POS THEN…
Note:
– if the searched value is found, variable “POS” indicates the position in the array (after the “THEN”)
– if not found, “POS” indicates the next position immediately available in the array (after the “ELSE”), e.g.
dimension of the array +1.
Example 1:
Example: You have to find a constant that may be PMUF or PMPR or anything else looking like “PM…” in the
array R.NEW(SW.AS.TYPE)
SCHED.TYPES = SUBSTRINGS(R.NEW(SW.AS.TYPE),1,2)
END
YY.OR.MED.FM = ''
YY.OR.MED.VM = ''
YY.OR.MED.SM = ''
IF YY.OR.MED.FM THEN
...
END
You just need to adapt the correct data separator, depending on the structure of the ARRAY.