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.

Note:
  1. To find and replace long strings that do not fit on the Command line, use the CX command (see Handling long strings in CHANGE).
  2. 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).
  3. 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:

  1. Display your data in the editor panel (see Starting and ending editor sessions for details).
  2. 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).
  3. 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).
  4. 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 Z Data Tools 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.

The CHANGE command may affect record length:
  • 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, Z Data Tools 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 Z Data Tools 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. Z Data Tools maintains the same record length by dropping blanks from the end of the record.
    • If string2 is shorter than string1, then Z Data Tools 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, Z Data Tools 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