Conditions for Execution of the EXCHANGE Statement

The two disk files must be closed when the EXCHANGE statement is executed, the two rows must be the same size, the specified row numbers and the specified copy numbers must be valid, and the two files cannot be code files of any kind.

Row numbers begin with zero and copy numbers begin with 1. If there are copies of the file and a copy number is specified, then only the rows of that copy are exchanged.

For the exchange to take place, the referenced files must be closed with retention. For more information, see CLOSE Statement.

If the system detects an error, the exchange is not performed and the program resumes execution with the next statement. After the program uses the EXCHANGE statement, the row addresses should be checked by using file attributes to ensure that the exchange was successfully completed.

 Caution

The EXCHANGE statement creates an unaudited directory transaction. An unaudited directory transaction is not subject to recovery in the event of halt/load disk family verification. Thus, the disk family directory can be left in an inconsistent state with an area within the family allocated to both of the files involved in the exchange operation.

Always make sure that an EXCHANGE statement finishes successfully. You can do this by programmatically capturing the row addresses that were involved in the exchange, and comparing them with the respective rows of the files that were involved in the exchange. If the comparison yields an inconsistency, then take corrective measures to recover the affected files to their respective states before the EXCHANGE statement was executed.

Refer the System Messages Support Reference Manual for information about recovery techniques.