Finding and replacing strings
To find and replace one or more occurrences of a character string in a data set or data set member, you can use the CHANGE primary command. In SNGL or TABL display format, you can also use the CHANGE command to find and replace a numeric value in numeric fields.
- To find and replace long strings that do not fit on the Command line, use the CX command (see Handling long strings in CHANGE).
- To find and replace strings in multiple data sets or data set members, use the Find/Change Utility (see Finding and changing data in multiple PDS members).
- To find a string or numeric value without changing it, use the FIND primary command. See FIND/FX primary command.
To change character strings with the CHANGE command:
- Display your data in the editor panel (see Starting and ending editor sessions for details).
- If you are using a template and wish to limit the effects of the CHANGE command, apply suitable record identification or record selection criteria to select your records for processing (see Selecting records with templates).
- If you want to prevent particular records from being affected by the CHANGE command, use commands such as BOUNDS or EX to limit the range of the CHANGE command (see Limiting the effect of editing changes).
- On the Command Line, enter the CHANGE command, together with any
desired parameters, and the search and replace strings. For example:
CHANGE black white
See CHANGE/CX primary command for details about the syntax and parameters of the CHANGE command.
The CHANGE command highlights all occurrences of the search string or numeric value in the entire data set.
To turn off the highlighting, enter the RESET FIND command.
If the CHANGE command changes data, then File Manager places the cursor at the start of the changed data; if necessary, automatically scrolling to bring the data into view.
To change the next occurrence of the string, press the RChange function key (F6).
To find the next occurrence of the string and optionally change it, use a combination of the RFind function key (F5) and the RChange function key (F6).
To find the same string as you specified on the previous CHANGE primary command, specify an asterisk (*) as the search string.
To use the same replacement string as you specified on the previous CHANGE primary command, specify an asterisk (*) as the replacement string.
To limit the search for a string to only where it appears as a prefix in the data, specify the PREFIX parameter.
To limit the search for a string to only where it appears as a suffix in the data, specify the SUFFIX parameter.
To limit the search for a string to only where it appears as a "word" in the data, specify the WORD parameter.
To change all occurrences of the string (except those in not-selected or suppressed records), use the ALL parameter with the change command.
The CHANGE command does not affect not-selected or suppressed records that are hidden or represented by shadow lines. To include these records in a CHANGE command, you need to show them. For details, see SHOW (REC) primary command.
The CHANGE command does affect records that have been hidden using the EXCLUDE command, unless you have used the NX parameter. If a change affects an excluded record, it becomes not-excluded. For more information on using the EXCLUDE command or EX and NX parameters, see Excluding records, CHANGE/CX primary command or EXCLUDE/XX primary command.
If you have zoomed in on a record, then the CHANGE command affects only that record. See Zooming in to see all of a record.
- When you use the CHANGE command in CHAR, HEX or LHEX display format:
- For variable-length files where the edit type supports record length changes, if string2 is longer than string1 and there are not enough EBCDIC blank characters (X'40') at the end of the record to accommodate the difference in length, File Manager expands the record length as required.
- For variable-length files where the edit type supports record length changes, if string2 is shorter than string1, then File Manager reduces the record length as required.
Otherwise, for fixed-length files, or where the type of edit prevents record length changes:
- If string2 is longer than string1, then the change only occurs if there are enough EBCDIC blank characters (X'40') at the end of the record to accommodate the difference in length. File Manager maintains the same record length by dropping blanks from the end of the record.
- If string2 is shorter than string1, then File Manager maintains the same record length by padding the end of the record with blanks.
- If you use the CHANGE command in SNGL or TABL display format to
change a non-numeric field, the change is the same as the above fixed-length
considerations except it applies to a field rather than a record.
When record length changes are possible, and the field being affected
by the change overlaps the end of the underlying record, File Manager
may expand the record as required to complete the change request.
This only occurs when the underlying record is shorter than the record
structure. If you use the CHANGE command in SNGL or TABL display format to change a numeric field, then the length of string1 and string2 are not significant. For example, if field #2 is a numeric field, then the following CHANGE command is allowed, because string1 and string2 are interpreted as numeric values:
CHANGE 107 2 #2
For more information on changing values in numeric fields, see Searching numeric fields.
- If the argument is a DBCS string, only data between a shift-out
and shift-in is searched for a match. For example, a DBCS blank
X'0E40400F'
does not find two consecutive blanks in non-DBCS data.The exception to this rule is in TABL or SNGL format where the field is a graphic field. Unformatted graphic fields are not treated as DBCS.
For details on limiting the columns, fields or records searched by the CHANGE command, see Limiting the effect of editing changes.
Examples
- If you are not using a template:
CHANGE CAT DOG
- When zoomed in, changes the next occurrence of “CAT” to “DOG” in the current record only. Otherwise, changes the next occurrence of “CAT” to “DOG”.
CHANGE YELLOW ORANGE ALL
- When zoomed in, changes all occurrences of “YELLOW” to “ORANGE” in the current record only. Otherwise, changes all occurrences of “YELLOW” to “ORANGE” in all records.
- If you are using a template, and the data is displayed
in SNGL or TABL format:
CHANGE BLACK WHITE (#4 #7)
- In TABL format, changes the next occurrence of “BLACK” to “WHITE”, where “BLACK” is completely contained within either of the fields represented by field references 4 and 7. In SNGL format, changes the next occurrence of “BLACK” to “WHITE”, where “BLACK” is completely contained within either of the fields represented by field references 4 and 7, in the current record only.
CHANGE BLACK WHITE ALL #2,#8
- In TABL format, changes all occurrences of “BLACK” to “WHITE”, where “BLACK” is completely contained within either of the fields represented by field references 2 and 8, in all records. In SNGL format, changes all occurrences of “BLACK” to “WHITE”, where “BLACK” is completely contained within either of the fields represented by field references 2 and 8, in the current record only.