Example: lr_set_transaction_instance_status

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();