Variable to search (VAR)
Specifies the CL variable that is to be searched for the string of characters identified by the STRING parameter.
If the CL variable contains trailing blank characters command analyzer defaults to trimming the blank characters. Specifying a non-blank character in the last position of the VAR parameter, such as with VAR(&DATA *CAT '!'), will cause trailing blank characters in CL variable &DATA to be included in the search. To avoid incorrect results make sure that the concatenated character (such as the '!' in the example) is not part of the STRING value being searched for.
This is a required parameter.
- character-value
- Specify the CL variable to be searched.
Examples for FNDSTRXCL
Example 1: Finding the String 'abc' Without Case Sensitivity
Dcl Var(&String) Type(*Char) Len(10) Value('abc')
Dcl Var(&Target) Type(*Char) Len(256) +
Value('ABCDEabcdeAbCdE')
Dcl Var(&Pos) Type(*Int)
FndStrXCL String(&String) Var(&Target) Pos(&Pos)
This example finds the string 'abc' within the CL variable &Target. When the FNDSTRXCL command runs a value of 1 is returned in CL variable &Pos. The string 'abc' compares as equal to the value 'ABC' found in position 1 of &Target as the Ignore Case (IGNCASE) parameter is defaulting to the value *YES.
Example 2: Finding the String 'abc' With Case Sensitivity
Dcl Var(&String) Type(*Char) Len(10) Value('abc')
Dcl Var(&Target) Type(*Char) Len(256) +
Value('ABCDEabcdeAbCdE')
Dcl Var(&Pos) Type(*Int)
FndStrXCL String(&String) Var(&Target) Pos(&Pos) IgnCase(*No)
This example finds the string 'abc' within the CL variable &Target. When the FNDSTRXCL command runs a value of 6 is returned in CL variable &Pos. The string 'abc' compares as equal to only the value 'abc' found in position 6 of &Target as the Ignore Case (IGNCASE) parameter is set to the value *NO.
Example 3: Finding the ASCII String 'abc' Without Case Sensitivity
Dcl Var(&String) Type(*Char) Len(10) Value('abc')
Dcl Var(&Target) Type(*Char) Len(256) +
Value(x'414243444561626364654142434445')
Dcl Var(&Pos) Type(*Int)
FndStrXCL String(&String) Var(&Target) Pos(&Pos) VarCCSID(*ASCII)
This example finds the string 'abc' within the CL variable &Target. When the FNDSTRXCL command runs a value of 1 is returned in CL variable &Pos. The string 'abc' compares as equal to the value 'ABC' found in position 1 of &Target as the Ignore Case (IGNCASE) parameter is defaulting to the value *YES. The STRING parameter is encoded in the job CCSID. The VAR parameter is encoded in ASCII. The *ASCII special value is associated with CCSID 819 - ISO Latin 1. The characters represented in the VAR parameter are the same as those used in Example 1.
Example 4: Finding the ASCII String 'abc' With Case Sensitivity
Dcl Var(&String) Type(*Char) Len(10) Value('abc')
Dcl Var(&Target) Type(*Char) Len(256) +
Value(x'414243444561626364654142434445')
Dcl Var(&Pos) Type(*Int)
FndStrXCL String(&String) Var(&Target) Pos(&Pos) IgnCase(*No) +
VarCCSID(819)
This example finds the string 'abc' within the CL variable &Target. When the FNDSTRXCL command runs a value of 6 is returned in CL variable &Pos. The string 'abc' compares as equal to only the value 'abc' found in position 6 of &Target as the Ignore Case (IGNCASE) parameter is set to the value *NO. The STRING parameter is encoded in the job CCSID. The VAR parameter is encoded in the CCSID 819 - ISO Latin 1. The characters represented in the VAR parameter are the same as those used in Example 2.
Example 5: Finding All Instances of 'de' Without Case Sensitivity
Dcl Var(&Target) Type(*Char) Len(256) +
Value('ABCDEabcdeAbCdE')
Dcl Var(&Pos) Type(*Int)
Dcl Var(&Pos_Chr) Type(*Char) Len(10)
FndStrXCL String('de') Var(&Target) Pos(&Pos)
DoUntil Cond(&Pos *EQ 0)
ChgVar Var(&Pos_Chr) Value(&Pos)
SndPgmMsg Msg('Found at' *BCat &Pos_Chr)
ChgVar Var(&Pos) Value(&Pos + 2)
FndStrXCL String('de') Var(&Target) Pos(&Pos) +
StrPos(&Pos)
MonMsg MsgID(XCL5014) Exec(Leave)
EndDo
This example finds all occurrences of the string 'de' within the CL variable &Target. The STRPOS keyword is used to increment the starting position within the VAR value past each instance of 'de' that is found. When the DOUNTIL loop runs the following messages will be displayed.
Found at 0000000004
Found at 0000000009
Found at 0000000014
The MONMSG for XCL5014 is necessary as the string 'de' is found in the last two data positions of the VAR parameter value. Incrementing the STRPOS value by 2 after finding the third occurrence of 'de' will cause a start position of 16 which is greater than the blank trimmed length of the VAR parameter value. If the 'CHGVAR VAR(&POS) VALUE(&POS + 2)' statement were changed to 'CHGVAR VAR(&POS) VALUE(&POS + 1)' then the MONMSG command would not be necessary. The DOUNTIL loop would however run more often as the 'e' of each 'de' occurrence would now be tested.