The &FNDSTR built-in function is used to locate a given data string (called the search argument) in another data string. This function requires special processing for DBCS data, to avoid a single byte character being located in a double byte string. For example, if searching for a single byte A (X'C1'), the second byte of a Kanji symbol represented by X'45C1' contains the X'C1' code, but it should not be considered a match.
The search argument is single byte data only, or double byte data only, or a mixture of single byte data and double byte data.
The search argument is stripped of consecutive shift out/shift in sequences before the scan is performed. For example, if the search argument is AA<>BB, the actual string searched for would be AABB. If the resulting string is null, a value of 0 will be assigned to the target variable.
If the search argument begins with a double byte character, the shift out is removed from the search argument before the scan is performed. If the search argument ends with a double byte character, the shift in character is removed from the search argument before the scan is performed. This allows a DBCS string to be located within another DBCS string.
If the search argument begins with a single byte character, a match only occurs in the case where the first character at the location at which the data was found, is a single byte character. If the search argument begins with a double byte character, a match only occurs where the first character at the location at which the data was found is a double byte character.
When using &CONTROL DBCS, DBCSN, or DBCSP, if the search argument is found in a section of data which is not the first section of data, a value of 999 is returned. This is the same as the processing with &CONTROL NODBCS.
Examples: &FNDSTR
&CONTROL DBCS &A = &FNDSTR <> AAA<>BBB
results in
&A = 0
After the shift out and shift in, characters are removed from the search argument. No data remains so the value returned is 0.
&CONTROL DBCS &A = &FNDSTR A<>B AAABBB
results in
&A = 3
After the shift out and shift in, characters are removed from the search argument. The search argument becomes AB.
&CONTROL DBCS &A = &FNDSTR <.B> AAA<.A.B.C>
results in
&A = 7
After the shift out and shift in, characters are removed from the search argument The search argument becomes a double byte character .B, which exists at offset 7.
&CONTROL DBCSN &A = &FNDSTR <.B> AAA<.A.B.C>
results in
&A = 6
After the shift out and shift in, characters are removed from the search argument. The search argument becomes double byte character .B, which exists at offset 6. The shift out character after AAA is not included in the calculation of the offset.
&CONTROL DBCS &A = &FNDSTR A <.A.B.C>
results in
&A = 0
Although the value for single byte A and the value for the second byte of the double byte .A are the same, no match occurs because the search argument is a single byte character and .A is a double byte character.
&CONTROL DBCS& A = &FNDSTR <.C>D <.A.B.C>DEF
results in
&A = 6
&A = &FNDSTR A<.B> AAA<.B.C.D>
results in
&A = 3
The search argument is a mixture of double byte data and single byte data.
&CONTROL DBCS &A = &FNDSTR <.A> AAAA BBBB CC<.A>DD EEEE
results in
&A = 999 (string found but not in first piece of data)
| Copyright © 2009 CA. All rights reserved. |
|