LoadRunner Variables

There is always confusion related to variables in the LoadRunner script. Because some variables require defining at the start of the script while some variables can be used directly without any initialization. Let’s discuss what is the exact difference between them.

Basically, there are two types of variable in the LoadRunner:

1. Language-Specific Variables:

Language-specific variables are those variables that need both declaration and definition (optional) at the start of the script such as:

int count;

float amount;

You can use these variables to perform some mathematical or file-handling operations in the script.

2. LoadRunner Variables:

These variables do not require any explicit declaration. When a function calls LoadRunner declares these variables internally. Such as:


web_reg_save_param("correlationVar", "LB =", "RB =", LAST);

LoadRunner variable is used with curly braces in the script. For example, the correlation variable will be written as {correlationVar}. 


Language-Specific VariableLoadRunner Variable
Required Declaration at the beginningDo not require any declaration
Mostly used by the language-specific or custom functions like strcpy(), rand()Mostly used by protocol-specific functions like web_url(), web_reg_find()
Language-specific functions do not use LR variables directly.LoadRunner functions accept both types of variables
To use the value of the LR variable in the language-specific function, it should be copied into a Language-Specific variable.To copy the value of the language-specific variable to LR variable lr_save_string(), lr_save_int() functions are used.
Language-specific variables can be used directly in the script.While using the LR variable, they should be enclosed within Curly Braces {}


From language-specific variable to LoadRunner variable:

As mentioned above to copy the value of the language-specific variable to the LoadRunner variable, lr_save_int() and lr_save_string() functions are used.


int x = 5;
lr_save_int(x, "lrVarInt");

Here, x is a language-specific variable and lrVarInt is a LoadRunner variable. lr_save_int function copies the value of the language-specific variable in the LoadRunner variable. Now the lrVarInt has value 5 and can be used like {lrVarInt} in the script.

Similarly, you can use lr_save_string() function to copy the value of string variables into LoadRunner variables.

From LoadRunner variable to Language-Specific variable:

lr_eval_string() is an important function in LoadRunner which helps to convert the LoadRunner variable into the language-specific variable. Whenever you want to use the value of the LoadRunner variable in a language-specific function then you need to first evaluate the parameter. lr_eval_string function evaluates the parameter and returns the value in a string data type.


A LoadRunner variable (say lrVarStr) stores a value ‘PerfMatrix’, so lr_eval_string(“{lrVarStr}”) will return ‘PerfMatrix’ which will be copied in a language-specific variable (say lsVarStr).

char lsVarStr[15];
strcpy(lsVarStr, lr_eval_string("{lrVarStr}");

Similarly, let’s assume another LoadRunner variable (say lrVarInt) stores a value ‘100’, so lr_eval_string(“{lrVarInt}”) will return ‘100’ in string format which will be first converted into an integer using atoi function and then assigned to a language-specific variable (say lsVarInt).

int lsVarInt;
lsVarInt = atoi(lr_eval_string("{lrVarStr}"));


  1. lr_eval_string() function always returns string value irrespective of the datatype of the parameter
  2. In the case of an integer, the value returned by lr_eval_string() needs to be converted from string to integer explicitly
  3. atoi() function converts any string to an integer. Hence I used it in the above example.

Using the above methods you can use the value of LoadRunner and Language-Specific variables in both ways depending on the requirement.

You may be interested:

Leave a Comment