Command processing in a macro

When you issue a MACRO command, the server processes all commands in the macro file in order, including commands that are contained in any nested macros. The server commits all commands in a macro after successfully completing processing for the highest-level macro.

If an error occurs in any command in the macro or in any nested macro, the server stops processing and rolls back any changes that were caused by all previous commands.

If you specify the ITEMCOMMIT option when you enter the DSMADMC command, the server commits each command in a script or a macro individually after successfully completing processing for each command. If an error occurs, the server continues processing and rolls back only the changes caused by the failed command.

You can control precisely when commands are committed with the COMMIT command. If an error occurs while the server is processing the commands in a macro, the server stops processing the macro and rolls back any uncommitted changes. Uncommitted changes are commands that were processed since the last COMMIT command. Make sure that your administrative client session is not running with the ITEMCOMMIT option if you want to control command processing with the COMMIT command.

You can test a macro before you implement it by using the ROLLBACK command. You can enter the commands (except the COMMIT command) you want to issue in the macro, and enter ROLLBACK as the last command. Then, you can run the macro to verify that all the commands process successfully. Any changes to the database caused by the commands are rolled back by the ROLLBACK command. Remember to remove the ROLLBACK command before you make the macro available for actual use. Also, make sure that your administrative client session is not running with the ITEMCOMMIT option if you want to control command processing with the ROLLBACK command.

Tip: Commands that start background processes cannot be rolled back.
If you have a series of commands that process successfully from the command line, but are unsuccessful when issued within a macro, there are probably dependencies between commands. It is possible that a command issued within a macro cannot be processed successfully until a previous command that is issued within the same macro is committed. Either of the following actions allows successful processing of these commands within a macro:
  • Insert a COMMIT command before the command dependent on a previous command. For example, if COMMAND C is dependent upon COMMAND B, you would insert a COMMIT command before COMMAND C.
        command a
        command b
        commit
        command c/
  • Start the administrative client session by using the ITEMCOMMIT option. This option causes each command within a macro to be committed before the next command is processed.