Scan & Replace Data in Source (SCANRPL)

Where allowed to run: All environments (*ALL)
Threadsafe: No
Parameters
Examples
Error messages

The Scan & Replace Data in Source (SCANRPL) command scans one or all source file members in a source file and replaces a search pattern with the specified replacement text. Any source file member may be scanned and replaced using this command.

Restrictions:

Top

Parameters

Keyword Description Choices Notes
PATTERN Search pattern (regex allowed) Character value Required, Positional 1
REGEX RegEx search pattern *YES, *NO Optional, Positional 2
NEWVALUE Replacement string Character value, *PRINT Optional, Positional 3
SRCFILE Source file Qualified object name Optional, Positional 4
Qualifier 1: Source file Name, QRPGLESRC
Qualifier 2: Library Name, *CURLIB, *LIBL
SRCMBR Source Member to scan Name, *ALL, *FIRST Optional, Positional 5
MATCHCASE Match upper/lower case *MATCH, *IGNORE, *YES, *NO Optional, Positional 6
START Starting line position Integer, 1 Optional, Positional 7
OCCURS Line occurrence to process Integer, *ALL Optional, Positional 8
IGNSPACE Ignore Spaces in REGEX PATTERN *IGNORE, *YES, *NO Optional, Positional 9
Top

Search pattern (PATTERN)

Specifies the search pattern used to scan the input source file record. Any plain text or a regular expression may be specified. To use a regular expression, specify the REGEX(*YES) parameter option.

This is a required parameter.

character-value
Specify the search pattern. This parameter is case-sensitive unless CASE(*IGNORE) is specified.
Top

Regular Expression Search (REGEX)

Specifies the search pattern uses the regular express (REGEX) engine to search instead of the standard linear scan/search routine. Regular expressions may be specified in the PATTERN parameter when this parameter is REGEX(*YES), however remember to escape any control characters with a preceeding backslash. For example, if you are searching for a values such as "QGPL.CUSTMAST" the period must be escaped otherwise the regular expression engine will match any character with the period. So "QGPL/CUSTMAST" and "QGPL.QCUSTMAST" would both match the regex search pattern. Note that the SCANRPL program auto-escapes on the forward slash character since it is widely used in IBM i application systems.

This is a required parameter.

character-value
Specify the search pattern. This parameter is case-sensitive unless CASE(*IGNORE) is specified.
Top

Replacement string (NEWVALUE)

Specifies the text that is inserted into the source record in place of the text specified on the search pattern parameter.

This is a required parameter.

character-value
Specify the replacement text. This parameter is case sensitive.
Top

Source file (SRCFILE)

Specifies a source file that contains the source member to be scanned.

Qualifier 1: Source file

QRPGLESRC
RPG IV source file QRPGLESRC is used as the file name.
name
Specify the name of source file that contains the members to be scanned.

Qualifier 2: Library

*CURLIB
The current library contains the source file.
*LIBL
The library list is searched for the source file.
name
Specify the name of the library containing the source file.
Top

Source Member to scan (SRCMBR)

Specifies the source member that is searched.

*ALL
All source members in the source file specified on the SRCFILE parameter are searched scanned (and replaced where appropriate).
*FIRST
The first source member in the source file is searched.
name
Specify the name of specific source member to search.
Top
Top

Starting position (START)

Specifies the position on each line where the scan operation begins.

1
The first positions of each line is the starting point for the scan/replace.
1-32766
The starting position on each line where the scan/replace begins.
Top

Occurrence to process (OCCURS)

Specifies the individual occurrence of the scan pattern on the line to process. If anything other than *ALL (or 0) is specified, only that individual occurrence is replaced--other occurrences of PATTERN are not changed. NOTE: It is uncommon to use anything other than the default value of *ALL for this parameter.

*ALL
All occurrences of PATTERN on each line of the source member are replaced with the NEWVALUE replacement string.
1-32766
The occurrence of the PATTERN on each source member line to be replaced.
Top

Ignore spaces in PATTERN (IGNSPACE)

Causes the regular expression search to ignore spaces embedded within the PATTERN parameter. Spaces on the searched text (source member line) are not impacted by this parameter.

*NO
Spaces embedded in the regular expression (PATTERN parameter) are respected and considered part of the search pattern.
*YES
Spaces embedded in the regular expression (PATTERN parameter) are ignored.
*IGNORE
Same as *YES. Spaces in the pattern are ignored.
Top

Examples for SCANRPL

Example 1: Simple Command Example

SCANRPL PATTERN('xtools/qcpysrc,')
        NEWVALUE('cozTools/qcpysrc,')
          SRCFILE(QRPGLESRC) SRCMBR(*ALL) CASE(*IGNORE)

This command scans all source members in QRPGLESRC for the pattern 'xtools/qcpysrc' while ignoring upper/lower case variations. It then replaces each occurrance of that search pattern with 'cozTools/qcpysrc,'. The 'cozTools/qcpysrc,' replacement text is embedded with the same upper/lower case pattern as the users has specified on the command.

Top

Error messages

Unknown
Top