0% found this document useful (0 votes)
815 views2 pages

Wikibanking - info-LOCATE and FINDSTR Functions

The document compares the LOCATE and FINDSTR functions for searching values in arrays. LOCATE requires specifying the array dimension, while FINDSTR does not. FINDSTR searches an array and sets variables to indicate if the value was found in the flat, multi, or sub-valued portions of the array. An example shows using FINDSTR to search an array and set variables YY.OR.MED.FM, YY.OR.MED.VM, YY.OR.MED.SM to contain the found value or empty string if not found.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
815 views2 pages

Wikibanking - info-LOCATE and FINDSTR Functions

The document compares the LOCATE and FINDSTR functions for searching values in arrays. LOCATE requires specifying the array dimension, while FINDSTR does not. FINDSTR searches an array and sets variables to indicate if the value was found in the flat, multi, or sub-valued portions of the array. An example shows using FINDSTR to search an array and set variables YY.OR.MED.FM, YY.OR.MED.VM, YY.OR.MED.SM to contain the found value or empty string if not found.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

wikibanking.info http://www.wikibanking.

info/2013/09/findstr-instead-of-locate-function/

LOCATE and FINDSTR functions

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:

For an array looking like this: value1:@FM:value2:@FM:value3:@FM:value4

LOCATE "value2" IN array<1> SETTING POS THEN


...
END

will fill variable “POS” with “2”.

LOCATE "toto" IN array<1> SETTING POS THEN


...
END

will fill variable “POS” with “5”.

Need to find part of the content of a value in an array?

SUBSTRINGS() is the solution!

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)

LOCATE 'PM' IN SCHED.TYPES<1,1> SETTING POS THEN

END

An alternative to LOCATE is FINDSTR


Compared to LOCATE function, knowing the dimension of the array is not a pre-requisite with FINDSTR.
Example:

YY.OR.MED.FM = ''
YY.OR.MED.VM = ''
YY.OR.MED.SM = ''

FINDSTR searched_value IN array SETTING YY.OR.MED.FM, YY.OR.MED.VM, YY.OR.MED.SM ELSE


YY.OR.MED.FM = “”

IF YY.OR.MED.FM THEN
...
END

You just need to adapt the correct data separator, depending on the structure of the ARRAY.

You might also like