Scan a CL Variable (CLSCAN)

Where allowed to run:
  • Batch program (*BPGM)
  • Interactive program (*IPGM)
  • Batch ILE CL module (*BMOD)
  • Interactive ILE CL module (*IMOD)
Threadsafe: No
Parameters
Examples
Error messages

The Scan a CL Variable (CLSCAN) command scans a CL variable for the specified pattern and returns its location to another CL variable.

Restrictions:

Top

Parameters

Keyword Description Choices Notes
PATTERN Search for pattern Character value Required, Positional 1
SCHDATA Data or CL variable to search Character value Required, Positional 2
CASE Match upper/lower case *MATCH, *IGNORE, *YES, *NO Optional, Positional 3
START Start searching in position Integer, 1 Optional, Positional 4
LEN Max chars to search from Start Integer, *END Optional, Positional 5
RTNPOS CL-var to receive position Not restricted Optional, Positional 6
RTNCHAR Char CL-var for position Character value Optional, Positional 7
Top

Search for pattern (PATTERN)

Specify what is to be searched for. The "pattern".

This is a required parameter.

Top

Data or CL variable to search (SCHDATA)

Specify the string or CL variable to be searched for the pattern. This parameter has a maximum length of 5000 characters.

This is a required parameter.

Top

Match upper/lower case (CASE)

Specifies whether a case-sensitive scan is performed.

*MATCH
The scan is case-sensitive. The upper/lower case pattern must be exactly as is appears in the searched data (SCHDATA) parameter.
*IGNORE
The scan is case-insensitive. Upper/Lower case differences between the pattern and the searched data are ignored.
*YES
This is an alias for CASE(*MATCH)
*NO
This is an alias for CASE(*IGNORE)
Top

Start searching in position (START)

Specify the starting position where the scan is to begin. This value identifies the first character of the searched data that is scanned for the pattern.

1
The default is position 1 (the first position of the searched data).
integer
Specify the position within the searched data to begin the scan. If this value is greater than the length of the searched data then the scan will return zero.
Top

Max chars to search from Start (LEN)

Specify the number of characters of the searched data value to be scanned, starting from the START value.

*END
All characters from the position identified in the START parameter through the end of the variable are scanned.
integer
Specify the number of characters to be scanned in the searched data.
Top

CL-var to receive position (RTNPOS)

Specify a CL variable to receive the scan position if the scan pattern is located in the searched data.

unrestricted-value
Specify any numeric CL variable; any length any type to receive the found position.
Top

Char CL-var for position (RTNCHAR)

Specify an optional CL variable of TYPE(*CHAR) that receives the found position as left-justified text. This is provided to avoid that additional step often necessary with numeric to character CL conversions.

character-value
Specify the CL variable of TYPE(*CHAR) that receives the found position.
Top

Examples for CLSCAN

Example 1:Case Insensitive CLSCAN

DCL  &POS TYPE(*DEC) LEN(7 0)
CLSCAN  PATTERN('company') SCHDATA(&COMPNAME) CASE(*IGNORE)
          RTNPOS(&POS)

This command performs a case insensitive scan of the &COMPNAME CL variable for the word 'company' and if found, returns the location to the &POS CL variable.

Example 2: More Complex CLSCAN Example

DCL  &POS TYPE(*DEC) LEN(7 0)
DCL  &POSA TYPE(*CHAR) LEN(5)
CLSCAN  PATTERN('company') SCHDATA(&COMPNAME) START(5) LEN(16)
          RTNPOS(&POS) RTNCHAR(&POSA)

This command performs a case-sensitive scan beginning in position 5 of &COMPNAME through position 20 (Pos 5 + Len(16) = Pos 5 to 20) and if found, returns the position as numeric to the &POS variable and as left-justified text to the &POSA variable.

Top

Error messages

Unknown
Top