Share this page

# lr.end_transaction

Marks the end of a transaction.

    int lr.end_transaction( String transaction_name, int status);

Transaction Functions | Java Syntax

## Arguments

Name | Comments
--- | ---
transaction_name | A string indicating the name of an existing transaction.
status | The Transaction Status

The lr.end_transaction function marks the end of a transaction and records the amount of time it took to perform the transaction. To indicate a transaction to be analyzed, place the lr.start_transaction function before the transaction, and the lr.end_transaction function after the transaction.

You can manually set the status of the transaction or you can allow the script to detect it automatically. To manually set the status, you perform a manual check within the code of your script (see example) evaluating the return code of a function. For the "succeed" return code, set the status to lr.PASS. For a "fail" return code, set the status to lr.FAIL. For an "aborted" return code, set the status to lr.STOP.

If status is lr.AUTO, then the value of status is automatically assigned. By default, this value is lr.PASS signifying a successful transaction. However, if prior to lr.end_transaction, you change the default value using lr.set_transaction_status, lr.set_transaction_status_by_name, lr.set_transaction_instance_status, or lr.fail_trans_with_error, then this is the value which is passed as status in lr.end_transaction.

If you make a series of calls to functions that modify the lr.AUTO status, then it is the last call before lr.end_transaction which effectively changes the status.

## Return Values

This function returns 0 if it succeeds. It returns -1 if the transaction name is illegal or if there is no prior call to lr.start_transaction with a transaction of the same name.

## Parameterization

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

## Examples

### Example 1 - Simple Transaction

The sample below illustrates timing the duration of a method call getStockList from an ORB interface. The sample code does not check for exceptions.

Copy code

    lr.start_transaction("GetStocks");
    orStockServer1.getStockList();
    lr.end_transaction("GetStocks", lr.PASS);

### Example 2 - Conditional transaction sample

The sample below illustrates timing the duration of the same sample code, however it adds checks for exceptions and ensures that the getStockList() method returns an non-zero length array.

Copy code

    lr.start_transaction("GetStocks");
    try {
        String stocks[];
        stocks = orStockServer1.getStockList();
        if (stocks.length == 0)
                throw new Exception("No stocks returned/available");
        lr.end_transaction("GetStocks", lr.PASS);
       }
    catch (Exception e1) {
            lr.end_transaction("GetStocks", lr.FAIL);
            lr.message(" An exception occurred : " + e1.toString() );
        }

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: