CHANGEFILE Statement

The CHANGEFILE statement changes the names of files without opening them.

<changefile statement>

── CHANGEFILE ── ( ──<directory element>── , ──<directory element>─────►
►─ ) ──────────────────────────────────────────────────────────────────┤

The CHANGEFILE statement returns a value of TRUE if an error occurs. Error numbers, stored in field [39:20] of the result, correspond to the causes of failure as follows:

Value

Meaning

10

The first directory element is in error.

20

The second directory element is in error.

30

File names have not been changed.

File names and directory names must be specified in EBCDIC and must be followed by a period. All errors in the names are detected at run time.

If a family substitution specification is in effect, the CHANGEFILE statement affects only the substitute family, not the alternate family.

If a directory name is specified as the source, the names of the files in that directory are changed according to the following rules:

  • If the specified target directory is a new directory, then the names of all the files in the source directory are changed.

  • If the specified target directory is not a new directory, then only files that do not have corresponding names in the target directory are changed. For example, the first column in the following table shows file names that exist before the statement CHANGEFILE("A.","B.") is executed, and the second column shows the file names resulting from execution of the statement.

    Existing Files

    Resulting Files

    A/B/C

    B/B/C

    A/B/D

    A/B/D

    A/C/C

    B/C/C

    B/B/D

    B/B/D

    B/C/D

    B/C/D

    Note that because the file name B/B/D already exists, the file name A/B/D is not changed.

  • A directory element of the form <file name>/= affects only files in that specified directory. It does not affect a file named <file name>.

    Note: If one of the directory elements is of the form <file name>/=, the other elements must also be of that same form.
  • If the source directory element is in the permanent directory namespace, (for example, within the *DIR directory), is not of the form <file name>/= , and the directory is empty, only the file or directory is changed.

Conflicting CHANGE Requests

Two simultaneous change requests that affect the same set of files can produce unpredictable results because directory change requests are processed in groups of files. For example, two simultaneous CHANGEFILE ("A.", "B.") and CHANGEFILE ("B.", "A.") statements, where both directories A/= and B/= exist with nonconflicting file names, can result in all of the files being held in directory A/=, all of the files being held in directory B/=, or all of the files being split between the two directories.