Release the NEW Power of CL

Release the NEW Power of CL

Name:

Email:

Programming Services

Do you need a program written?

Bruce Vining Services can provide highly experienced IBM i developers to supplement your staff with short term contracts. We don't do general ledger but if you are looking for custom solutions involving system functions such as database, communications, security, encryption, print, and work management you will find your answers at Bruce Vining Services.

Find String using XCL PDF Print E-mail

Find String using XCL (FNDSTRXCL)

Where allowed to run:
  • Batch program (*BPGM)
  • Interactive program (*IPGM)
Threadsafe: Yes
Parameters
Examples
Error messages

The Find String using XCL (FNDSTRXCL) command finds a string of one or more characters within a CL variable. The FNDSTRXCL command returns the position within the CL variable identifying the first byte of the found string.

This function is also available with command FNDSTR in library VC2XCL. Any use of this alternative command name should be library qualified in case the i operating system were to use this command name in a future release.

Top

Parameters

KeywordDescriptionChoicesNotes
STRING String to find Character value Required, Positional 1
VAR Variable to search Character value Required, Positional 2
POS Position string found at Integer Required, Positional 3
STRPOS Starting position in variable Integer, 1 Optional
IGNCASE Ignore case *YES, *NO Optional
STRCCSID CCSID of string 0-65533, *JOB, *ASCII, *UCS2, *UTF8, *UTF16 Optional
VARCCSID CCSID of variable to search 0-65533, *JOB, *ASCII, *UCS2, *UTF8, *UTF1 Optional
Top

String to find (STRING)

Specifies the character string to find within the VAR parameter.

If a CL variable is used trailing blank characters in the string are ignored. If a literal value is used trailing characters are ignored unless a quoted literal value is specified.

This is a required parameter.

character-value
Specify the string that is to be searched for.
Top

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.
Top

Position string found at (POS)

Specifies the CL variable which is to receive the starting position within the VAR variable which identifies the first match of the character string value found in the STRING parameter.

A returned value of 0 indicates that the string was not found.

This is a required parameter.

integer
Specify the name of the CL variable to receive the starting position of string found in the VAR variable.
Top

Starting position in variable (STRPOS)

Specifies the byte position within the VAR parameter where the search is to start.

1
The search starts with the first byte of the VAR parameter.
integer
Specify the byte at which the search should start.
Top

Ignore case (IGNCASE)

Specifies if lowercase and uppercase characters should be considered as matches when searching for the character string within the VAR parameter.

*YES
Lowercase and uppercase differences are ignored. For example an uppercase 'A' in the STRING parameter will be considered a match for a lowercase 'a' in the VAR parameter.
*NO
Lowercase and uppercase characters are considered as unique characters for matching purposes.
Top

CCSID of string (STRCCSID)

Specifies the CCSID of the character string identified by the STRING parameter.

*JOB
The character string identified by the STRING parameter is encoded using the job CCSID. If the job CCSID is 65535 the default job CCSID will be used.
*ASCII
The character string identified by the STRING parameter is encoded using CCSID 819 (ISO Latin 1).
*UCS2
The character string identified by the STRING parameter is encoded using CCSID 13488 (Unicode UCS2).
*UTF8
The character string identified by the STRING parameter is encoded using CCSID 1208 (Unicode UTF8).
*UTF16
The character string identified by the STRING parameter is encoded using CCSID 1200 (Unicode UTF16).
0-65533
Specify the CCSID of the STRING parameter data.
Top

CCSID of variable to search (VARCCSID)

Specifies the CCSID of the character data identified by the VAR parameter.

*JOB
The character data identified by the VAR parameter is encoded using the job CCSID. If the job CCSID is 65535 the default job CCSID will be used.
*ASCII
The character string identified by the VAR parameter is encoded using CCSID 819 (ISO Latin 1).
*UCS2
The character string identified by the VAR parameter is encoded using CCSID 13488 (Unicode UCS2).
*UTF8
The character string identified by the VAR parameter is encoded using CCSID 1208 (Unicode UTF8).
*UTF16
The character string identified by the VAR parameter is encoded using CCSID 1200 (Unicode UTF16).
0-65533
Specify the CCSID of the VAR parameter data.
Top

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.

Top

Error messages for FNDSTRXCL

*ESCAPE Messages

XCL500B
CCSID value of &1 is not supported.
XCL500C
Encoding scheme &1 not supported.
XCL500D
Function did not complete. See previously listed messages related to possible user errors.
XCL5014
Invalid start position specified.
XCL9002
Function did not complete. See previously listed messages related to possible user errors.
XCL9003
Function did not complete. See previously listed messages for possible cause.
XCL9004
Function did not complete. See previously listed messages for possible cause.
XCL9005
Function did not complete. Contact your service provider.
Top
 
Joomla 1.5 Templates by Joomlashack