lr_set_transaction_instance_status

Sets the status of a transaction instance.

int lr_set_transaction_instance_status( int status, long trans_handle );
Alphabetical Listing - C Language Utility Functions

Arguments

NameComments
status One of the Transaction Status constants for pass, fail, or stop. The auto status is not applicable.
trans_handle The handle to a transaction instance

The lr_set_transaction_instance_status function sets the status of the open transaction with the transaction handle trans_handle. The handle was returned by lr_start_transaction_instance.

This transaction's lr_end_transaction_instance statement must use automatic status assignment by passing a Transaction Status of auto as its status parameter.

A transaction's status is defined in the status parameter of lr_end_transaction_instance. If this status is LR_AUTO the value is automatically assigned. By default, this value is LR_PASS signifying a successful transaction. lr_set_transaction_instance_status changes this default value to status.

For more information on transaction instances, see lr_start_transaction_instance.

Return Values

This function returns 0 on success and a negative value on failure.

Parameterization

You cannot use standard parameterization for any arguments in this function.

Example

In the following example,the transaction instance "withdraw" measures the time it takes to perform a withdrawal from a bank server. When the server API call bank_withdraw() is completed, it returns a value to the status variable and the transaction instance is complete.

If the withdrawal fails, then lr_set_transaction_instance_status changes the default status for the transaction to LR_FAIL. The LR_FAIL status is automatically assigned to the LR_AUTO flag in the lr_end_transaction_instance statement because it uses the LR_AUTO flag.

long id;
int status;
int amount_overdrawn = get_amount_overdrawn(); /* Call to server API */
while (amount_overdrawn < LIMIT) {
     /* Notify that a transaction is starting */
    id = lr_start_transaction_instance("withdraw", 0);
    status = bank_withdraw(500); /* Call to server API */     /* Set transaction status with operation result - pass or fail */
     if (status != 0) /* Withdrawal failed */
          lr_set_transaction_instance_status(LR_FAIL, id);
          lr_end_transaction_instance(id, LR_AUTO);
          amount_overdrawn = get_amount_overdrawn();
}