Implementing compensation

Compensation is the act of modifying, or compensating for, the effects of a completed activity. The designer of the business transaction decides how compensation is implemented.

About this task

Often, compensating for an activity means undoing the actions that it took - for example, compensation for accepting an order might be to cancel the order.

Compensation of an activity is always controlled and instigated by the parent of the activity. It is therefore convenient to talk of compensation as an act that a parent performs on a child - as in “compensating an activity”. Strictly speaking, however, it is the parent that is compensated (it “receives compensation” for some previous action taken by the child. The previous action of the child is compensated for—it is reversed or modified.

Here are two ways in which you could implement compensation of a completed child activity.
  1. Run the activity again.

    To run the activity again, you must first issue a RESET ACTIVITY command, to reset the activity to its initial state. You must then tell the activity that it is being invoked to perform compensation; you could do this by placing a flag in an input data-container. You cannot use the INPUTEVENT option of the RUN command to tell the activity why it is being invoked; specifying INPUTEVENT is invalid when an activity is in its initial state.

    In this method, the program used for compensation, the compensation program , is the same program used for normal (forward) execution of the activity.

  2. Define and run a new, compensation, activity.

    This method is more straightforward. You could use a PUT CONTAINER command to provide the compensation activity with the same input data that was passed to the activity for which it compensates.

    In this method, the program used for compensation is likely to be different from the program used for the execution of the activity that is compensated.

    The compensation example in this section uses this method.