Implementing compensation

Compensation is the act of modifying ("compensating for") the effects of a completed activity. How compensation is implemented is decided by the designer of the business transaction. 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 activity’s parent. 7

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

  1. Re-run the activity.

    To do this, 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. (Note that 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 is the more straightforward method. 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 that used for the execution of the activity that is compensated.

    The compensation example in this section uses this method.

Related concepts
A compensation example
Using the BTS API to write business applications
The Sale example application
Related tasks
Dealing with application locking
Related reference
Overview of BTS API commands
BTS application programming commands

7.
It is convenient to talk of compensation as an act that a parent performs on a child--as in "compensating an activity". We use this convention throughout the rest of the book. 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.

[[ Contents Previous Page | Next Page Index ]]